Commit 1011eb52 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Show correct display-mode value in TWAs.

All custom tab activities were defaulting to browser mode. This CL sets
the display mode to `standalone` where applicable. The BrowserControlsVisibilityDelegate
is used to make this decision, since even with standalone TWAs,
navigations and failed verifications can lead the tab to go back browser
mode.

Bug: 941749
Change-Id: I2454f708dd6d99660513eac8353d3497eb9829d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826887Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703293}
parent 193ddf44
...@@ -39,6 +39,7 @@ import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; ...@@ -39,6 +39,7 @@ import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate; import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.chrome.browser.util.IntentUtils; import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.UrlUtilities; import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.chrome.browser.webapps.WebDisplayMode;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.ResourceRequestBody; import org.chromium.content_public.common.ResourceRequestBody;
import org.chromium.ui.mojom.WindowOpenDisposition; import org.chromium.ui.mojom.WindowOpenDisposition;
...@@ -151,15 +152,18 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -151,15 +152,18 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
extends ActivityTabWebContentsDelegateAndroid { extends ActivityTabWebContentsDelegateAndroid {
private final MultiWindowUtils mMultiWindowUtils; private final MultiWindowUtils mMultiWindowUtils;
private final boolean mShouldEnableEmbeddedMediaExperience; private final boolean mShouldEnableEmbeddedMediaExperience;
private final boolean mIsTrustedWebActivity;
/** /**
* See {@link TabWebContentsDelegateAndroid}. * See {@link TabWebContentsDelegateAndroid}.
*/ */
public CustomTabWebContentsDelegate(Tab tab, ChromeActivity activity, public CustomTabWebContentsDelegate(Tab tab, ChromeActivity activity,
MultiWindowUtils multiWindowUtils, boolean shouldEnableEmbeddedMediaExperience) { MultiWindowUtils multiWindowUtils, boolean shouldEnableEmbeddedMediaExperience,
boolean isTrustedWebActivity) {
super(tab, activity); super(tab, activity);
mMultiWindowUtils = multiWindowUtils; mMultiWindowUtils = multiWindowUtils;
mShouldEnableEmbeddedMediaExperience = shouldEnableEmbeddedMediaExperience; mShouldEnableEmbeddedMediaExperience = shouldEnableEmbeddedMediaExperience;
mIsTrustedWebActivity = isTrustedWebActivity;
} }
@Override @Override
...@@ -203,12 +207,17 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -203,12 +207,17 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
super.openNewTab(url, extraHeaders, postData, disposition, isRendererInitiated); super.openNewTab(url, extraHeaders, postData, disposition, isRendererInitiated);
} }
@Override
protected @WebDisplayMode int getDisplayMode() {
return mIsTrustedWebActivity ? WebDisplayMode.STANDALONE : WebDisplayMode.BROWSER;
}
} }
private final ChromeActivity mActivity; private final ChromeActivity mActivity;
private final boolean mShouldHideBrowserControls; private final boolean mShouldHideBrowserControls;
private final boolean mIsOpenedByChrome; private final boolean mIsOpenedByChrome;
private final boolean mShouldAllowAppBanners; private final boolean mIsTrustedWebActivity;
private final boolean mShouldEnableEmbeddedMediaExperience; private final boolean mShouldEnableEmbeddedMediaExperience;
private final BrowserControlsVisibilityDelegate mBrowserStateVisibilityDelegate; private final BrowserControlsVisibilityDelegate mBrowserStateVisibilityDelegate;
private final ExternalAuthUtils mExternalAuthUtils; private final ExternalAuthUtils mExternalAuthUtils;
...@@ -220,20 +229,20 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -220,20 +229,20 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
* @param activity {@link ChromeActivity} instance. * @param activity {@link ChromeActivity} instance.
* @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 isTrustedWebActivity Whether the CustomTab is a TWA.
* @param shouldEnableEmbeddedMediaExperience Whether embedded media experience is enabled. * @param shouldEnableEmbeddedMediaExperience Whether embedded media experience is enabled.
* @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).
*/ */
private CustomTabDelegateFactory(ChromeActivity activity, boolean shouldHideBrowserControls, private CustomTabDelegateFactory(ChromeActivity activity, boolean shouldHideBrowserControls,
boolean isOpenedByChrome, boolean shouldAllowAppBanners, boolean isOpenedByChrome, boolean isTrustedWebActivity,
boolean shouldEnableEmbeddedMediaExperience, boolean shouldEnableEmbeddedMediaExperience,
BrowserControlsVisibilityDelegate visibilityDelegate, ExternalAuthUtils authUtils, BrowserControlsVisibilityDelegate visibilityDelegate, ExternalAuthUtils authUtils,
MultiWindowUtils multiWindowUtils) { MultiWindowUtils multiWindowUtils) {
mActivity = activity; mActivity = activity;
mShouldHideBrowserControls = shouldHideBrowserControls; mShouldHideBrowserControls = shouldHideBrowserControls;
mIsOpenedByChrome = isOpenedByChrome; mIsOpenedByChrome = isOpenedByChrome;
mShouldAllowAppBanners = shouldAllowAppBanners; mIsTrustedWebActivity = isTrustedWebActivity;
mShouldEnableEmbeddedMediaExperience = shouldEnableEmbeddedMediaExperience; mShouldEnableEmbeddedMediaExperience = shouldEnableEmbeddedMediaExperience;
mBrowserStateVisibilityDelegate = visibilityDelegate; mBrowserStateVisibilityDelegate = visibilityDelegate;
mExternalAuthUtils = authUtils; mExternalAuthUtils = authUtils;
...@@ -248,7 +257,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -248,7 +257,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
// Don't show an app install banner for the user of a Trusted Web Activity - they've already // Don't show an app install banner for the user of a Trusted Web Activity - they've already
// got an app installed! // got an app installed!
this(activity, intentDataProvider.shouldEnableUrlBarHiding(), this(activity, intentDataProvider.shouldEnableUrlBarHiding(),
intentDataProvider.isOpenedByChrome(), !intentDataProvider.isTrustedWebActivity(), intentDataProvider.isOpenedByChrome(), intentDataProvider.isTrustedWebActivity(),
intentDataProvider.shouldEnableEmbeddedMediaExperience(), visibilityDelegate, intentDataProvider.shouldEnableEmbeddedMediaExperience(), visibilityDelegate,
authUtils, multiWindowUtils); authUtils, multiWindowUtils);
} }
...@@ -281,8 +290,8 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -281,8 +290,8 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
@Override @Override
public TabWebContentsDelegateAndroid createWebContentsDelegate(Tab tab) { public TabWebContentsDelegateAndroid createWebContentsDelegate(Tab tab) {
return new CustomTabWebContentsDelegate( return new CustomTabWebContentsDelegate(tab, mActivity, mMultiWindowUtils,
tab, mActivity, mMultiWindowUtils, mShouldEnableEmbeddedMediaExperience); mShouldEnableEmbeddedMediaExperience, mIsTrustedWebActivity);
} }
@Override @Override
...@@ -304,7 +313,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory { ...@@ -304,7 +313,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
@Override @Override
public boolean canShowAppBanners() { public boolean canShowAppBanners() {
return mShouldAllowAppBanners; return !mIsTrustedWebActivity;
} }
/** /**
......
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