Commit 41be1078 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🤝 Disable app banners on Trusted Web Activities.

Chances are the user of a TWA already has an app installed for the site
they are viewing. In this case we should not show the app install
banner.

Bug: 906673
Change-Id: Ic09242e902cb4a76cc3deb879a1dd62b71614bf7
Reviewed-on: https://chromium-review.googlesource.com/c/1342618Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609660}
parent dae73840
...@@ -527,8 +527,12 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -527,8 +527,12 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
} }
private CustomTabDelegateFactory createCustomTabDelegateFactory() { private CustomTabDelegateFactory createCustomTabDelegateFactory() {
// Don't show an app install banner for the user of a Trusted Web Activity - they've already
// got an app installed!
// TODO(peconn): Look into allowing the banner again if the user leaves the Trusted origin.
boolean allowAppBanners = !mIntentDataProvider.isTrustedWebActivity();
return new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(), return new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(),
mIntentDataProvider.isOpenedByChrome(), mIntentDataProvider.isOpenedByChrome(), allowAppBanners,
getComponent().resolveControlsVisibilityDelegate()); getComponent().resolveControlsVisibilityDelegate());
} }
......
...@@ -192,6 +192,7 @@ public class CustomTabDelegateFactory extends TabDelegateFactory { ...@@ -192,6 +192,7 @@ public class CustomTabDelegateFactory extends TabDelegateFactory {
private final boolean mShouldHideBrowserControls; private final boolean mShouldHideBrowserControls;
private final boolean mIsOpenedByChrome; private final boolean mIsOpenedByChrome;
private final boolean mShouldAllowAppBanners;
private final BrowserControlsVisibilityDelegate mBrowserStateVisibilityDelegate; private final BrowserControlsVisibilityDelegate mBrowserStateVisibilityDelegate;
private ExternalNavigationDelegateImpl mNavigationDelegate; private ExternalNavigationDelegateImpl mNavigationDelegate;
...@@ -200,16 +201,26 @@ public class CustomTabDelegateFactory extends TabDelegateFactory { ...@@ -200,16 +201,26 @@ public class CustomTabDelegateFactory extends TabDelegateFactory {
/** /**
* @param shouldHideBrowserControls Whether or not the browser controls may auto-hide. * @param shouldHideBrowserControls Whether or not the browser controls may auto-hide.
* @param isOpenedByChrome Whether the CustomTab was originally opened by Chrome. * @param isOpenedByChrome Whether the CustomTab was originally opened by Chrome.
* @param shouldAllowAppBanners Whether app install banners can be shown.
* @param visibilityDelegate The delegate that handles browser control visibility associated * @param visibilityDelegate The delegate that handles browser control visibility associated
* with browser actions (as opposed to tab state). * with browser actions (as opposed to tab state).
*/ */
public CustomTabDelegateFactory(boolean shouldHideBrowserControls, boolean isOpenedByChrome, public CustomTabDelegateFactory(boolean shouldHideBrowserControls, boolean isOpenedByChrome,
BrowserControlsVisibilityDelegate visibilityDelegate) { boolean shouldAllowAppBanners, BrowserControlsVisibilityDelegate visibilityDelegate) {
mShouldHideBrowserControls = shouldHideBrowserControls; mShouldHideBrowserControls = shouldHideBrowserControls;
mIsOpenedByChrome = isOpenedByChrome; mIsOpenedByChrome = isOpenedByChrome;
mShouldAllowAppBanners = shouldAllowAppBanners;
mBrowserStateVisibilityDelegate = visibilityDelegate; mBrowserStateVisibilityDelegate = visibilityDelegate;
} }
/**
* Creates a basic/empty CustomTabDelegateFactory for use when creating a hidden tab. It will
* be replaced when the hidden Tab becomes shown.
*/
static CustomTabDelegateFactory createDummy() {
return new CustomTabDelegateFactory(false, false, false, null);
}
@Override @Override
public BrowserControlsVisibilityDelegate createBrowserControlsVisibilityDelegate(Tab tab) { public BrowserControlsVisibilityDelegate createBrowserControlsVisibilityDelegate(Tab tab) {
TabStateBrowserControlsVisibilityDelegate tabDelegate = TabStateBrowserControlsVisibilityDelegate tabDelegate =
...@@ -247,6 +258,11 @@ public class CustomTabDelegateFactory extends TabDelegateFactory { ...@@ -247,6 +258,11 @@ public class CustomTabDelegateFactory extends TabDelegateFactory {
ChromeContextMenuPopulator.ContextMenuMode.CUSTOM_TAB); ChromeContextMenuPopulator.ContextMenuMode.CUSTOM_TAB);
} }
@Override
public boolean canShowAppBanners(Tab tab) {
return mShouldAllowAppBanners;
}
/** /**
* @return The {@link ExternalNavigationHandler} in this tab. For test purpose only. * @return The {@link ExternalNavigationHandler} in this tab. For test purpose only.
*/ */
......
...@@ -1445,7 +1445,7 @@ public class CustomTabsConnection { ...@@ -1445,7 +1445,7 @@ public class CustomTabsConnection {
if (extras != null) extrasIntent.putExtras(extras); if (extras != null) extrasIntent.putExtras(extras);
if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) return; if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null) return;
Tab tab = Tab.createDetached(new CustomTabDelegateFactory(false, false, null)); Tab tab = Tab.createDetached(CustomTabDelegateFactory.createDummy());
HiddenTabObserver observer = new HiddenTabObserver(this); HiddenTabObserver observer = new HiddenTabObserver(this);
tab.addObserver(observer); tab.addObserver(observer);
......
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