Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java

Issue 2898373002: Redirects _blank and window.open() off-origin navigation from PWA to CCT. (Closed)
Patch Set: Merge Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
index 17b34f1bcf96183eda47b6eeaf8e765bea289883..709dcc617c668c231b1c3988d9f28a5fe4eea249 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java
@@ -65,6 +65,7 @@ import org.chromium.chrome.browser.rappor.RapporServiceBridge;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabDelegateFactory;
+import org.chromium.chrome.browser.tabmodel.AsyncTabParams;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
import org.chromium.chrome.browser.tabmodel.ChromeTabCreator;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
@@ -98,7 +99,8 @@ public class CustomTabActivity extends ChromeActivity {
private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0;
private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1;
private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2;
- private static final int WEBCONTENTS_STATE_MAX = 3;
+ private static final int WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS = 3;
+ private static final int WEBCONTENTS_STATE_MAX = 4;
private static CustomTabContentHandler sActiveContentHandler;
@@ -574,28 +576,15 @@ public class CustomTabActivity extends ChromeActivity {
private Tab createMainTab() {
CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication());
- String url = getUrlToLoad();
- String referrerUrl = connection.getReferrer(mSession, getIntent());
- Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
+ WebContents webContents = takeWebContents(connection);
+
+ int assignedTabId = IntentUtils.safeGetIntExtra(
+ getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
+ int parentTabId = IntentUtils.safeGetIntExtra(
+ getIntent(), IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_ID);
+ Tab tab = new Tab(assignedTabId, parentTabId, false, this, getWindowAndroid(),
TabLaunchType.FROM_EXTERNAL_APP, null, null);
tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSession));
-
- int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
- WebContents webContents = connection.takePrerenderedUrl(mSession, url, referrerUrl);
- mUsingPrerender = webContents != null;
- if (mUsingPrerender) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
- if (!mUsingPrerender) {
- webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
- if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
- }
- RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch",
- webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
- if (webContents == null) {
- webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
- }
- if (!mUsingPrerender) {
- connection.resetPostMessageHandlerForSession(mSession, webContents);
- }
tab.initialize(
webContents, getTabContentManager(),
new CustomTabDelegateFactory(
@@ -612,6 +601,52 @@ public class CustomTabActivity extends ChromeActivity {
return tab;
}
+ private WebContents takeWebContents(CustomTabsConnection connection) {
+ mUsingPrerender = true;
+ int webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
+ WebContents webContents = takePrerenderedWebContents(connection);
+
+ if (webContents == null) {
+ mUsingPrerender = false;
+ webContents = takeAsyncWebContents();
+ if (webContents != null) {
+ webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS;
+ } else {
+ webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
+ if (webContents != null) {
+ webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
+ } else {
+ webContents =
+ WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
+ webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
+ }
+ }
+ }
+
+ RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch",
+ webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
+
+ if (!mUsingPrerender) {
+ connection.resetPostMessageHandlerForSession(mSession, webContents);
+ }
+
+ return webContents;
+ }
+
+ private WebContents takePrerenderedWebContents(CustomTabsConnection connection) {
+ String url = getUrlToLoad();
+ String referrerUrl = connection.getReferrer(mSession, getIntent());
+ return connection.takePrerenderedUrl(mSession, url, referrerUrl);
+ }
+
+ private WebContents takeAsyncWebContents() {
+ int assignedTabId = IntentUtils.safeGetIntExtra(
+ getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
+ AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId);
+ if (asyncParams == null) return null;
+ return asyncParams.getWebContents();
+ }
+
private void initializeMainTab(Tab tab) {
tab.getTabRedirectHandler().updateIntent(getIntent());
tab.getView().requestFocus();
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698