| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; | 58 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; |
| 59 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil
ityDelegate; | 59 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil
ityDelegate; |
| 60 import org.chromium.chrome.browser.gsa.GSAState; | 60 import org.chromium.chrome.browser.gsa.GSAState; |
| 61 import org.chromium.chrome.browser.metrics.PageLoadMetrics; | 61 import org.chromium.chrome.browser.metrics.PageLoadMetrics; |
| 62 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 62 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
| 63 import org.chromium.chrome.browser.page_info.PageInfoPopup; | 63 import org.chromium.chrome.browser.page_info.PageInfoPopup; |
| 64 import org.chromium.chrome.browser.rappor.RapporServiceBridge; | 64 import org.chromium.chrome.browser.rappor.RapporServiceBridge; |
| 65 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 65 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 66 import org.chromium.chrome.browser.tab.Tab; | 66 import org.chromium.chrome.browser.tab.Tab; |
| 67 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 67 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 68 import org.chromium.chrome.browser.tabmodel.AsyncTabParams; | |
| 69 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; | 68 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; |
| 70 import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; | 69 import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; |
| 71 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 70 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 72 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 71 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 73 import org.chromium.chrome.browser.tabmodel.TabModelObserver; | 72 import org.chromium.chrome.browser.tabmodel.TabModelObserver; |
| 74 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 73 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 75 import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl; | 74 import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl; |
| 76 import org.chromium.chrome.browser.tabmodel.TabReparentingParams; | 75 import org.chromium.chrome.browser.tabmodel.TabReparentingParams; |
| 77 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; | 76 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; |
| 78 import org.chromium.chrome.browser.util.ColorUtils; | 77 import org.chromium.chrome.browser.util.ColorUtils; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 */ | 91 */ |
| 93 public class CustomTabActivity extends ChromeActivity { | 92 public class CustomTabActivity extends ChromeActivity { |
| 94 | 93 |
| 95 private static final String TAG = "CustomTabActivity"; | 94 private static final String TAG = "CustomTabActivity"; |
| 96 private static final String LAST_URL_PREF = "pref_last_custom_tab_url"; | 95 private static final String LAST_URL_PREF = "pref_last_custom_tab_url"; |
| 97 | 96 |
| 98 // For CustomTabs.WebContentsStateOnLaunch, see histograms.xml. Append only. | 97 // For CustomTabs.WebContentsStateOnLaunch, see histograms.xml. Append only. |
| 99 private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0; | 98 private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0; |
| 100 private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1; | 99 private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1; |
| 101 private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2; | 100 private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2; |
| 102 private static final int WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS = 3; | 101 private static final int WEBCONTENTS_STATE_MAX = 3; |
| 103 private static final int WEBCONTENTS_STATE_MAX = 4; | |
| 104 | 102 |
| 105 private static CustomTabContentHandler sActiveContentHandler; | 103 private static CustomTabContentHandler sActiveContentHandler; |
| 106 | 104 |
| 107 private FindToolbarManager mFindToolbarManager; | 105 private FindToolbarManager mFindToolbarManager; |
| 108 private CustomTabIntentDataProvider mIntentDataProvider; | 106 private CustomTabIntentDataProvider mIntentDataProvider; |
| 109 private CustomTabsSessionToken mSession; | 107 private CustomTabsSessionToken mSession; |
| 110 private CustomTabContentHandler mCustomTabContentHandler; | 108 private CustomTabContentHandler mCustomTabContentHandler; |
| 111 private Tab mMainTab; | 109 private Tab mMainTab; |
| 112 private CustomTabBottomBarDelegate mBottomBarDelegate; | 110 private CustomTabBottomBarDelegate mBottomBarDelegate; |
| 113 private CustomTabTabPersistencePolicy mTabPersistencePolicy; | 111 private CustomTabTabPersistencePolicy mTabPersistencePolicy; |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess
ion)); | 567 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess
ion)); |
| 570 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { | 568 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { |
| 571 tab.enableEmbeddedMediaExperience(true); | 569 tab.enableEmbeddedMediaExperience(true); |
| 572 } | 570 } |
| 573 initializeMainTab(tab); | 571 initializeMainTab(tab); |
| 574 return tab; | 572 return tab; |
| 575 } | 573 } |
| 576 | 574 |
| 577 private Tab createMainTab() { | 575 private Tab createMainTab() { |
| 578 CustomTabsConnection connection = CustomTabsConnection.getInstance(getAp
plication()); | 576 CustomTabsConnection connection = CustomTabsConnection.getInstance(getAp
plication()); |
| 579 WebContents webContents = takeWebContents(connection); | 577 String url = getUrlToLoad(); |
| 580 | 578 String referrerUrl = connection.getReferrer(mSession, getIntent()); |
| 581 int assignedTabId = IntentUtils.safeGetIntExtra( | 579 Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g
etWindowAndroid(), |
| 582 getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); | |
| 583 int parentTabId = IntentUtils.safeGetIntExtra( | |
| 584 getIntent(), IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_
ID); | |
| 585 Tab tab = new Tab(assignedTabId, parentTabId, false, this, getWindowAndr
oid(), | |
| 586 TabLaunchType.FROM_EXTERNAL_APP, null, null); | 580 TabLaunchType.FROM_EXTERNAL_APP, null, null); |
| 587 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess
ion)); | 581 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess
ion)); |
| 582 |
| 583 int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; |
| 584 WebContents webContents = connection.takePrerenderedUrl(mSession, url, r
eferrerUrl); |
| 585 mUsingPrerender = webContents != null; |
| 586 if (mUsingPrerender) webContentsStateOnLaunch = WEBCONTENTS_STATE_PREREN
DERED_WEBCONTENTS; |
| 587 if (!mUsingPrerender) { |
| 588 webContents = WarmupManager.getInstance().takeSpareWebContents(false
, false); |
| 589 if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STAT
E_SPARE_WEBCONTENTS; |
| 590 } |
| 591 RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOn
Launch", |
| 592 webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); |
| 593 if (webContents == null) { |
| 594 webContents = WebContentsFactory.createWebContentsWithWarmRenderer(f
alse, false); |
| 595 } |
| 596 if (!mUsingPrerender) { |
| 597 connection.resetPostMessageHandlerForSession(mSession, webContents); |
| 598 } |
| 588 tab.initialize( | 599 tab.initialize( |
| 589 webContents, getTabContentManager(), | 600 webContents, getTabContentManager(), |
| 590 new CustomTabDelegateFactory( | 601 new CustomTabDelegateFactory( |
| 591 mIntentDataProvider.shouldEnableUrlBarHiding(), | 602 mIntentDataProvider.shouldEnableUrlBarHiding(), |
| 592 mIntentDataProvider.isOpenedByChrome(), | 603 mIntentDataProvider.isOpenedByChrome(), |
| 593 getFullscreenManager().getBrowserVisibilityDelegate()), | 604 getFullscreenManager().getBrowserVisibilityDelegate()), |
| 594 false, false); | 605 false, false); |
| 595 | 606 |
| 596 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { | 607 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { |
| 597 tab.enableEmbeddedMediaExperience(true); | 608 tab.enableEmbeddedMediaExperience(true); |
| 598 } | 609 } |
| 599 | 610 |
| 600 initializeMainTab(tab); | 611 initializeMainTab(tab); |
| 601 return tab; | 612 return tab; |
| 602 } | 613 } |
| 603 | 614 |
| 604 private WebContents takeWebContents(CustomTabsConnection connection) { | |
| 605 mUsingPrerender = true; | |
| 606 int webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS
; | |
| 607 WebContents webContents = takePrerenderedWebContents(connection); | |
| 608 | |
| 609 if (webContents == null) { | |
| 610 mUsingPrerender = false; | |
| 611 webContents = takeAsyncWebContents(); | |
| 612 if (webContents != null) { | |
| 613 webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONT
ENTS; | |
| 614 } else { | |
| 615 webContents = WarmupManager.getInstance().takeSpareWebContents(f
alse, false); | |
| 616 if (webContents != null) { | |
| 617 webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTEN
TS; | |
| 618 } else { | |
| 619 webContents = | |
| 620 WebContentsFactory.createWebContentsWithWarmRenderer
(false, false); | |
| 621 webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; | |
| 622 } | |
| 623 } | |
| 624 } | |
| 625 | |
| 626 RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOn
Launch", | |
| 627 webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); | |
| 628 | |
| 629 if (!mUsingPrerender) { | |
| 630 connection.resetPostMessageHandlerForSession(mSession, webContents); | |
| 631 } | |
| 632 | |
| 633 return webContents; | |
| 634 } | |
| 635 | |
| 636 private WebContents takePrerenderedWebContents(CustomTabsConnection connecti
on) { | |
| 637 String url = getUrlToLoad(); | |
| 638 String referrerUrl = connection.getReferrer(mSession, getIntent()); | |
| 639 return connection.takePrerenderedUrl(mSession, url, referrerUrl); | |
| 640 } | |
| 641 | |
| 642 private WebContents takeAsyncWebContents() { | |
| 643 int assignedTabId = IntentUtils.safeGetIntExtra( | |
| 644 getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); | |
| 645 AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId)
; | |
| 646 if (asyncParams == null) return null; | |
| 647 return asyncParams.getWebContents(); | |
| 648 } | |
| 649 | |
| 650 private void initializeMainTab(Tab tab) { | 615 private void initializeMainTab(Tab tab) { |
| 651 tab.getTabRedirectHandler().updateIntent(getIntent()); | 616 tab.getTabRedirectHandler().updateIntent(getIntent()); |
| 652 tab.getView().requestFocus(); | 617 tab.getView().requestFocus(); |
| 653 mTabObserver = new CustomTabObserver( | 618 mTabObserver = new CustomTabObserver( |
| 654 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome
()); | 619 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome
()); |
| 655 | 620 |
| 656 mMetricsObserver = new PageLoadMetricsObserver( | 621 mMetricsObserver = new PageLoadMetricsObserver( |
| 657 CustomTabsConnection.getInstance(getApplication()), mSession, ta
b); | 622 CustomTabsConnection.getInstance(getApplication()), mSession, ta
b); |
| 658 tab.addObserver(mTabObserver); | 623 tab.addObserver(mTabObserver); |
| 659 | 624 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 // Custom Tabs can be used to open Chrome help pages before the ToS has
been accepted. | 1173 // Custom Tabs can be used to open Chrome help pages before the ToS has
been accepted. |
| 1209 if (IntentHandler.isIntentChromeOrFirstParty(intent) | 1174 if (IntentHandler.isIntentChromeOrFirstParty(intent) |
| 1210 && IntentUtils.safeGetBooleanExtra( | 1175 && IntentUtils.safeGetBooleanExtra( |
| 1211 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG
E, false)) { | 1176 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG
E, false)) { |
| 1212 return false; | 1177 return false; |
| 1213 } | 1178 } |
| 1214 | 1179 |
| 1215 return super.requiresFirstRunToBeCompleted(intent); | 1180 return super.requiresFirstRunToBeCompleted(intent); |
| 1216 } | 1181 } |
| 1217 } | 1182 } |
| OLD | NEW |