Commit bbe98cb0 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Reland "Move custom tabs off notSecureIsIntentChromeOrFirstParty()"

This is a reland of 0bd64fcf

Original change's description:
> Move custom tabs off notSecureIsIntentChromeOrFirstParty()
>
> Instead, use the CCT session token to determine the connected client
> package and verify using that instead.
>
> Bug: 832124
> Change-Id: I96f9c6831f7dcbf801e3ee48d59904a4788d97b2
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1324910
> Reviewed-by: Peter Conn <peconn@chromium.org>
> Commit-Queue: Robert Sesek <rsesek@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#754033}

Tbr: peconn@chromium.org
Bug: 832124
Change-Id: I6c9c765e9b055dc660fe2ac653e0e86530359e29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127246
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754461}
parent 2b3d3ab3
...@@ -331,7 +331,7 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo ...@@ -331,7 +331,7 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo
@Override @Override
protected boolean requiresFirstRunToBeCompleted(Intent intent) { protected boolean requiresFirstRunToBeCompleted(Intent intent) {
// Custom Tabs can be used to open Chrome help pages before the ToS has been accepted. // Custom Tabs can be used to open Chrome help pages before the ToS has been accepted.
if (IntentHandler.notSecureIsIntentChromeOrFirstParty(intent) if (CustomTabIntentDataProvider.isTrustedCustomTab(intent, mSession)
&& IntentUtils.safeGetIntExtra(intent, CustomTabIntentDataProvider.EXTRA_UI_TYPE, && IntentUtils.safeGetIntExtra(intent, CustomTabIntentDataProvider.EXTRA_UI_TYPE,
CustomTabIntentDataProvider.CustomTabsUiType.DEFAULT) CustomTabIntentDataProvider.CustomTabsUiType.DEFAULT)
== CustomTabIntentDataProvider.CustomTabsUiType.INFO_PAGE) { == CustomTabIntentDataProvider.CustomTabsUiType.INFO_PAGE) {
......
...@@ -218,6 +218,20 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -218,6 +218,20 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
IntentHandler.addTrustedIntentExtras(intent); IntentHandler.addTrustedIntentExtras(intent);
} }
/**
* Evaluates whether the passed Intent and/or CustomTabsSessionToken are
* from a trusted source. Trusted in this case means from the app itself or
* via a first-party application.
*
* @param intent The Intent used to start the custom tabs activity, or null.
* @param session The connected session for the custom tabs activity, or null.
* @return True if the intent or session are trusted.
*/
public static boolean isTrustedCustomTab(Intent intent, CustomTabsSessionToken session) {
return IntentHandler.wasIntentSenderChrome(intent)
|| CustomTabsConnection.getInstance().isSessionFirstParty(session);
}
/** /**
* Constructs a {@link CustomTabIntentDataProvider}. * Constructs a {@link CustomTabIntentDataProvider}.
* *
...@@ -233,7 +247,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -233,7 +247,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
mIntent = intent; mIntent = intent;
mSession = CustomTabsSessionToken.getSessionTokenFromIntent(intent); mSession = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
mIsTrustedIntent = IntentHandler.notSecureIsIntentChromeOrFirstParty(intent); mIsTrustedIntent = isTrustedCustomTab(intent, mSession);
mAnimationBundle = IntentUtils.safeGetBundleExtra( mAnimationBundle = IntentUtils.safeGetBundleExtra(
intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE); intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE);
......
...@@ -57,6 +57,7 @@ import org.chromium.chrome.browser.browserservices.PostMessageHandler; ...@@ -57,6 +57,7 @@ import org.chromium.chrome.browser.browserservices.PostMessageHandler;
import org.chromium.chrome.browser.browserservices.SessionDataHolder; import org.chromium.chrome.browser.browserservices.SessionDataHolder;
import org.chromium.chrome.browser.browserservices.SessionHandler; import org.chromium.chrome.browser.browserservices.SessionHandler;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.init.ChainedTasks; import org.chromium.chrome.browser.init.ChainedTasks;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
...@@ -1065,6 +1066,13 @@ public class CustomTabsConnection { ...@@ -1065,6 +1066,13 @@ public class CustomTabsConnection {
return mClientManager.getClientPackageNameForSession(session); return mClientManager.getClientPackageNameForSession(session);
} }
/** @return Whether the client of the {@code session} is a first-party application. */
public boolean isSessionFirstParty(CustomTabsSessionToken session) {
String packageName = getClientPackageNameForSession(session);
if (packageName == null) return false;
return ExternalAuthUtils.getInstance().isGoogleSigned(packageName);
}
@VisibleForTesting @VisibleForTesting
void setIgnoreUrlFragmentsForSession(CustomTabsSessionToken session, boolean value) { void setIgnoreUrlFragmentsForSession(CustomTabsSessionToken session, boolean value) {
mClientManager.setIgnoreFragmentsForSession(session, value); mClientManager.setIgnoreFragmentsForSession(session, value);
...@@ -1092,15 +1100,6 @@ public class CustomTabsConnection { ...@@ -1092,15 +1100,6 @@ public class CustomTabsConnection {
mClientManager.setSendNavigationInfoForSession(session, send); mClientManager.setSendNavigationInfoForSession(session, send);
} }
/**
* Extracts the creator package name from the intent.
* @param intent The intent to get the package name from.
* @return the package name which can be null.
*/
String extractCreatorPackage(Intent intent) {
return null;
}
/** /**
* Shows a toast about any possible sign in issues encountered during custom tab startup. * Shows a toast about any possible sign in issues encountered during custom tab startup.
* @param session The session that corresponding custom tab is assigned. * @param session The session that corresponding custom tab is assigned.
......
...@@ -28,6 +28,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesActivityTabCon ...@@ -28,6 +28,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesActivityTabCon
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.compositor.CompositorViewHolder; import org.chromium.chrome.browser.compositor.CompositorViewHolder;
import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory; import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory;
import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
import org.chromium.chrome.browser.customtabs.CustomTabNavigationEventObserver; import org.chromium.chrome.browser.customtabs.CustomTabNavigationEventObserver;
import org.chromium.chrome.browser.customtabs.CustomTabObserver; import org.chromium.chrome.browser.customtabs.CustomTabObserver;
import org.chromium.chrome.browser.customtabs.CustomTabTabPersistencePolicy; import org.chromium.chrome.browser.customtabs.CustomTabTabPersistencePolicy;
...@@ -440,7 +441,7 @@ public class CustomTabActivityTabController ...@@ -440,7 +441,7 @@ public class CustomTabActivityTabController
/** Sets the initial background color for the Tab, shown before the page content is ready. */ /** Sets the initial background color for the Tab, shown before the page content is ready. */
private void prepareTabBackground(final Tab tab) { private void prepareTabBackground(final Tab tab) {
if (!IntentHandler.notSecureIsIntentChromeOrFirstParty(mIntent)) return; if (!CustomTabIntentDataProvider.isTrustedCustomTab(mIntent, mSession)) return;
int backgroundColor = mIntentDataProvider.getInitialBackgroundColor(); int backgroundColor = mIntentDataProvider.getInitialBackgroundColor();
if (backgroundColor == Color.TRANSPARENT) return; if (backgroundColor == Color.TRANSPARENT) return;
......
...@@ -958,7 +958,7 @@ public class CustomTabActivityTest { ...@@ -958,7 +958,7 @@ public class CustomTabActivityTest {
// Mark the intent as trusted so it can show more than one action button. // Mark the intent as trusted so it can show more than one action button.
IntentHandler.addTrustedIntentExtras(intent); IntentHandler.addTrustedIntentExtras(intent);
Assert.assertTrue(IntentHandler.notSecureIsIntentChromeOrFirstParty(intent)); Assert.assertTrue(IntentHandler.wasIntentSenderChrome(intent));
ArrayList<Bundle> toolbarItems = new ArrayList<>(2); ArrayList<Bundle> toolbarItems = new ArrayList<>(2);
final PendingIntent pi1 = PendingIntent.getBroadcast( final PendingIntent pi1 = PendingIntent.getBroadcast(
...@@ -1033,7 +1033,7 @@ public class CustomTabActivityTest { ...@@ -1033,7 +1033,7 @@ public class CustomTabActivityTest {
Intent intent = createMinimalCustomTabIntent(); Intent intent = createMinimalCustomTabIntent();
// By default, the intent should not be trusted. // By default, the intent should not be trusted.
Assert.assertFalse(IntentHandler.notSecureIsIntentChromeOrFirstParty(intent)); Assert.assertFalse(IntentHandler.wasIntentSenderChrome(intent));
ArrayList<Bundle> toolbarItems = new ArrayList<>(2); ArrayList<Bundle> toolbarItems = new ArrayList<>(2);
final PendingIntent pi = PendingIntent.getBroadcast( final PendingIntent pi = PendingIntent.getBroadcast(
......
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