Commit aaaf1711 authored by tedchoc's avatar tedchoc Committed by Commit bot

Ensure CCTs have the proper context menu on tab restore.

Custom tab context menus worked previously because CustomTabActivity
was in charge of creating the initial tab, and all subsequent tabs
reuse the delegate of the parent tab.

When restoring, the TabModelSelectorImpl via TabPersistentStore
was creating the tabs and using the default logic in ChromeTabCreator.

This change moves ChromeTabCreator creation to the activities
themselves, which allows CCTs to overwrite the default tab delegate
construction.  This also moves the svelte tab saving logic to the
selector, which is consistent with all other tab saving behavior (and
allows the activity to be unaware of that dependency and enables
creation w/ fewer params).

BUG=649139

Review-Url: https://codereview.chromium.org/2359923005
Cr-Commit-Position: refs/heads/master@{#420702}
parent a9d229b2
......@@ -107,7 +107,6 @@ import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.SyncController;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
import org.chromium.chrome.browser.tabmodel.ChromeTabCreator;
import org.chromium.chrome.browser.tabmodel.EmptyTabModel;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModel;
......@@ -1219,10 +1218,12 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
}
/**
* Sets the {@link ChromeTabCreator}s owned by this {@link ChromeActivity}.
* @param regularTabCreator A {@link ChromeTabCreator} instance.
* Sets the {@link org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator}s owned by
* this {@link ChromeActivity}.
* @param regularTabCreator The creator for normal tabs.
* @param incognitoTabCreator The creator for incognito tabs.
*/
public void setTabCreators(TabCreatorManager.TabCreator regularTabCreator,
protected void setTabCreators(TabCreatorManager.TabCreator regularTabCreator,
TabCreatorManager.TabCreator incognitoTabCreator) {
mRegularTabCreator = regularTabCreator;
mIncognitoTabCreator = incognitoTabCreator;
......
......@@ -1035,6 +1035,9 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
finish();
return;
}
setTabCreators(
new ChromeTabCreator(this, getWindowAndroid(), false),
new ChromeTabCreator(this, getWindowAndroid(), true));
mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelectorImpl) {
private boolean mIsFirstPageLoadStart = true;
......
......@@ -52,7 +52,9 @@ import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.pageinfo.WebsiteSettingsPopup;
import org.chromium.chrome.browser.rappor.RapporServiceBridge;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabDelegateFactory;
import org.chromium.chrome.browser.tab.TabIdManager;
import org.chromium.chrome.browser.tabmodel.ChromeTabCreator;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelObserver;
......@@ -68,6 +70,7 @@ import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.common.Referrer;
import org.chromium.ui.base.PageTransition;
import org.chromium.ui.base.WindowAndroid;
/**
* The activity for custom tabs. It will be launched on top of a client's task.
......@@ -128,6 +131,22 @@ public class CustomTabActivity extends ChromeActivity {
}
}
private static class CustomTabCreator extends ChromeTabCreator {
private final boolean mSupportsUrlBarHiding;
public CustomTabCreator(
ChromeActivity activity, WindowAndroid nativeWindow, boolean incognito,
boolean supportsUrlBarHiding) {
super(activity, nativeWindow, incognito);
mSupportsUrlBarHiding = supportsUrlBarHiding;
}
@Override
public TabDelegateFactory createDefaultTabDelegateFactory() {
return new CustomTabDelegateFactory(mSupportsUrlBarHiding);
}
}
private PageLoadMetricsObserver mMetricsObserver;
// Only the normal tab model is observed because there is no incognito tabmodel in Custom Tabs.
......@@ -271,6 +290,13 @@ public class CustomTabActivity extends ChromeActivity {
getTaskId(), getSavedInstanceState() != null);
setTabModelSelector(new TabModelSelectorImpl(
this, persistencePolicy, getWindowAndroid(), false));
setTabCreators(
new CustomTabCreator(
this, getWindowAndroid(), false,
mIntentDataProvider.shouldEnableUrlBarHiding()),
new CustomTabCreator(
this, getWindowAndroid(), true,
mIntentDataProvider.shouldEnableUrlBarHiding()));
getToolbarManager().setCloseButtonDrawable(mIntentDataProvider.getCloseButtonDrawable());
getToolbarManager().setShowTitle(mIntentDataProvider.getTitleVisibilityState()
......
......@@ -2647,6 +2647,14 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
mShouldPreserve = preserve;
}
/**
* @return Whether there are pending {@link LoadUrlParams} associated with the tab. This
* indicates the tab was created for lazy load.
*/
public boolean hasPendingLoadParams() {
return mPendingLoadParams != null;
}
/**
* @return Parameters that should be used for a lazily loaded Tab. May be null.
*/
......
......@@ -37,20 +37,16 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
private final ChromeActivity mActivity;
private final WindowAndroid mNativeWindow;
private final TabModelOrderController mOrderController;
private final TabPersistentStore mTabSaver;
private final boolean mIncognito;
private TabModel mTabModel;
private TabContentManager mTabContentManager;
private TabModelOrderController mOrderController;
public ChromeTabCreator(ChromeActivity activity, WindowAndroid nativeWindow,
TabModelOrderController orderController, TabPersistentStore tabSaver,
boolean incognito) {
public ChromeTabCreator(
ChromeActivity activity, WindowAndroid nativeWindow, boolean incognito) {
mActivity = activity;
mNativeWindow = nativeWindow;
mOrderController = orderController;
mTabSaver = tabSaver;
mIncognito = incognito;
}
......@@ -116,7 +112,7 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
AsyncTabParamsManager.remove(assignedTabId);
boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
TabDelegateFactory delegateFactory = parent == null ? new TabDelegateFactory()
TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory()
: parent.getDelegateFactory();
Tab tab;
if (asyncParams != null && asyncParams.getTabToReparent() != null) {
......@@ -125,7 +121,8 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
TabReparentingParams params = (TabReparentingParams) asyncParams;
tab = params.getTabToReparent();
tab.attachAndFinishReparenting(mActivity, new TabDelegateFactory(), params);
tab.attachAndFinishReparenting(
mActivity, createDefaultTabDelegateFactory(), params);
} else if (asyncParams != null && asyncParams.getWebContents() != null) {
openInForeground = true;
WebContents webContents = asyncParams.getWebContents();
......@@ -150,7 +147,6 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
tab = Tab.createTabForLazyLoad(mActivity, mIncognito, mNativeWindow, type,
parentId, loadUrlParams);
tab.initialize(null, mTabContentManager, delegateFactory, !openInForeground, false);
mTabSaver.addTabToSaveQueue(tab);
} else {
tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
mNativeWindow, type, parentId, !openInForeground);
......@@ -198,7 +194,7 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
if (index != TabModel.INVALID_TAB_INDEX) position = index + 1;
boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
TabDelegateFactory delegateFactory = parent == null ? new TabDelegateFactory()
TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory()
: parent.getDelegateFactory();
Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
mNativeWindow, type, parentId, !openInForeground);
......@@ -302,7 +298,8 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
id, mActivity, state.isIncognito(), mNativeWindow, state.parentId, state);
boolean selectTab = mOrderController.willOpenInForeground(TabLaunchType.FROM_RESTORE,
state.isIncognito());
tab.initialize(null, mTabContentManager, new TabDelegateFactory(), !selectTab, false);
tab.initialize(
null, mTabContentManager, createDefaultTabDelegateFactory(), !selectTab, false);
assert state.isIncognito() == mIncognito;
mTabModel.addTab(tab, index, TabLaunchType.FROM_RESTORE);
return tab;
......@@ -337,12 +334,22 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
/**
* Sets the tab model and tab content manager to use.
* @param model The new {@link TabModel} to use.
* @param manager The new {@link TabContentManager} to use.
* @param model The new {@link TabModel} to use.
* @param orderController The controller for determining the order of tabs.
* @param manager The new {@link TabContentManager} to use.
*/
public void setTabModel(TabModel model, TabContentManager manager) {
public void setTabModel(
TabModel model, TabModelOrderController orderController, TabContentManager manager) {
mTabModel = model;
mOrderController = orderController;
mTabContentManager = manager;
}
/**
* @return The default tab delegate factory to be used if creating new tabs w/o parents.
*/
public TabDelegateFactory createDefaultTabDelegateFactory() {
return new TabDelegateFactory();
}
}
......@@ -57,9 +57,6 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
private CloseAllTabsDelegate mCloseAllTabsDelegate;
private ChromeTabCreator mRegularTabCreator;
private ChromeTabCreator mIncognitoTabCreator;
/**
* Builds a {@link TabModelSelectorImpl} instance.
* @param activity The {@link ChromeActivity} this model selector lives in.
......@@ -108,11 +105,6 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
mTabSaver = new TabPersistentStore(persistencePolicy, this, mActivity, mActivity,
persistentStoreObserver, mergeTabs);
mOrderController = new TabModelOrderController(this);
mRegularTabCreator = new ChromeTabCreator(
mActivity, windowAndroid, mOrderController, mTabSaver, false);
mIncognitoTabCreator = new ChromeTabCreator(
mActivity, windowAndroid, mOrderController, mTabSaver, true);
mActivity.setTabCreators(mRegularTabCreator, mIncognitoTabCreator);
}
@Override
......@@ -161,14 +153,16 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
assert !mActiveState : "onNativeLibraryReady called twice!";
mTabContentManager = tabContentProvider;
TabModelImpl normalModel = new TabModelImpl(false, mRegularTabCreator, mIncognitoTabCreator,
ChromeTabCreator regularTabCreator = (ChromeTabCreator) mActivity.getTabCreator(false);
ChromeTabCreator incognitoTabCreator = (ChromeTabCreator) mActivity.getTabCreator(true);
TabModelImpl normalModel = new TabModelImpl(false, regularTabCreator, incognitoTabCreator,
mUma, mOrderController, mTabContentManager, mTabSaver, this, mIsUndoSupported);
TabModel incognitoModel = new IncognitoTabModel(new IncognitoTabModelImplCreator(
mRegularTabCreator, mIncognitoTabCreator, mUma, mOrderController,
regularTabCreator, incognitoTabCreator, mUma, mOrderController,
mTabContentManager, mTabSaver, this));
initialize(isIncognitoSelected(), normalModel, incognitoModel);
mRegularTabCreator.setTabModel(normalModel, mTabContentManager);
mIncognitoTabCreator.setTabModel(incognitoModel, mTabContentManager);
regularTabCreator.setTabModel(normalModel, mOrderController, mTabContentManager);
incognitoTabCreator.setTabModel(incognitoModel, mOrderController, mTabContentManager);
mTabSaver.setTabContentManager(mTabContentManager);
addObserver(new EmptyTabModelSelectorObserver() {
......@@ -178,6 +172,8 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
if (TabModelUtils.getTabById(getCurrentModel(), tab.getId()) != null) {
mTabContentManager.invalidateIfChanged(tab.getId(), tab.getUrl());
}
if (tab.hasPendingLoadParams()) mTabSaver.addTabToSaveQueue(tab);
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment