Commit c33a2044 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🛃 Store ClientDataHeader in the ClientManager.

Bug: 1040143
Change-Id: If698ecc2b828895ab7308e805ed7a1f81857c439
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020706
Commit-Queue: Peter Conn <peconn@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735818}
parent 1be4630f
...@@ -188,6 +188,7 @@ class ClientManager { ...@@ -188,6 +188,7 @@ class ClientManager {
private boolean mAllowResourcePrefetch; private boolean mAllowResourcePrefetch;
private boolean mShouldGetPageLoadMetrics; private boolean mShouldGetPageLoadMetrics;
private boolean mShouldHideTopBar; private boolean mShouldHideTopBar;
private String mCustomTabsClientDataHeaderValue;
public SessionParams(Context context, int uid, CustomTabsCallback customTabsCallback, public SessionParams(Context context, int uid, CustomTabsCallback customTabsCallback,
DisconnectCallback callback, PostMessageHandler postMessageHandler, DisconnectCallback callback, PostMessageHandler postMessageHandler,
...@@ -582,6 +583,25 @@ class ClientManager { ...@@ -582,6 +583,25 @@ class ClientManager {
if (params != null) params.mShouldSendBottomBarScrollState = send; if (params != null) params.mShouldSendBottomBarScrollState = send;
} }
/**
* Sets the value of the X-CCT-Client-Data header that will be sent on some Custom Tabs
* requests.
*/
public synchronized void setClientDataHeaderValue(
CustomTabsSessionToken session, String headerValue) {
SessionParams params = mSessionParams.get(session);
if (params != null) params.mCustomTabsClientDataHeaderValue = headerValue;
}
/**
* Gets the value previously set by {@link #setClientDataHeaderValue}.
*/
public synchronized String getClientDataHeaderValue(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
if (params == null) return null;
return params.mCustomTabsClientDataHeaderValue;
}
/** /**
* @return Whether navigation info should be recorded and shared for the session. * @return Whether navigation info should be recorded and shared for the session.
*/ */
......
...@@ -1034,6 +1034,13 @@ public class CustomTabsConnection { ...@@ -1034,6 +1034,13 @@ public class CustomTabsConnection {
mClientManager.setSendNavigationInfoForSession(session, send); mClientManager.setSendNavigationInfoForSession(session, send);
} }
/**
* See {@link ClientManager#setClientDataHeaderValue}.
*/
String getClientDataHeaderValueForSession(CustomTabsSessionToken session) {
return mClientManager.getClientDataHeaderValue(session);
}
/** /**
* Extracts the creator package name from the intent. * Extracts the creator package name from the intent.
* @param intent The intent to get the package name from. * @param intent The intent to get the package name from.
......
...@@ -170,6 +170,20 @@ public class ClientManagerTest { ...@@ -170,6 +170,20 @@ public class ClientManagerTest {
mClientManager.getPredictionOutcome(mSession, URL + "#fragment")); mClientManager.getPredictionOutcome(mSession, URL + "#fragment"));
} }
@Test
@SmallTest
public void testClientDataHeader() {
Assert.assertTrue(mClientManager.newSession(mSession, mUid, null, null, null));
String headerValue = "header value";
mClientManager.setClientDataHeaderValue(mSession, headerValue);
Assert.assertEquals(headerValue, mClientManager.getClientDataHeaderValue(mSession));
mClientManager.setClientDataHeaderValue(mSession, null);
Assert.assertNull(mClientManager.getClientDataHeaderValue(mSession));
}
@Test @Test
@SmallTest @SmallTest
public void testPostMessageOriginVerification() { public void testPostMessageOriginVerification() {
......
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