Index: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuHelper.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuHelper.java |
index 871c950a8222cf5962898611fb9083d94dbc9bd5..953d04830cd22d2a196e889d108b56351ed18ffd 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuHelper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuHelper.java |
@@ -5,6 +5,7 @@ |
package org.chromium.chrome.browser.browseractions; |
import android.app.PendingIntent; |
+import android.app.ProgressDialog; |
import android.support.customtabs.browseractions.BrowserActionItem; |
import android.support.customtabs.browseractions.BrowserActionsIntent; |
import android.util.Pair; |
@@ -59,6 +60,10 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
private final List<Pair<Integer, List<ContextMenuItem>>> mItems; |
+ private final ProgressDialog mProgressDialog; |
+ |
+ private boolean mIsOpenInBackgroundPending; |
+ |
public BrowserActionsContextMenuHelper(BrowserActionActivity activity, ContextMenuParams params, |
Yusuf
2017/07/10 06:14:56
Looking at how we are using the Activity here, if
ltian
2017/07/26 01:22:12
Done.
|
List<BrowserActionItem> customItems, String sourcePackageName) { |
mActivity = activity; |
@@ -72,7 +77,9 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
mOnMenuClosed = new Runnable() { |
@Override |
public void run() { |
- mActivity.finish(); |
+ if (!mIsOpenInBackgroundPending) { |
+ mActivity.finish(); |
+ } |
} |
}; |
mItemSelectedCallback = new Callback<Integer>() { |
@@ -96,6 +103,7 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
ChromeContextMenuItem.BROWSER_ACTION_SAVE_LINK_AS, |
ChromeContextMenuItem.BROWSER_ACTIONS_COPY_ADDRESS, shareItem); |
mDelegate = new BrowserActionsContextMenuItemDelegate(mActivity, sourcePackageName); |
+ mProgressDialog = new ProgressDialog(mActivity); |
mItems = buildContextMenuItems(customItems); |
} |
@@ -131,7 +139,12 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
private boolean onItemSelected(int itemId) { |
if (itemId == R.id.browser_actions_open_in_background) { |
- mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()); |
+ if (mActivity.isNativeInitialized()) { |
+ mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()); |
+ } else { |
+ mIsOpenInBackgroundPending = true; |
+ waitNativeInitialized(); |
+ } |
} else if (itemId == R.id.browser_actions_open_in_incognito_tab) { |
mDelegate.onOpenInIncognitoTab(mCurrentContextMenuParams.getLinkUrl()); |
} else if (itemId == R.id.browser_actions_save_link_as) { |
@@ -146,6 +159,21 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
return true; |
} |
+ /** |
+ * Display a progress dialog to wait for native libraries initialized. |
+ */ |
+ private void waitNativeInitialized() { |
+ mProgressDialog.setMessage( |
+ mActivity.getString(R.string.browser_actions_loading_native_message)); |
+ mProgressDialog.show(); |
+ } |
+ |
+ private void dismissProgressDialog() { |
+ if (mProgressDialog != null && mProgressDialog.isShowing()) { |
+ mProgressDialog.dismiss(); |
+ } |
+ } |
+ |
/** |
* Displays the Browser Actions context menu. |
* @param view The view to show the context menu if old UI is used. |
@@ -183,4 +211,16 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe |
@Override |
public void onViewDetachedFromWindow(View v) {} |
+ |
+ /** |
+ * Finishes all pending actions which requires Chrome native libraries. |
+ */ |
+ public void handlePendingActions() { |
Yusuf
2017/07/10 06:14:56
onNativeInitialized
ltian
2017/07/26 01:22:12
Done.
|
+ if (mIsOpenInBackgroundPending) { |
+ mIsOpenInBackgroundPending = false; |
+ dismissProgressDialog(); |
+ mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()); |
+ mActivity.finish(); |
+ } |
+ } |
} |