Commit 66f6e18b authored by gogerald's avatar gogerald Committed by Commit Bot

[Payments] Enable openning custom tab in incognito mode

Use case of this change is for payment request + payment handler (service worker):
Users could enter into incognito mode and install a payment handler (service worker) there.
Then go to a merchant website to buy with that payment handler, which will open a web page
in custom tab to ask inputs.
After that the opened web page should be able to find out the service worker to send back
the result.
So the registered payment handler (service worker) and opened web page must in the same
browser context.

Below is the test video record,
https://drive.google.com/file/d/1CTFw9_-jCOvmV1fEMg8TZHd0inNKdPS2/view?usp=sharing

Bug: 848245
Change-Id: Ice00df0b53c40a34108d84c8fa55d8160a03d6e2
Reviewed-on: https://chromium-review.googlesource.com/1080688
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565700}
parent e6b0ebd3
......@@ -409,7 +409,9 @@ public class CustomTabActivity extends ChromeActivity {
mConnection.cancelSpeculation(mSession);
}
getTabModelSelector().getModel(false).addObserver(mTabModelObserver);
getTabModelSelector()
.getModel(mIntentDataProvider.isIncognito())
.addObserver(mTabModelObserver);
boolean successfulStateRestore = false;
// Attempt to restore the previous tab state if applicable.
......@@ -431,7 +433,9 @@ public class CustomTabActivity extends ChromeActivity {
} else {
mMainTab = createMainTab();
}
getTabModelSelector().getModel(false).addTab(mMainTab, 0, mMainTab.getLaunchType());
getTabModelSelector()
.getModel(mIntentDataProvider.isIncognito())
.addTab(mMainTab, 0, mMainTab.getLaunchType());
}
// This cannot be done before because we want to do the reparenting only
......@@ -587,8 +591,8 @@ public class CustomTabActivity extends ChromeActivity {
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, getWindowAndroid(),
TabLaunchType.FROM_EXTERNAL_APP, null, null);
Tab tab = new Tab(assignedTabId, parentTabId, mIntentDataProvider.isIncognito(),
getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null);
if (getIntent().getIntExtra(
CustomTabIntentDataProvider.EXTRA_BROWSER_LAUNCH_SOURCE, ACTIVITY_TYPE_OTHER)
== ACTIVITY_TYPE_WEBAPK) {
......@@ -621,11 +625,13 @@ public class CustomTabActivity extends ChromeActivity {
webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS;
webContents.resumeLoadingCreatedWebContents();
} else {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
webContents = WarmupManager.getInstance().takeSpareWebContents(
mIntentDataProvider.isIncognito(), false);
if (webContents != null) {
webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
} else {
webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
webContents = WebContentsFactory.createWebContentsWithWarmRenderer(
mIntentDataProvider.isIncognito(), false);
webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
}
}
......
......@@ -139,6 +139,9 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
/** Whether this CustomTabActivity was explicitly started by another Chrome Activity. */
private boolean mIsOpenedByChrome;
private boolean mIsIncognito;
/**
* Add extras to customize menu items for opening payment request UI custom tab from Chrome.
*/
......@@ -202,6 +205,8 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
mIsOpenedByChrome =
IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OPENED_BY_CHROME, false);
mIsIncognito = IntentUtils.safeGetBooleanExtra(
intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false);
final int requestedUiType =
IntentUtils.safeGetIntExtra(intent, EXTRA_UI_TYPE, CUSTOM_TABS_UI_TYPE_DEFAULT);
......@@ -580,4 +585,12 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
boolean isForPaymentRequest() {
return mUiType == CUSTOM_TABS_UI_TYPE_PAYMENT_REQUEST;
}
/**
* @return Whether the custom Tab should be opened in incognito mode.
*/
boolean isIncognito() {
// Only open custom tab in incognito mode for payment request.
return isTrustedIntent() && mIsOpenedByChrome && isForPaymentRequest() && mIsIncognito;
}
}
......@@ -2327,6 +2327,17 @@ public class CustomTabActivityTest {
ApplicationStatus.unregisterActivityStateListener(listener);
}
@Test
@MediumTest
public void testLaunchIncognitoCustomTabForPaymentRequest() throws Exception {
Intent intent = createMinimalCustomTabIntent();
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
CustomTabIntentDataProvider.addPaymentRequestUIExtras(intent);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
Assert.assertTrue(mCustomTabActivityTestRule.getActivity().getActivityTab().isIncognito());
}
/**
* Tests that a Weblite URL from an external app uses the lite_url param when Data Reduction
* Proxy previews are being used.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment