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; | |
68 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; | 69 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; |
69 import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; | 70 import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; |
70 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 71 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
71 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 72 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
72 import org.chromium.chrome.browser.tabmodel.TabModelObserver; | 73 import org.chromium.chrome.browser.tabmodel.TabModelObserver; |
73 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 74 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
74 import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl; | 75 import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl; |
75 import org.chromium.chrome.browser.tabmodel.TabReparentingParams; | 76 import org.chromium.chrome.browser.tabmodel.TabReparentingParams; |
76 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; | 77 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; |
77 import org.chromium.chrome.browser.util.ColorUtils; | 78 import org.chromium.chrome.browser.util.ColorUtils; |
(...skipping 13 matching lines...) Expand all Loading... | |
91 */ | 92 */ |
92 public class CustomTabActivity extends ChromeActivity { | 93 public class CustomTabActivity extends ChromeActivity { |
93 | 94 |
94 private static final String TAG = "CustomTabActivity"; | 95 private static final String TAG = "CustomTabActivity"; |
95 private static final String LAST_URL_PREF = "pref_last_custom_tab_url"; | 96 private static final String LAST_URL_PREF = "pref_last_custom_tab_url"; |
96 | 97 |
97 // For CustomTabs.WebContentsStateOnLaunch, see histograms.xml. Append only. | 98 // For CustomTabs.WebContentsStateOnLaunch, see histograms.xml. Append only. |
98 private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0; | 99 private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0; |
99 private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1; | 100 private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1; |
100 private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2; | 101 private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2; |
101 private static final int WEBCONTENTS_STATE_MAX = 3; | 102 private static final int WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS = 3; |
103 private static final int WEBCONTENTS_STATE_MAX = 4; | |
102 | 104 |
103 private static CustomTabContentHandler sActiveContentHandler; | 105 private static CustomTabContentHandler sActiveContentHandler; |
104 | 106 |
105 private FindToolbarManager mFindToolbarManager; | 107 private FindToolbarManager mFindToolbarManager; |
106 private CustomTabIntentDataProvider mIntentDataProvider; | 108 private CustomTabIntentDataProvider mIntentDataProvider; |
107 private CustomTabsSessionToken mSession; | 109 private CustomTabsSessionToken mSession; |
108 private CustomTabContentHandler mCustomTabContentHandler; | 110 private CustomTabContentHandler mCustomTabContentHandler; |
109 private Tab mMainTab; | 111 private Tab mMainTab; |
110 private CustomTabBottomBarDelegate mBottomBarDelegate; | 112 private CustomTabBottomBarDelegate mBottomBarDelegate; |
111 private CustomTabTabPersistencePolicy mTabPersistencePolicy; | 113 private CustomTabTabPersistencePolicy mTabPersistencePolicy; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess ion)); | 569 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess ion)); |
568 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { | 570 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { |
569 tab.enableEmbeddedMediaExperience(true); | 571 tab.enableEmbeddedMediaExperience(true); |
570 } | 572 } |
571 initializeMainTab(tab); | 573 initializeMainTab(tab); |
572 return tab; | 574 return tab; |
573 } | 575 } |
574 | 576 |
575 private Tab createMainTab() { | 577 private Tab createMainTab() { |
576 CustomTabsConnection connection = CustomTabsConnection.getInstance(getAp plication()); | 578 CustomTabsConnection connection = CustomTabsConnection.getInstance(getAp plication()); |
577 String url = getUrlToLoad(); | 579 WebContents webContents = takeWebContents(connection); |
578 String referrerUrl = connection.getReferrer(mSession, getIntent()); | 580 |
579 Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g etWindowAndroid(), | 581 int assignedTabId = IntentUtils.safeGetIntExtra( |
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(), | |
580 TabLaunchType.FROM_EXTERNAL_APP, null, null); | 586 TabLaunchType.FROM_EXTERNAL_APP, null, null); |
581 tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSess ion)); | 587 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 } | |
599 tab.initialize( | 588 tab.initialize( |
600 webContents, getTabContentManager(), | 589 webContents, getTabContentManager(), |
601 new CustomTabDelegateFactory( | 590 new CustomTabDelegateFactory( |
602 mIntentDataProvider.shouldEnableUrlBarHiding(), | 591 mIntentDataProvider.shouldEnableUrlBarHiding(), |
603 mIntentDataProvider.isOpenedByChrome(), | 592 mIntentDataProvider.isOpenedByChrome(), |
604 getFullscreenManager().getBrowserVisibilityDelegate()), | 593 getFullscreenManager().getBrowserVisibilityDelegate()), |
605 false, false); | 594 false, false); |
606 | 595 |
607 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { | 596 if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) { |
608 tab.enableEmbeddedMediaExperience(true); | 597 tab.enableEmbeddedMediaExperience(true); |
609 } | 598 } |
610 | 599 |
611 initializeMainTab(tab); | 600 initializeMainTab(tab); |
612 return tab; | 601 return tab; |
613 } | 602 } |
614 | 603 |
604 private WebContents takeWebContents(CustomTabsConnection connection) { | |
605 WebContents webContents; | |
606 int webContentsStateOnLaunch; | |
607 mUsingPrerender = false; | |
608 | |
609 if ((webContents = takePrerenderedWebContents(connection)) != null) { | |
610 webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS ; | |
611 mUsingPrerender = true; | |
612 } else if ((webContents = takeAsyncWebContents()) != null) { | |
Yusuf
2017/06/15 16:15:56
I know it will make you have a slightly worse nest
piotrs
2017/06/15 23:28:21
Done.
| |
613 webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS ; | |
614 } else if ((webContents = WarmupManager.getInstance().takeSpareWebConten ts(false, false)) | |
615 != null) { | |
616 webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS; | |
617 } else { | |
618 webContents = WebContentsFactory.createWebContentsWithWarmRenderer(f alse, false); | |
619 webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; | |
620 } | |
621 RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOn Launch", | |
622 webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); | |
623 | |
624 if (!mUsingPrerender) { | |
625 connection.resetPostMessageHandlerForSession(mSession, webContents); | |
626 } | |
627 | |
628 return webContents; | |
629 } | |
630 | |
631 private WebContents takePrerenderedWebContents(CustomTabsConnection connecti on) { | |
632 String url = getUrlToLoad(); | |
633 String referrerUrl = connection.getReferrer(mSession, getIntent()); | |
634 return connection.takePrerenderedUrl(mSession, url, referrerUrl); | |
635 } | |
636 | |
637 private WebContents takeAsyncWebContents() { | |
638 int assignedTabId = IntentUtils.safeGetIntExtra( | |
639 getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); | |
640 AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId) ; | |
641 if (asyncParams == null) { | |
Yusuf
2017/06/15 16:15:56
one line
piotrs
2017/06/15 23:28:21
Done.
| |
642 return null; | |
643 } | |
644 return asyncParams.getWebContents(); | |
645 } | |
646 | |
615 private void initializeMainTab(Tab tab) { | 647 private void initializeMainTab(Tab tab) { |
616 tab.getTabRedirectHandler().updateIntent(getIntent()); | 648 tab.getTabRedirectHandler().updateIntent(getIntent()); |
617 tab.getView().requestFocus(); | 649 tab.getView().requestFocus(); |
618 mTabObserver = new CustomTabObserver( | 650 mTabObserver = new CustomTabObserver( |
619 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome ()); | 651 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome ()); |
620 | 652 |
621 mMetricsObserver = new PageLoadMetricsObserver( | 653 mMetricsObserver = new PageLoadMetricsObserver( |
622 CustomTabsConnection.getInstance(getApplication()), mSession, ta b); | 654 CustomTabsConnection.getInstance(getApplication()), mSession, ta b); |
623 tab.addObserver(mTabObserver); | 655 tab.addObserver(mTabObserver); |
624 | 656 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 // Custom Tabs can be used to open Chrome help pages before the ToS has been accepted. | 1205 // Custom Tabs can be used to open Chrome help pages before the ToS has been accepted. |
1174 if (IntentHandler.isIntentChromeOrFirstParty(intent) | 1206 if (IntentHandler.isIntentChromeOrFirstParty(intent) |
1175 && IntentUtils.safeGetBooleanExtra( | 1207 && IntentUtils.safeGetBooleanExtra( |
1176 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG E, false)) { | 1208 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG E, false)) { |
1177 return false; | 1209 return false; |
1178 } | 1210 } |
1179 | 1211 |
1180 return super.requiresFirstRunToBeCompleted(intent); | 1212 return super.requiresFirstRunToBeCompleted(intent); |
1181 } | 1213 } |
1182 } | 1214 } |
OLD | NEW |