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 99b175421537ab6ef81e98cc8027b5d64a5c6d02..f97f2d697411f31cfd72983faf4b9d38b4516e06 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 |
@@ -4,10 +4,8 @@ |
package org.chromium.chrome.browser.browseractions; |
-import android.app.Activity; |
import android.app.PendingIntent; |
import android.app.PendingIntent.CanceledException; |
-import android.app.ProgressDialog; |
import android.content.Intent; |
import android.net.Uri; |
import android.support.customtabs.browseractions.BrowserActionItem; |
@@ -23,7 +21,6 @@ |
import org.chromium.base.Callback; |
import org.chromium.base.Log; |
-import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItem; |
import org.chromium.chrome.browser.contextmenu.ContextMenuItem; |
@@ -44,33 +41,14 @@ |
public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListener, |
OnCloseContextMenuListener, |
OnAttachStateChangeListener { |
- /** Notified about events happening for Browser Actions tests. */ |
- public interface BrowserActionsTestDelegate { |
- /** Called when menu is shown. */ |
- void onBrowserActionsMenuShown(); |
- |
- /** Called when {@link BrowserActionActivity#finishNativeInitialization} is done. */ |
- void onFinishNativeInitialization(); |
- |
- /** Called when Browser Actions start opening a tab in background */ |
- void onOpenTabInBackgroundStart(); |
- |
- /** Initializes data needed for testing. */ |
- void initialize(BrowserActionsContextMenuItemDelegate delegate, |
- SparseArray<PendingIntent> customActions, |
- List<Pair<Integer, List<ContextMenuItem>>> items, |
- ProgressDialog progressDialog); |
- } |
- |
- |
- static final List<Integer> CUSTOM_BROWSER_ACTIONS_ID_GROUP = |
+ private static final String TAG = "cr_BrowserActions"; |
+ private static final boolean IS_NEW_UI_ENABLED = true; |
+ |
+ private static final List<Integer> CUSTOM_BROWSER_ACTIONS_ID_GROUP = |
Arrays.asList(R.id.browser_actions_custom_item_one, |
R.id.browser_actions_custom_item_two, R.id.browser_actions_custom_item_three, |
R.id.browser_actions_custom_item_four, R.id.browser_actions_custom_item_five); |
- private static final String TAG = "cr_BrowserActions"; |
- private static final boolean IS_NEW_UI_ENABLED = true; |
- |
// Items list that could be included in the Browser Actions context menu for type {@code LINK}. |
private final List<? extends ContextMenuItem> mBrowserActionsLinkGroup; |
@@ -78,44 +56,31 @@ |
private final SparseArray<PendingIntent> mCustomItemActionMap = new SparseArray<>(); |
private final ContextMenuParams mCurrentContextMenuParams; |
- private final BrowserActionsContextMenuItemDelegate mMenuItemDelegate; |
- private final Activity mActivity; |
+ private final BrowserActionsContextMenuItemDelegate mDelegate; |
+ private final BrowserActionActivity mActivity; |
private final Callback<Integer> mItemSelectedCallback; |
private final Runnable mOnMenuShown; |
private final Runnable mOnMenuClosed; |
- private final Runnable mOnMenuShownListener; |
private final Callback<Boolean> mOnShareClickedRunnable; |
private final PendingIntent mOnBrowserActionSelectedCallback; |
private final List<Pair<Integer, List<ContextMenuItem>>> mItems; |
- private final ProgressDialog mProgressDialog; |
- |
- private BrowserActionsTestDelegate mTestDelegate; |
- private boolean mIsOpenInBackgroundPending; |
- private boolean mIsNativeInitialized; |
- |
- public BrowserActionsContextMenuHelper(Activity activity, ContextMenuParams params, |
+ public BrowserActionsContextMenuHelper(BrowserActionActivity activity, ContextMenuParams params, |
List<BrowserActionItem> customItems, String sourcePackageName, |
- PendingIntent onBrowserActionSelectedCallback, final Runnable listener) { |
+ PendingIntent onBrowserActionSelectedCallback) { |
mActivity = activity; |
mCurrentContextMenuParams = params; |
- mOnMenuShownListener = listener; |
mOnMenuShown = new Runnable() { |
@Override |
public void run() { |
- mOnMenuShownListener.run(); |
- if (mTestDelegate != null) { |
- mTestDelegate.onBrowserActionsMenuShown(); |
- } |
+ mActivity.onMenuShown(); |
} |
}; |
mOnMenuClosed = new Runnable() { |
@Override |
public void run() { |
- if (!mIsOpenInBackgroundPending) { |
- mActivity.finish(); |
- } |
+ mActivity.finish(); |
} |
}; |
mItemSelectedCallback = new Callback<Integer>() { |
@@ -127,7 +92,7 @@ |
mOnShareClickedRunnable = new Callback<Boolean>() { |
@Override |
public void onResult(Boolean isShareLink) { |
- mMenuItemDelegate.share(true, mCurrentContextMenuParams.getLinkUrl()); |
+ mDelegate.share(true, mCurrentContextMenuParams.getLinkUrl()); |
} |
}; |
ShareContextMenuItem shareItem = new ShareContextMenuItem(R.drawable.ic_share_white_24dp, |
@@ -138,21 +103,10 @@ |
ChromeContextMenuItem.BROWSER_ACTIONS_OPEN_IN_INCOGNITO_TAB, |
ChromeContextMenuItem.BROWSER_ACTION_SAVE_LINK_AS, |
ChromeContextMenuItem.BROWSER_ACTIONS_COPY_ADDRESS, shareItem); |
- mMenuItemDelegate = new BrowserActionsContextMenuItemDelegate(mActivity, sourcePackageName); |
+ mDelegate = new BrowserActionsContextMenuItemDelegate(mActivity, sourcePackageName); |
mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback; |
- mProgressDialog = new ProgressDialog(mActivity); |
mItems = buildContextMenuItems(customItems); |
- } |
- |
- /** |
- * Sets the {@link BrowserActionsTestDelegate} for testing. |
- * @param testDelegate The delegate used to notified Browser Actions events. |
- */ |
- @VisibleForTesting |
- void setTestDelegateForTesting(BrowserActionsTestDelegate testDelegate) { |
- mTestDelegate = testDelegate; |
- mTestDelegate.initialize(mMenuItemDelegate, mCustomItemActionMap, mItems, mProgressDialog); |
} |
/** |
@@ -184,28 +138,24 @@ |
} |
} |
- boolean onItemSelected(int itemId) { |
+ private boolean onItemSelected(int itemId) { |
if (itemId == R.id.browser_actions_open_in_background) { |
- if (mIsNativeInitialized) { |
- handleOpenInBackground(); |
- } else { |
- mIsOpenInBackgroundPending = true; |
- waitNativeInitialized(); |
- } |
+ mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()); |
+ notifyBrowserActionSelected(BrowserActionsIntent.ITEM_OPEN_IN_NEW_TAB); |
} else if (itemId == R.id.browser_actions_open_in_incognito_tab) { |
- mMenuItemDelegate.onOpenInIncognitoTab(mCurrentContextMenuParams.getLinkUrl()); |
+ mDelegate.onOpenInIncognitoTab(mCurrentContextMenuParams.getLinkUrl()); |
notifyBrowserActionSelected(BrowserActionsIntent.ITEM_OPEN_IN_INCOGNITO); |
} else if (itemId == R.id.browser_actions_save_link_as) { |
- mMenuItemDelegate.startDownload(mCurrentContextMenuParams.getLinkUrl()); |
+ mDelegate.startDownload(mCurrentContextMenuParams.getLinkUrl()); |
notifyBrowserActionSelected(BrowserActionsIntent.ITEM_DOWNLOAD); |
} else if (itemId == R.id.browser_actions_copy_address) { |
- mMenuItemDelegate.onSaveToClipboard(mCurrentContextMenuParams.getLinkUrl()); |
+ mDelegate.onSaveToClipboard(mCurrentContextMenuParams.getLinkUrl()); |
notifyBrowserActionSelected(BrowserActionsIntent.ITEM_COPY); |
} else if (itemId == R.id.browser_actions_share) { |
- mMenuItemDelegate.share(false, mCurrentContextMenuParams.getLinkUrl()); |
+ mDelegate.share(false, mCurrentContextMenuParams.getLinkUrl()); |
notifyBrowserActionSelected(BrowserActionsIntent.ITEM_SHARE); |
} else if (mCustomItemActionMap.indexOfKey(itemId) >= 0) { |
- mMenuItemDelegate.onCustomItemSelected(mCustomItemActionMap.get(itemId)); |
+ mDelegate.onCustomItemSelected(mCustomItemActionMap.get(itemId)); |
} |
return true; |
} |
@@ -218,21 +168,6 @@ |
mOnBrowserActionSelectedCallback.send(mActivity, 0, additionalData, null, null); |
} catch (CanceledException e) { |
Log.e(TAG, "Browser Actions failed to send default items' pending intent."); |
- } |
- } |
- |
- /** |
- * 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(); |
} |
} |
@@ -273,28 +208,4 @@ |
@Override |
public void onViewDetachedFromWindow(View v) {} |
- |
- /** |
- * Finishes all pending actions which requires Chrome native libraries. |
- */ |
- public void onNativeInitialized() { |
- mIsNativeInitialized = true; |
- if (mTestDelegate != null) { |
- mTestDelegate.onFinishNativeInitialization(); |
- } |
- if (mIsOpenInBackgroundPending) { |
- mIsOpenInBackgroundPending = false; |
- dismissProgressDialog(); |
- handleOpenInBackground(); |
- mActivity.finish(); |
- } |
- } |
- |
- private void handleOpenInBackground() { |
- mMenuItemDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()); |
- if (mTestDelegate != null) { |
- mTestDelegate.onOpenTabInBackgroundStart(); |
- } |
- notifyBrowserActionSelected(BrowserActionsIntent.ITEM_OPEN_IN_NEW_TAB); |
- } |
} |