summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-07-25 09:38:43 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-25 09:38:43 -0700
commit420d149566e19f1663db69420375b6dd1f0acd6f (patch)
tree5ae789cb68c7b9d91f7a510461157a2d45d3e128
parentc8b708c379ec8ef47772d186fefe385ef7e12359 (diff)
parentaaa1f375bc9d6a6a175819fac34d39202f69a166 (diff)
downloadpackages_apps_browser-420d149566e19f1663db69420375b6dd1f0acd6f.zip
packages_apps_browser-420d149566e19f1663db69420375b6dd1f0acd6f.tar.gz
packages_apps_browser-420d149566e19f1663db69420375b6dd1f0acd6f.tar.bz2
Merge changes I78550965,I6e0fe0ba,Ia6db6cf3
* changes: Cache the factory reset URL. Fix StrictMode violation in InstantSearchEngine Query Private Browsing state for NFC on UI thread.
-rw-r--r--src/com/android/browser/BrowserSettings.java33
-rw-r--r--src/com/android/browser/InstantSearchEngine.java2
-rw-r--r--src/com/android/browser/NfcHandler.java76
3 files changed, 61 insertions, 50 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index a4f0f04..2023ee6 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -103,7 +103,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
private WebStorageSizeManager mWebStorageSizeManager;
private AutofillHandler mAutofillHandler;
private WeakHashMap<WebSettings, String> mCustomUserAgents;
- private boolean mInitialized = false;
+ private static boolean sInitialized = false;
// Looper shared between some lightweight background operations
// Specifically, this is created on the thread that initializes browser settings
// and is then reused by CrashRecoveryHandler
@@ -116,6 +116,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
// Cached settings
private SearchEngine mSearchEngine;
+ private static String sFactoryResetUrl;
+
public static void initialize(final Context context) {
sInstance = new BrowserSettings(context);
}
@@ -199,21 +201,28 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
}
mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
}
+
+ sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
+ if (sFactoryResetUrl.indexOf("{CID}") != -1) {
+ sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
+ BrowserProvider.getClientId(mContext.getContentResolver()));
+ }
+
Looper.prepare();
mBackgroundLooper = Looper.myLooper();
- synchronized (BrowserSettings.this) {
- mInitialized = true;
- BrowserSettings.this.notifyAll();
+ synchronized (BrowserSettings.class) {
+ sInitialized = true;
+ BrowserSettings.class.notifyAll();
}
Looper.loop();
}
};
- void requireInitialization() {
- synchronized (BrowserSettings.this) {
- while (!mInitialized) {
+ private static void requireInitialization() {
+ synchronized (BrowserSettings.class) {
+ while (!sInitialized) {
try {
- BrowserSettings.this.wait();
+ BrowserSettings.class.wait();
} catch (InterruptedException e) {
}
}
@@ -334,12 +343,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
}
public static String getFactoryResetHomeUrl(Context context) {
- String url = context.getResources().getString(R.string.homepage_base);
- if (url.indexOf("{CID}") != -1) {
- url = url.replace("{CID}",
- BrowserProvider.getClientId(context.getContentResolver()));
- }
- return url;
+ requireInitialization();
+ return sFactoryResetUrl;
}
public LayoutAlgorithm getLayoutAlgorithm() {
diff --git a/src/com/android/browser/InstantSearchEngine.java b/src/com/android/browser/InstantSearchEngine.java
index c913494..4dd83fa 100644
--- a/src/com/android/browser/InstantSearchEngine.java
+++ b/src/com/android/browser/InstantSearchEngine.java
@@ -199,7 +199,7 @@ public class InstantSearchEngine implements SearchEngine, DropdownChangeListener
return false;
}
- final String currentUrl = current.getUrl();
+ final String currentUrl = mController.getCurrentTab().getUrl();
if (currentUrl != null) {
Uri uri = Uri.parse(currentUrl);
diff --git a/src/com/android/browser/NfcHandler.java b/src/com/android/browser/NfcHandler.java
index bc19950..a8e11d3 100644
--- a/src/com/android/browser/NfcHandler.java
+++ b/src/com/android/browser/NfcHandler.java
@@ -21,6 +21,10 @@ import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Message;
+
+import java.util.concurrent.CountDownLatch;
/** This class implements sharing the URL of the currently
* shown browser page over NFC. Sharing is only active
@@ -31,42 +35,26 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback {
private NfcAdapter mNfcAdapter;
private Activity mActivity;
private Controller mController;
+ private Handler mHandler;
+ private Tab mCurrentTab;
+ private boolean mIsPrivate;
+ private CountDownLatch mPrivateBrowsingSignal;
- /** We need an async task to check whether the tab is private
- * on the UI thread.
- */
- private class CreateMessageTask extends AsyncTask<Void, Void, NdefMessage> {
- private boolean mIsPrivate = false;
- private Tab mCurrentTab;
-
- @Override
- protected void onPreExecute() {
- mCurrentTab = mController.getCurrentTab();
- if ((mCurrentTab != null) && (mCurrentTab.getWebView() != null)) {
- mIsPrivate = mCurrentTab.getWebView().isPrivateBrowsingEnabled();
- }
- }
-
- @Override
- protected NdefMessage doInBackground(Void... params) {
- if ((mCurrentTab == null) || mIsPrivate) {
- return null;
- }
- String currentUrl = mCurrentTab.getUrl();
- if (currentUrl != null) {
- NdefRecord record = NdefRecord.createUri(currentUrl);
- NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
- return msg;
- } else {
- return null;
- }
- }
- }
+ private static final int GET_PRIVATE_BROWSING_STATE_MSG = 100;
public NfcHandler(Activity browser, Controller controller) {
mActivity = browser;
mController = controller;
mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
+ mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == GET_PRIVATE_BROWSING_STATE_MSG) {
+ mIsPrivate = mCurrentTab.getWebView().isPrivateBrowsingEnabled();
+ mPrivateBrowsingSignal.countDown();
+ }
+ }
+ };
}
void onPause() {
@@ -83,11 +71,29 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback {
@Override
public NdefMessage createMessage() {
- CreateMessageTask task = new CreateMessageTask();
- task.execute();
- try {
- return task.get();
- } catch (Exception e) {
+ mCurrentTab = mController.getCurrentTab();
+ if ((mCurrentTab != null) && (mCurrentTab.getWebView() != null)) {
+ // We can only read the WebView state on the UI thread, so post
+ // a message and wait.
+ mPrivateBrowsingSignal = new CountDownLatch(1);
+ mHandler.sendMessage(mHandler.obtainMessage(GET_PRIVATE_BROWSING_STATE_MSG));
+ try {
+ mPrivateBrowsingSignal.await();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+
+ if ((mCurrentTab == null) || mIsPrivate) {
+ return null;
+ }
+
+ String currentUrl = mCurrentTab.getUrl();
+ if (currentUrl != null) {
+ NdefRecord record = NdefRecord.createUri(currentUrl);
+ NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
+ return msg;
+ } else {
return null;
}
}