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 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 |
615 private void initializeMainTab(Tab tab) { | 650 private void initializeMainTab(Tab tab) { |
616 tab.getTabRedirectHandler().updateIntent(getIntent()); | 651 tab.getTabRedirectHandler().updateIntent(getIntent()); |
617 tab.getView().requestFocus(); | 652 tab.getView().requestFocus(); |
618 mTabObserver = new CustomTabObserver( | 653 mTabObserver = new CustomTabObserver( |
619 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome
()); | 654 getApplication(), mSession, mIntentDataProvider.isOpenedByChrome
()); |
620 | 655 |
621 mMetricsObserver = new PageLoadMetricsObserver( | 656 mMetricsObserver = new PageLoadMetricsObserver( |
622 CustomTabsConnection.getInstance(getApplication()), mSession, ta
b); | 657 CustomTabsConnection.getInstance(getApplication()), mSession, ta
b); |
623 tab.addObserver(mTabObserver); | 658 tab.addObserver(mTabObserver); |
624 | 659 |
(...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. | 1208 // Custom Tabs can be used to open Chrome help pages before the ToS has
been accepted. |
1174 if (IntentHandler.isIntentChromeOrFirstParty(intent) | 1209 if (IntentHandler.isIntentChromeOrFirstParty(intent) |
1175 && IntentUtils.safeGetBooleanExtra( | 1210 && IntentUtils.safeGetBooleanExtra( |
1176 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG
E, false)) { | 1211 intent, CustomTabIntentDataProvider.EXTRA_IS_INFO_PAG
E, false)) { |
1177 return false; | 1212 return false; |
1178 } | 1213 } |
1179 | 1214 |
1180 return super.requiresFirstRunToBeCompleted(intent); | 1215 return super.requiresFirstRunToBeCompleted(intent); |
1181 } | 1216 } |
1182 } | 1217 } |
OLD | NEW |