Commit ff9183ee authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

cct: adds extra that controls whether client data header is added

Prior to this the header was always added. After this, the header
is only added if an extra is supplied. This only changes whether
setClientDataHeaderForNewTab() is called and does not alter
the implementation of that function.

BUG=1163158
TEST=covered by tests

Change-Id: Ic5d222d719a81c6da3d4e0c7866e18cbcee6e817
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611340
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840370}
parent 6e1ad802
...@@ -539,4 +539,13 @@ public abstract class BrowserServicesIntentDataProvider { ...@@ -539,4 +539,13 @@ public abstract class BrowserServicesIntentDataProvider {
public boolean shouldHideIncognitoIconOnToolbarInCct() { public boolean shouldHideIncognitoIconOnToolbarInCct() {
return false; return false;
} }
/**
* @return Whether the cct-client-data header should be added. Note that a return value of true
* does not necessarily mean the header will be added. There are aditional checks in
* {@link setClientDataHeaderForNewTab()}. This is applicable only to cct.
*/
public boolean shouldAddCctClientDataHeader() {
return false;
}
} }
...@@ -99,6 +99,13 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -99,6 +99,13 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
public static final String BUNDLE_EXIT_ANIMATION_RESOURCE = public static final String BUNDLE_EXIT_ANIMATION_RESOURCE =
ANIMATION_BUNDLE_PREFIX + "animExitRes"; ANIMATION_BUNDLE_PREFIX + "animExitRes";
/**
* See {@link BrowserServicesIntentDataProvider#shouldAddCctClientDataHeader} for details on
* this.
*/
public static final String EXTRA_ADD_CCT_CLIENT_DATA_HEADER =
"org.chromium.chrome.browser.customtabs.ADD_CCT_CLIENT_DATA_HEADER";
/** /**
* Extra that indicates whether or not the Custom Tab is being launched by an Intent fired by * Extra that indicates whether or not the Custom Tab is being launched by an Intent fired by
* Chrome itself. * Chrome itself.
...@@ -908,4 +915,9 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -908,4 +915,9 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return !IntentUtils.safeGetBooleanExtra( return !IntentUtils.safeGetBooleanExtra(
mIntent, EXTRA_HIDE_OPEN_IN_CHROME_MENU_ITEM, false); mIntent, EXTRA_HIDE_OPEN_IN_CHROME_MENU_ITEM, false);
} }
@Override
public boolean shouldAddCctClientDataHeader() {
return IntentUtils.safeGetBooleanExtra(mIntent, EXTRA_ADD_CCT_CLIENT_DATA_HEADER, false);
}
} }
...@@ -405,7 +405,7 @@ public class CustomTabActivityTabController implements InflationObserver { ...@@ -405,7 +405,7 @@ public class CustomTabActivityTabController implements InflationObserver {
mConnection.getClientPackageNameForSession(mSession))); mConnection.getClientPackageNameForSession(mSession)));
// clang-format on // clang-format on
if (!tab.isIncognito()) { if (!tab.isIncognito() && mIntentDataProvider.shouldAddCctClientDataHeader()) {
mConnection.setClientDataHeaderForNewTab(mSession, webContents); mConnection.setClientDataHeaderForNewTab(mSession, webContents);
} }
......
...@@ -187,9 +187,8 @@ public class CustomTabActivityTabControllerUnitTest { ...@@ -187,9 +187,8 @@ public class CustomTabActivityTabControllerUnitTest {
assertNull(env.tabProvider.getTab()); assertNull(env.tabProvider.getTab());
} }
// Some websites replace the tab with a new one.
@Test @Test
public void doesNotSetHeaderWhenIncognito() { public void doesNotSetCctClientDataHeaderWhenIncognito() {
doAnswer((mock) -> { doAnswer((mock) -> {
fail("setClientDataHeaderForNewTab() should not be called for incognito tabs"); fail("setClientDataHeaderForNewTab() should not be called for incognito tabs");
return null; return null;
...@@ -197,9 +196,38 @@ public class CustomTabActivityTabControllerUnitTest { ...@@ -197,9 +196,38 @@ public class CustomTabActivityTabControllerUnitTest {
.when(env.connection) .when(env.connection)
.setClientDataHeaderForNewTab(any(), any()); .setClientDataHeaderForNewTab(any(), any());
env.isIncognito = true; env.isIncognito = true;
when(env.intentDataProvider.shouldAddCctClientDataHeader()).thenReturn(true);
mTabController.onPreInflationStartup(); mTabController.onPreInflationStartup();
mTabController.finishNativeInitialization(); mTabController.finishNativeInitialization();
Tab tab = env.prepareTab(); Tab tab = env.prepareTab();
assertTrue(tab.isIncognito()); assertTrue(tab.isIncognito());
} }
@Test
public void doesNotSetCctClientDataHeaderWithoutExtra() {
doAnswer((mock) -> {
fail("setClientDataHeaderForNewTab() should not be called without extra");
return null;
})
.when(env.connection)
.setClientDataHeaderForNewTab(any(), any());
mTabController.onPreInflationStartup();
mTabController.finishNativeInitialization();
}
@Test
public void setsCctClientDataHeaderWithExtra() {
final boolean[] wasSetClientDataHeaderForNewTabCalled = new boolean[1];
doAnswer((mock) -> {
wasSetClientDataHeaderForNewTabCalled[0] = true;
return null;
})
.when(env.connection)
.setClientDataHeaderForNewTab(any(), any());
when(env.intentDataProvider.shouldAddCctClientDataHeader()).thenReturn(true);
mTabController.onPreInflationStartup();
mTabController.finishNativeInitialization();
Tab tab = env.prepareTab();
assertTrue(wasSetClientDataHeaderForNewTabCalled[0]);
}
} }
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