| Index: chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java
|
| index 0e06062af7a489ef323668b2156e2abad07e4ce4..342b660ebb93678437cc7d28081ec01885d79745 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java
|
| @@ -30,6 +30,7 @@ import org.chromium.chrome.browser.ChromeApplication;
|
| import org.chromium.chrome.browser.IntentHandler;
|
| import org.chromium.chrome.browser.KeyboardShortcuts;
|
| import org.chromium.chrome.browser.TabState;
|
| +import org.chromium.chrome.browser.UrlConstants;
|
| import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason;
|
| import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument;
|
| import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocumentTabSwitcher;
|
| @@ -68,6 +69,7 @@ import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager;
|
| import org.chromium.components.service_tab_launcher.ServiceTabLauncher;
|
| import org.chromium.content_public.browser.LoadUrlParams;
|
| import org.chromium.content_public.browser.NavigationEntry;
|
| +import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.ui.base.PageTransition;
|
|
|
| /**
|
| @@ -123,10 +125,10 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| @Override
|
| public void onUrlUpdated(Tab tab) {
|
| - assert mDocumentTab == tab;
|
| + assert mTab == tab;
|
|
|
| updateTaskDescription();
|
| - mTabModel.updateEntry(getIntent(), mDocumentTab);
|
| + mTabModel.updateEntry(getIntent(), mTab);
|
| }
|
|
|
| @Override
|
| @@ -151,10 +153,10 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| @Override
|
| public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
|
| - assert mDocumentTab == tab;
|
| + assert mTab == tab;
|
|
|
| updateTaskDescription();
|
| - mTabModel.updateEntry(getIntent(), mDocumentTab);
|
| + mTabModel.updateEntry(getIntent(), mTab);
|
| }
|
|
|
| @Override
|
| @@ -213,7 +215,7 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| private int mDefaultThemeColor;
|
|
|
| - private DocumentTab mDocumentTab;
|
| + private Tab mTab;
|
| private FindToolbarManager mFindToolbarManager;
|
| private boolean mRecordedStartupUma;
|
|
|
| @@ -221,7 +223,7 @@ public class DocumentActivity extends ChromeActivity {
|
| // used from the UI thread.
|
| private static boolean sIsFirstPageLoadStart = true;
|
|
|
| - /** Whether the DocumentTab has already been added to the TabModel. */
|
| + /** Whether the Tab has already been added to the TabModel. */
|
| private boolean mNeedsToBeAddedToTabModel;
|
|
|
| @Override
|
| @@ -356,8 +358,8 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| if (mNeedsToBeAddedToTabModel) {
|
| mNeedsToBeAddedToTabModel = false;
|
| - mTabModel.addTab(getIntent(), mDocumentTab);
|
| - getTabModelSelector().setTab(mDocumentTab);
|
| + mTabModel.addTab(getIntent(), mTab);
|
| + getTabModelSelector().setTab(mTab);
|
| }
|
|
|
| super.finishNativeInitialization();
|
| @@ -368,7 +370,7 @@ public class DocumentActivity extends ChromeActivity {
|
| */
|
| protected final int determineTabId() {
|
| int tabId = ActivityDelegate.getTabIdFromIntent(getIntent());
|
| - if (tabId == Tab.INVALID_TAB_ID && mDocumentTab != null) tabId = mDocumentTab.getId();
|
| + if (tabId == Tab.INVALID_TAB_ID && mTab != null) tabId = mTab.getId();
|
| return tabId;
|
| }
|
|
|
| @@ -403,10 +405,10 @@ public class DocumentActivity extends ChromeActivity {
|
| }
|
|
|
| // Check the Tab's history.
|
| - if (TextUtils.isEmpty(initialUrl) && mDocumentTab != null
|
| - && mDocumentTab.getWebContents() != null) {
|
| + if (TextUtils.isEmpty(initialUrl) && mTab != null
|
| + && mTab.getWebContents() != null) {
|
| NavigationEntry entry =
|
| - mDocumentTab.getWebContents().getNavigationController().getEntryAtIndex(0);
|
| + mTab.getWebContents().getNavigationController().getEntryAtIndex(0);
|
| if (entry != null) initialUrl = entry.getOriginalUrl();
|
| }
|
|
|
| @@ -415,12 +417,12 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| @Override
|
| public CharSequence onCreateDescription() {
|
| - return mDocumentTab != null ? mDocumentTab.getTitle() : "";
|
| + return mTab != null ? mTab.getTitle() : "";
|
| }
|
|
|
| @Override
|
| - public final DocumentTab getActivityTab() {
|
| - return mDocumentTab;
|
| + public final Tab getActivityTab() {
|
| + return mTab;
|
| }
|
|
|
| @Override
|
| @@ -457,8 +459,8 @@ public class DocumentActivity extends ChromeActivity {
|
| // If finishing, release all the active media players as we don't know when onStop()
|
| // will get called.
|
| super.onPause();
|
| - if (isFinishing() && mDocumentTab != null && mDocumentTab.getWebContents() != null) {
|
| - mDocumentTab.getWebContents().releaseMediaPlayers();
|
| + if (isFinishing() && mTab != null && mTab.getWebContents() != null) {
|
| + mTab.getWebContents().releaseMediaPlayers();
|
| }
|
| }
|
|
|
| @@ -482,7 +484,7 @@ public class DocumentActivity extends ChromeActivity {
|
| public void onResumeWithNative() {
|
| super.onResumeWithNative();
|
|
|
| - if (mDocumentTab != null) {
|
| + if (mTab != null) {
|
| AsyncTabCreationParams asyncParams = AsyncTabCreationParamsManager.remove(
|
| ActivityDelegate.getTabIdFromIntent(getIntent()));
|
| if (asyncParams != null && asyncParams.getLoadUrlParams().getUrl() != null) {
|
| @@ -534,7 +536,7 @@ public class DocumentActivity extends ChromeActivity {
|
| }
|
|
|
| if (asyncParams != null && asyncParams.getOriginalIntent() != null) {
|
| - mDocumentTab.getTabRedirectHandler().updateIntent(asyncParams.getOriginalIntent());
|
| + mTab.getTabRedirectHandler().updateIntent(asyncParams.getOriginalIntent());
|
| } else {
|
| if (getIntent() != null) {
|
| try {
|
| @@ -544,14 +546,14 @@ public class DocumentActivity extends ChromeActivity {
|
| // Ignore exception.
|
| }
|
| }
|
| - mDocumentTab.getTabRedirectHandler().updateIntent(intent);
|
| + mTab.getTabRedirectHandler().updateIntent(intent);
|
| }
|
|
|
| - mDocumentTab.loadUrl(loadUrlParams);
|
| + mTab.loadUrl(loadUrlParams);
|
| if (asyncParams != null && asyncParams.getRequestId() != null
|
| && asyncParams.getRequestId() > 0) {
|
| ServiceTabLauncher.onWebContentsForRequestAvailable(
|
| - asyncParams.getRequestId(), mDocumentTab.getWebContents());
|
| + asyncParams.getRequestId(), mTab.getWebContents());
|
| }
|
| }
|
|
|
| @@ -567,31 +569,27 @@ public class DocumentActivity extends ChromeActivity {
|
| : ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color);
|
| AsyncTabCreationParams asyncParams = AsyncTabCreationParamsManager.remove(
|
| ActivityDelegate.getTabIdFromIntent(getIntent()));
|
| - int tabId = determineTabId();
|
| - TabState tabState = mTabModel.getTabStateForDocument(tabId);
|
| boolean isAffiliated = asyncParams != null ? asyncParams.isAffiliated() : false;
|
| boolean isCreatedWithWebContents = asyncParams != null
|
| && asyncParams.getWebContents() != null;
|
|
|
| - mDocumentTab = DocumentTab.create(DocumentActivity.this, isIncognito(), getWindowAndroid(),
|
| - determineLastKnownUrl(), asyncParams != null ? asyncParams.getWebContents() : null,
|
| - tabState, isAffiliated, getTabCreationState(tabState != null, isAffiliated));
|
| + mTab = createActivityTab(asyncParams);
|
|
|
| if (asyncParams != null && asyncParams.getWebContents() != null) {
|
| Intent parentIntent = IntentUtils.safeGetParcelableExtra(getIntent(),
|
| IntentHandler.EXTRA_PARENT_INTENT);
|
| - mDocumentTab.setParentIntent(parentIntent);
|
| + mTab.setParentIntent(parentIntent);
|
| }
|
|
|
| if (mTabModel.isNativeInitialized()) {
|
| - mTabModel.addTab(getIntent(), mDocumentTab);
|
| + mTabModel.addTab(getIntent(), mTab);
|
| } else {
|
| mNeedsToBeAddedToTabModel = true;
|
| }
|
|
|
| - getTabModelSelector().setTab(mDocumentTab);
|
| + getTabModelSelector().setTab(mTab);
|
|
|
| - if (mDocumentTab.didFailToRestore()
|
| + if (mTab.didFailToRestore()
|
| || (asyncParams != null && asyncParams.getLoadUrlParams().getUrl() != null)) {
|
| if (!isCreatedWithWebContents) {
|
| // Don't load tabs in the background on low end devices. We will call
|
| @@ -612,7 +610,7 @@ public class DocumentActivity extends ChromeActivity {
|
| loadLastKnownUrl(asyncParams);
|
| }
|
| }
|
| - mDocumentTab.setShouldPreserve(IntentUtils.safeGetBooleanExtra(getIntent(),
|
| + mTab.setShouldPreserve(IntentUtils.safeGetBooleanExtra(getIntent(),
|
| IntentHandler.EXTRA_PRESERVE_TASK, false));
|
| }
|
|
|
| @@ -691,15 +689,15 @@ public class DocumentActivity extends ChromeActivity {
|
| mFindToolbarManager, overviewModeBehavior, layoutDriver, tabSwitcherClickHandler,
|
| null, null, null);
|
|
|
| - mDocumentTab.setFullscreenManager(getFullscreenManager());
|
| + mTab.setFullscreenManager(getFullscreenManager());
|
|
|
| - mDocumentTab.addObserver(new DocumentTabObserver());
|
| + mTab.addObserver(new DocumentTabObserver());
|
|
|
| removeWindowBackground();
|
|
|
| - if (mDocumentTab != null) {
|
| + if (mTab != null) {
|
| DataReductionPreferences.launchDataReductionSSLInfoBar(
|
| - DocumentActivity.this, mDocumentTab.getWebContents());
|
| + DocumentActivity.this, mTab.getWebContents());
|
| }
|
| }
|
|
|
| @@ -710,20 +708,20 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| private void updateLastTabId() {
|
| ChromeApplication.getDocumentTabModelSelector().selectModel(isIncognito());
|
| - int tabId = mDocumentTab == null
|
| - ? ActivityDelegate.getTabIdFromIntent(getIntent()) : mDocumentTab.getId();
|
| + int tabId = mTab == null
|
| + ? ActivityDelegate.getTabIdFromIntent(getIntent()) : mTab.getId();
|
| mTabModel.setLastShownId(tabId);
|
| }
|
|
|
| @Override
|
| public boolean handleBackPressed() {
|
| - if (mDocumentTab == null) return false;
|
| + if (mTab == null) return false;
|
|
|
| if (exitFullscreenIfShowing()) return true;
|
|
|
| - if (mDocumentTab.canGoBack()) {
|
| - mDocumentTab.goBack();
|
| - } else if (!mDocumentTab.shouldPreserve()) {
|
| + if (mTab.canGoBack()) {
|
| + mTab.goBack();
|
| + } else if (!mTab.shouldPreserve()) {
|
| finishAndRemoveTask();
|
| } else {
|
| moveTaskToBack(true);
|
| @@ -737,6 +735,31 @@ public class DocumentActivity extends ChromeActivity {
|
| return (TabDelegate) super.getTabCreator(incognito);
|
| }
|
|
|
| + private Tab createActivityTab(AsyncTabCreationParams asyncParams) {
|
| + boolean isAffiliated = asyncParams != null ? asyncParams.isAffiliated() : false;
|
| + boolean isCreatedWithWebContents = asyncParams != null
|
| + && asyncParams.getWebContents() != null;
|
| + int tabId = determineTabId();
|
| + int parentTabId = getIntent().getIntExtra(
|
| + IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_ID);
|
| + TabState tabState = mTabModel.getTabStateForDocument(tabId);
|
| + boolean hasTabState = tabState != null;
|
| + String url = determineLastKnownUrl();
|
| +
|
| + Tab tab = new Tab(tabId, parentTabId, isIncognito(), this, getWindowAndroid(),
|
| + getTabLaunchType(url, hasTabState, isAffiliated),
|
| + getTabCreationState(hasTabState, isAffiliated), tabState);
|
| +
|
| + // Initialize tab and web contents.
|
| + WebContents webContents = isCreatedWithWebContents ? asyncParams.getWebContents() : null;
|
| + tab.initialize(webContents, getTabContentManager(),
|
| + new DocumentTabDelegateFactory(), isAffiliated, hasTabState);
|
| + tab.getView().requestFocus();
|
| + if (isCreatedWithWebContents) webContents.resumeLoadingCreatedWebContents();
|
| +
|
| + return tab;
|
| + }
|
| +
|
| /**
|
| * This cannot return {@link TabCreationState#FROZEN_ON_RESTORE_FAILED} since the Tab has
|
| * to be created first to even attempt restore.
|
| @@ -750,6 +773,16 @@ public class DocumentActivity extends ChromeActivity {
|
| return TabCreationState.LIVE_IN_FOREGROUND;
|
| }
|
|
|
| + private TabLaunchType getTabLaunchType(
|
| + String url, boolean hasTabState, boolean isAffiliated) {
|
| + if (hasTabState) return TabLaunchType.FROM_RESTORE;
|
| + if (isAffiliated) return TabLaunchType.FROM_LONGPRESS_BACKGROUND;
|
| + if (!TextUtils.isEmpty(url) && url.equals(UrlConstants.NTP_URL)) {
|
| + return TabLaunchType.FROM_MENU_OR_OVERVIEW;
|
| + }
|
| + return TabLaunchType.FROM_EXTERNAL_APP;
|
| + }
|
| +
|
| @Override
|
| public void createContextualSearchTab(String searchUrl) {
|
| AsyncTabCreationParams asyncParams =
|
| @@ -784,11 +817,11 @@ public class DocumentActivity extends ChromeActivity {
|
| } else if (id == R.id.all_bookmarks_menu_id) {
|
| StartupMetrics.getInstance().recordOpenedBookmarks();
|
| if (!EnhancedBookmarkUtils.showEnhancedBookmarkIfEnabled(this)) {
|
| - NewTabPage.launchBookmarksDialog(this, mDocumentTab, getTabModelSelector());
|
| + NewTabPage.launchBookmarksDialog(this, mTab, getTabModelSelector());
|
| }
|
| RecordUserAction.record("MobileMenuAllBookmarks");
|
| } else if (id == R.id.recent_tabs_menu_id) {
|
| - NewTabPage.launchRecentTabsDialog(this, mDocumentTab);
|
| + NewTabPage.launchRecentTabsDialog(this, mTab);
|
| RecordUserAction.record("MobileMenuOpenTabs");
|
| } else if (id == R.id.find_in_page_id) {
|
| mFindToolbarManager.showToolbar();
|
| @@ -826,7 +859,7 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| @Override
|
| public boolean shouldShowAppMenu() {
|
| - if (mDocumentTab == null || !getToolbarManager().isInitialized()) {
|
| + if (mTab == null || !getToolbarManager().isInitialized()) {
|
| return false;
|
| }
|
|
|
| @@ -840,7 +873,7 @@ public class DocumentActivity extends ChromeActivity {
|
| }
|
|
|
| private void updateTaskDescription() {
|
| - if (mDocumentTab == null) {
|
| + if (mTab == null) {
|
| updateTaskDescription(null, null);
|
| return;
|
| }
|
| @@ -851,8 +884,8 @@ public class DocumentActivity extends ChromeActivity {
|
| return;
|
| }
|
|
|
| - String label = mDocumentTab.getTitle();
|
| - String domain = UrlUtilities.getDomainAndRegistry(mDocumentTab.getUrl(), false);
|
| + String label = mTab.getTitle();
|
| + String domain = UrlUtilities.getDomainAndRegistry(mTab.getUrl(), false);
|
| if (TextUtils.isEmpty(label)) {
|
| label = domain;
|
| }
|
| @@ -863,7 +896,7 @@ public class DocumentActivity extends ChromeActivity {
|
|
|
| Bitmap bitmap = null;
|
| if (!isIncognito()) {
|
| - bitmap = mIcon.getBitmap(mDocumentTab.getUrl(), mLargestFavicon);
|
| + bitmap = mIcon.getBitmap(mTab.getUrl(), mLargestFavicon);
|
| }
|
|
|
| updateTaskDescription(label, bitmap);
|
| @@ -889,7 +922,7 @@ public class DocumentActivity extends ChromeActivity {
|
| */
|
| boolean isNewTabPage() {
|
| String url;
|
| - if (mDocumentTab == null) {
|
| + if (mTab == null) {
|
| // If the Tab hasn't been created yet, then we're really early in initialization.
|
| // Use a combination of the original URL from the Intent and whether or not the Tab is
|
| // retargetable to know whether or not the user navigated away from the NTP.
|
| @@ -899,7 +932,7 @@ public class DocumentActivity extends ChromeActivity {
|
| url = IntentHandler.getUrlFromIntent(getIntent());
|
| if (mTabModel.hasEntryForTabId(tabId) && !mTabModel.isRetargetable(tabId)) return false;
|
| } else {
|
| - url = mDocumentTab.getUrl();
|
| + url = mTab.getUrl();
|
| }
|
| return NewTabPage.isNTPUrl(url);
|
| }
|
|
|