diff options
author | Martijn Coenen <maco@google.com> | 2011-07-06 09:23:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-06 09:23:24 -0700 |
commit | a55da99bb24b952e8ba5cc08d5ad4da7e1344355 (patch) | |
tree | e92493ca8002f16c998c9a3acecbe004eda4219d | |
parent | 87ddc3da1b1e08a65da399e80f617de3db6df359 (diff) | |
parent | eee2126458da109b65bbed42904c6c407872c3af (diff) | |
download | packages_apps_browser-a55da99bb24b952e8ba5cc08d5ad4da7e1344355.zip packages_apps_browser-a55da99bb24b952e8ba5cc08d5ad4da7e1344355.tar.gz packages_apps_browser-a55da99bb24b952e8ba5cc08d5ad4da7e1344355.tar.bz2 |
Merge "0-click NFC: check for private tab on UI thread."
-rw-r--r-- | src/com/android/browser/NfcHandler.java | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/com/android/browser/NfcHandler.java b/src/com/android/browser/NfcHandler.java index bbac640..bc19950 100644 --- a/src/com/android/browser/NfcHandler.java +++ b/src/com/android/browser/NfcHandler.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; +import android.os.AsyncTask; /** This class implements sharing the URL of the currently * shown browser page over NFC. Sharing is only active @@ -31,6 +32,37 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback { private Activity mActivity; private Controller mController; + /** 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; + } + } + } + public NfcHandler(Activity browser, Controller controller) { mActivity = browser; mController = controller; @@ -51,17 +83,11 @@ public class NfcHandler implements NfcAdapter.NdefPushCallback { @Override public NdefMessage createMessage() { - Tab currentTab = mController.getCurrentTab(); - if (currentTab == null) { - return null; - } - String currentUrl = currentTab.getUrl(); - if (currentUrl != null && currentTab.getWebView() != null && - !currentTab.getWebView().isPrivateBrowsingEnabled()) { - NdefRecord record = NdefRecord.createUri(currentUrl); - NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); - return msg; - } else { + CreateMessageTask task = new CreateMessageTask(); + task.execute(); + try { + return task.get(); + } catch (Exception e) { return null; } } |