Android: Makes SelectionPopupController init simpler
Embedders have to do a bit convoluted initialization for SelectionPopupController (its action mode callback to be set requires a helper instance from the SPC itself). This CL makes it simpler by delegating the helper initialization to action mode callback constructor. |ceateContentViewCore| in Tab.java, For instance: From: SelectionPopupController controller = SelectionPopupController.fromWebContents(webContents); ChromeActionModeCallback actionModeCallback = new ChromeActionModeCallback(this, controller.getActionModeCallbackHelper()); controller.setActionModeCallback(actionModeCallback); SelectionPopupController.fromWebContents(webContents) setActionModeCallback(new ChromeActionModeCallback(this, webContents)); to: Change-Id: Ifec52ce2c1f9446f47de72295be1abc5e1c361d7 Reviewed-on: https://chromium-review.googlesource.com/1029757 Reviewed-by: Ted Choc <tedchoc@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org> Cr-Commit-Position: refs/heads/master@{#556037}
This commit is contained in:
android_webview/java/src/org/chromium/android_webview
chrome/android
java
src
org
chromium
chrome
browser
junit
src
org
chromium
chrome
content/shell/android/java/src/org/chromium/content_shell
@ -17,6 +17,8 @@ import android.view.MenuItem;
|
||||
import org.chromium.base.metrics.RecordUserAction;
|
||||
import org.chromium.content.R;
|
||||
import org.chromium.content_public.browser.ActionModeCallbackHelper;
|
||||
import org.chromium.content_public.browser.SelectionPopupController;
|
||||
import org.chromium.content_public.browser.WebContents;
|
||||
|
||||
/**
|
||||
* A class that handles selection action mode for Android WebView.
|
||||
@ -27,11 +29,11 @@ public class AwActionModeCallback implements ActionMode.Callback {
|
||||
private final ActionModeCallbackHelper mHelper;
|
||||
private int mAllowedMenuItems;
|
||||
|
||||
public AwActionModeCallback(Context context, AwContents awContents,
|
||||
ActionModeCallbackHelper helper) {
|
||||
public AwActionModeCallback(Context context, AwContents awContents, WebContents webContents) {
|
||||
mContext = context;
|
||||
mAwContents = awContents;
|
||||
mHelper = helper;
|
||||
mHelper =
|
||||
SelectionPopupController.fromWebContents(webContents).getActionModeCallbackHelper();
|
||||
mHelper.setAllowedMenuItems(0); // No item is allowed by default for WebView.
|
||||
}
|
||||
|
||||
|
@ -875,8 +875,7 @@ public class AwContents implements SmartClipProvider {
|
||||
viewDelegate, internalDispatcher, windowAndroid);
|
||||
mContentViewCore.setHideKeyboardOnBlur(false);
|
||||
SelectionPopupController controller = SelectionPopupController.fromWebContents(webContents);
|
||||
controller.setActionModeCallback(
|
||||
new AwActionModeCallback(mContext, this, controller.getActionModeCallbackHelper()));
|
||||
controller.setActionModeCallback(new AwActionModeCallback(mContext, this, webContents));
|
||||
if (mAutofillProvider != null) {
|
||||
controller.setNonSelectionActionModeCallback(
|
||||
new AutofillActionModeCallback(mContext, mAutofillProvider));
|
||||
|
@ -23,6 +23,8 @@ import org.chromium.components.feature_engagement.EventConstants;
|
||||
import org.chromium.content.R;
|
||||
import org.chromium.content_public.browser.ActionModeCallbackHelper;
|
||||
import org.chromium.content_public.browser.LoadUrlParams;
|
||||
import org.chromium.content_public.browser.SelectionPopupController;
|
||||
import org.chromium.content_public.browser.WebContents;
|
||||
import org.chromium.ui.base.PageTransition;
|
||||
|
||||
/**
|
||||
@ -32,9 +34,14 @@ public class ChromeActionModeCallback implements ActionMode.Callback {
|
||||
private final Tab mTab;
|
||||
private final ActionModeCallbackHelper mHelper;
|
||||
|
||||
public ChromeActionModeCallback(Tab tab, ActionModeCallbackHelper helper) {
|
||||
public ChromeActionModeCallback(Tab tab, WebContents webContents) {
|
||||
mTab = tab;
|
||||
mHelper = helper;
|
||||
mHelper = getActionModeCallbackHelper(webContents);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected ActionModeCallbackHelper getActionModeCallbackHelper(WebContents webContents) {
|
||||
return SelectionPopupController.fromWebContents(webContents).getActionModeCallbackHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1795,10 +1795,8 @@ public class Tab
|
||||
R.string.accessibility_content_view));
|
||||
ContentViewCore cvc = ContentViewCore.create(mThemedApplicationContext, PRODUCT_VERSION,
|
||||
webContents, new TabViewAndroidDelegate(this, cv), cv, getWindowAndroid());
|
||||
SelectionPopupController controller = SelectionPopupController.fromWebContents(webContents);
|
||||
ChromeActionModeCallback actionModeCallback =
|
||||
new ChromeActionModeCallback(this, controller.getActionModeCallbackHelper());
|
||||
controller.setActionModeCallback(actionModeCallback);
|
||||
SelectionPopupController.fromWebContents(webContents)
|
||||
.setActionModeCallback(new ChromeActionModeCallback(this, webContents));
|
||||
return cvc;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import org.chromium.chrome.browser.locale.LocaleManager;
|
||||
import org.chromium.chrome.browser.tab.Tab;
|
||||
import org.chromium.content.R;
|
||||
import org.chromium.content_public.browser.ActionModeCallbackHelper;
|
||||
import org.chromium.content_public.browser.WebContents;
|
||||
import org.chromium.testing.local.LocalRobolectricTestRunner;
|
||||
|
||||
/**
|
||||
@ -45,7 +46,18 @@ public class ChromeActionModeCallbackTest {
|
||||
@Mock
|
||||
private Menu mMenu;
|
||||
|
||||
private ChromeActionModeCallback mActionModeCallback;
|
||||
private class TestChromeActionModeCallback extends ChromeActionModeCallback {
|
||||
public TestChromeActionModeCallback(Tab tab, ActionModeCallbackHelper helper) {
|
||||
super(tab, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionModeCallbackHelper getActionModeCallbackHelper(WebContents webContents) {
|
||||
return mActionModeCallbackHelper;
|
||||
}
|
||||
}
|
||||
|
||||
private TestChromeActionModeCallback mActionModeCallback;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -55,7 +67,7 @@ public class ChromeActionModeCallbackTest {
|
||||
RecordUserAction.setDisabledForTests(true);
|
||||
|
||||
mActionModeCallback =
|
||||
Mockito.spy(new ChromeActionModeCallback(mTab, mActionModeCallbackHelper));
|
||||
Mockito.spy(new TestChromeActionModeCallback(mTab, mActionModeCallbackHelper));
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -306,8 +306,8 @@ public class Shell extends LinearLayout {
|
||||
mContentViewCore = (ContentViewCoreImpl) ContentViewCore.create(
|
||||
context, "", webContents, mViewAndroidDelegate, cv, mWindow);
|
||||
mWebContents = webContents;
|
||||
SelectionPopupController controller = SelectionPopupController.fromWebContents(webContents);
|
||||
controller.setActionModeCallback(defaultActionCallback());
|
||||
SelectionPopupController.fromWebContents(webContents)
|
||||
.setActionModeCallback(defaultActionCallback());
|
||||
mNavigationController = mWebContents.getNavigationController();
|
||||
if (getParent() != null) mWebContents.onShow();
|
||||
if (mWebContents.getVisibleUrl() != null) {
|
||||
|
Reference in New Issue
Block a user