Commit 12db8dbd authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Support TWA immersive mode 2/2

This is the second part after http://crrev.com/c/1803278.
This one relies on androidx-browser API updates.

Bug: 989610, 965329
Change-Id: Iccf0ed18a8db2e692e787211cfe53eaebedd5cb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844987
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720924}
parent 77c98968
......@@ -1157,6 +1157,7 @@ by a child template that "extends" this file.
<category android:name="androidx.browser.customtabs.category.NavBarColorCustomization"/>
<category android:name="androidx.browser.customtabs.category.ColorSchemeCustomization"/>
<category android:name="androidx.browser.trusted.category.WebShareTargetV2"/>
<category android:name="androidx.browser.trusted.category.ImmersiveMode"/>
</intent-filter>
</service>
<service android:name="androidx.browser.customtabs.PostMessageService" />
......
......@@ -2030,6 +2030,7 @@
<action android:name="android.support.customtabs.action.CustomTabsService"/>
<category android:name="androidx.browser.customtabs.category.ColorSchemeCustomization"/>
<category android:name="androidx.browser.customtabs.category.NavBarColorCustomization"/>
<category android:name="androidx.browser.trusted.category.ImmersiveMode"/>
<category android:name="androidx.browser.trusted.category.TrustedWebActivities"/>
<category
android:name="androidx.browser.trusted.category.TrustedWebActivitySplashScreensV1"/>
......
......@@ -15,6 +15,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsSessionToken;
import androidx.browser.trusted.TrustedWebActivityDisplayMode;
import androidx.browser.trusted.sharing.ShareData;
import androidx.browser.trusted.sharing.ShareTarget;
......@@ -319,6 +320,14 @@ public class BrowserServicesIntentDataProvider {
return false;
}
/**
* Returns {@link TrustedWebActivityDisplayMode} supplied in the intent.
*/
@Nullable
public TrustedWebActivityDisplayMode getTwaDisplayMode() {
return null;
}
/**
* @return The component name of the module entry point, or null if not specified.
*/
......
......@@ -4,6 +4,10 @@
package org.chromium.chrome.browser.browserservices.trustedwebactivityui;
import androidx.annotation.Nullable;
import androidx.browser.trusted.TrustedWebActivityDisplayMode;
import androidx.browser.trusted.TrustedWebActivityDisplayMode.ImmersiveMode;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.Origin;
......@@ -46,6 +50,9 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
private final TwaRegistrar mTwaRegistrar;
private final ClientPackageNameProvider mClientPackageNameProvider;
@Nullable
private final TrustedWebActivityDisplayMode mDisplayMode;
private boolean mInTwaMode = true;
@Inject
......@@ -75,6 +82,7 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
mImmersiveModeController = immersiveModeController;
mTwaRegistrar = twaRegistrar;
mClientPackageNameProvider = clientPackageNameProvider;
mDisplayMode = intentDataProvider.getTwaDisplayMode();
navigationController.setLandingPageOnCloseCriterion(
verifier::wasPreviouslyVerified);
......@@ -142,7 +150,16 @@ public class TrustedWebActivityCoordinator implements InflationObserver {
}
private void updateImmersiveMode(boolean inTwaMode) {
// TODO(pshmakov): implement this once we can depend on tip-of-tree of androidx-browser.
if (!(mDisplayMode instanceof ImmersiveMode)) {
return;
}
if (inTwaMode) {
ImmersiveMode immersiveMode = (ImmersiveMode) mDisplayMode;
mImmersiveModeController.get().enterImmersiveMode(
immersiveMode.layoutInDisplayCutoutMode(), immersiveMode.isSticky());
} else {
mImmersiveModeController.get().exitImmersiveMode();
}
}
// This doesn't belong here, but doesn't deserve a separate class. Do extract it if more
......
......@@ -31,6 +31,7 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsSessionToken;
import androidx.browser.customtabs.TrustedWebUtils;
import androidx.browser.trusted.TrustedWebActivityDisplayMode;
import androidx.browser.trusted.TrustedWebActivityIntentBuilder;
import androidx.browser.trusted.sharing.ShareData;
import androidx.browser.trusted.sharing.ShareTarget;
......@@ -224,6 +225,8 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
@Nullable
private final List<String> mTrustedWebActivityAdditionalOrigins;
@Nullable
private final TrustedWebActivityDisplayMode mTrustedWebActivityDisplayMode;
@Nullable
private String mUrlToLoad;
private boolean mHasCustomToolbarColor;
......@@ -346,6 +349,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
intent, TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false);
mTrustedWebActivityAdditionalOrigins = IntentUtils.safeGetStringArrayListExtra(intent,
TrustedWebActivityIntentBuilder.EXTRA_ADDITIONAL_TRUSTED_ORIGINS);
mTrustedWebActivityDisplayMode = resolveTwaDisplayMode();
mTitleVisibilityState = IntentUtils.safeGetIntExtra(
intent, CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);
mShowShareItem = IntentUtils.safeGetBooleanExtra(intent,
......@@ -580,6 +584,20 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return url;
}
@Nullable
private TrustedWebActivityDisplayMode resolveTwaDisplayMode() {
Bundle bundle = IntentUtils.safeGetBundleExtra(mIntent,
TrustedWebActivityIntentBuilder.EXTRA_DISPLAY_MODE);
if (bundle == null) {
return null;
}
try {
return TrustedWebActivityDisplayMode.fromBundle(bundle);
} catch (Throwable e) {
return null;
}
}
@Override
@Nullable
public Intent getIntent() {
......@@ -790,6 +808,12 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return mIsTrustedWebActivity;
}
@Nullable
@Override
public TrustedWebActivityDisplayMode getTwaDisplayMode() {
return mTrustedWebActivityDisplayMode;
}
@Override
public boolean isDynamicModuleEnabled() {
if (!ChromeFeatureList.isInitialized()) return false;
......
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