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

🤝 Trigger Origin Verification on Trusted Web Activity start.

This will display Trusted Web Activities correctly when they are
launched when verification hasn't been completed.

It also ensures that Trusted Web Activities show the top bar when they
are launched to a non-verified origin.

Bug: 871266
Change-Id: Ibd245812647a2f1d6b6a9405f14d12f46f6ae6f9
Reviewed-on: https://chromium-review.googlesource.com/1177611Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583674}
parent 0cdc1458
...@@ -22,6 +22,9 @@ import org.chromium.chrome.browser.tab.TabObserver; ...@@ -22,6 +22,9 @@ import org.chromium.chrome.browser.tab.TabObserver;
* Thread safety: All methods on this class should be called on the UI thread. * Thread safety: All methods on this class should be called on the UI thread.
*/ */
public class TrustedWebActivityUi { public class TrustedWebActivityUi {
/** The Digital Asset Link relationship used for Trusted Web Activities. */
private final static int RELATIONSHIP = CustomTabsService.RELATION_HANDLE_ALL_URLS;
private final TrustedWebActivityUiDelegate mDelegate; private final TrustedWebActivityUiDelegate mDelegate;
private final TrustedWebActivityDisclosure mDisclosure; private final TrustedWebActivityDisclosure mDisclosure;
...@@ -82,8 +85,8 @@ public class TrustedWebActivityUi { ...@@ -82,8 +85,8 @@ public class TrustedWebActivityUi {
// This doesn't perform a network request or attempt new verification - it checks to // This doesn't perform a network request or attempt new verification - it checks to
// see if a verification already exists for the given inputs. // see if a verification already exists for the given inputs.
setTrustedWebActivityMode(OriginVerifier.isValidOrigin(packageName, new Origin(url), setTrustedWebActivityMode(
CustomTabsService.RELATION_HANDLE_ALL_URLS), tab); OriginVerifier.isValidOrigin(packageName, new Origin(url), RELATIONSHIP), tab);
} }
}; };
...@@ -122,6 +125,22 @@ public class TrustedWebActivityUi { ...@@ -122,6 +125,22 @@ public class TrustedWebActivityUi {
mDelegate.getClientPackageName()); mDelegate.getClientPackageName());
} }
/**
* Perform verification for the URL that the CustomTabActivity starts on.
*/
public void attemptVerificationForInitialUrl(String url, Tab tab) {
assert mDelegate.getClientPackageName() != null;
String packageName = mDelegate.getClientPackageName();
Origin origin = new Origin(url);
new OriginVerifier((packageName2, origin2, verified, online) -> {
if (!origin.equals(new Origin(tab.getUrl()))) return;
setTrustedWebActivityMode(verified, tab);
}, packageName, RELATIONSHIP).start(origin);
}
/** /**
* Updates the UI appropriately for whether or not Trusted Web Activity mode is enabled. * Updates the UI appropriately for whether or not Trusted Web Activity mode is enabled.
*/ */
......
...@@ -660,6 +660,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -660,6 +660,7 @@ public class CustomTabActivity extends ChromeActivity {
} }
if (mTrustedWebActivityUi != null) { if (mTrustedWebActivityUi != null) {
mTrustedWebActivityUi.attemptVerificationForInitialUrl(url, getActivityTab());
mTrustedWebActivityUi.initialShowSnackbarIfNeeded(); mTrustedWebActivityUi.initialShowSnackbarIfNeeded();
} }
......
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