Commit cc217784 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android Refactor] Delete WebApkActivity part 2/3

This CL:
- Removes the remaining methods in WebApkActivity.
- Introduces BrowserServicesIntentDataProvider#getActivityType()

BUG=1059580

Change-Id: Ic54d36b27bc6ca8ee3f4f83419b41f53ff6ab3da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121444
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756320}
parent f29a5569
...@@ -20,6 +20,7 @@ import androidx.browser.trusted.sharing.ShareData; ...@@ -20,6 +20,7 @@ import androidx.browser.trusted.sharing.ShareData;
import androidx.browser.trusted.sharing.ShareTarget; import androidx.browser.trusted.sharing.ShareTarget;
import org.chromium.chrome.browser.customtabs.CustomButtonParams; import org.chromium.chrome.browser.customtabs.CustomButtonParams;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.webapps.WebApkExtras; import org.chromium.chrome.browser.webapps.WebApkExtras;
import org.chromium.chrome.browser.webapps.WebappExtras; import org.chromium.chrome.browser.webapps.WebappExtras;
...@@ -29,9 +30,9 @@ import java.util.Collections; ...@@ -29,9 +30,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Interface for model classes which parses incoming intent for customization data. * Base class for model classes which parse incoming intent for customization data.
*/ */
public class BrowserServicesIntentDataProvider { public abstract class BrowserServicesIntentDataProvider {
// The type of UI for Custom Tab to use. // The type of UI for Custom Tab to use.
@IntDef({CustomTabsUiType.DEFAULT, CustomTabsUiType.MEDIA_VIEWER, @IntDef({CustomTabsUiType.DEFAULT, CustomTabsUiType.MEDIA_VIEWER,
CustomTabsUiType.PAYMENT_REQUEST, CustomTabsUiType.INFO_PAGE, CustomTabsUiType.PAYMENT_REQUEST, CustomTabsUiType.INFO_PAGE,
...@@ -48,6 +49,11 @@ public class BrowserServicesIntentDataProvider { ...@@ -48,6 +49,11 @@ public class BrowserServicesIntentDataProvider {
int OFFLINE_PAGE = 6; int OFFLINE_PAGE = 6;
} }
/**
* @return The type of the Activity;
*/
public abstract @ActivityType int getActivityType();
/** /**
* @return the Intent this instance was created with. * @return the Intent this instance was created with.
*/ */
...@@ -299,22 +305,23 @@ public class BrowserServicesIntentDataProvider { ...@@ -299,22 +305,23 @@ public class BrowserServicesIntentDataProvider {
/** /**
* @return Whether the Activity should attempt to display a Trusted Web Activity. * @return Whether the Activity should attempt to display a Trusted Web Activity.
*/ */
public boolean isTrustedWebActivity() { public final boolean isTrustedWebActivity() {
return false; return getActivityType() == ActivityType.TRUSTED_WEB_ACTIVITY;
} }
/** /**
* @return Whether the Activity is either a Webapp or a WebAPK activity. * @return Whether the Activity is either a Webapp or a WebAPK activity.
*/ */
public boolean isWebappOrWebApkActivity() { public final boolean isWebappOrWebApkActivity() {
return false; return getActivityType() == ActivityType.WEBAPP
|| getActivityType() == ActivityType.WEB_APK;
} }
/** /**
* @return Whether the Activity is a WebAPK activity. * @return Whether the Activity is a WebAPK activity.
*/ */
public boolean isWebApkActivity() { public final boolean isWebApkActivity() {
return false; return getActivityType() == ActivityType.WEB_APK;
} }
/** /**
......
...@@ -114,6 +114,12 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo ...@@ -114,6 +114,12 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo
return mTabFactory.createTabCreators(); return mTabFactory.createTabCreators();
} }
@Override
@ActivityType
public int getActivityType() {
return getIntentDataProvider().getActivityType();
}
@Override @Override
public void initializeCompositor() { public void initializeCompositor() {
super.initializeCompositor(); super.initializeCompositor();
......
...@@ -45,7 +45,6 @@ import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActi ...@@ -45,7 +45,6 @@ import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActi
import org.chromium.chrome.browser.customtabs.features.CustomTabNavigationBarController; import org.chromium.chrome.browser.customtabs.features.CustomTabNavigationBarController;
import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule; import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.infobar.InfoBarContainer; import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.night_mode.NightModeStateProvider; import org.chromium.chrome.browser.night_mode.NightModeStateProvider;
...@@ -102,13 +101,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo ...@@ -102,13 +101,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo
} }
} }
@Override
@ActivityType
public int getActivityType() {
return mIntentDataProvider.isTrustedWebActivity()
? ActivityType.TRUSTED_WEB_ACTIVITY : ActivityType.CUSTOM_TAB;
}
@Override @Override
public void performPreInflationStartup() { public void performPreInflationStartup() {
// Parse the data from the Intent before calling super to allow the Intent to customize // Parse the data from the Intent before calling super to allow the Intent to customize
......
...@@ -43,6 +43,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -43,6 +43,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeVersionInfo; import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.browser_ui.styles.ChromeColors; import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.TintedDrawable; import org.chromium.components.browser_ui.widget.TintedDrawable;
...@@ -165,7 +166,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -165,7 +166,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
private final int mInitialBackgroundColor; private final int mInitialBackgroundColor;
private final boolean mDisableStar; private final boolean mDisableStar;
private final boolean mDisableDownload; private final boolean mDisableDownload;
private final boolean mIsTrustedWebActivity; private final @ActivityType int mActivityType;
@Nullable @Nullable
private final Integer mNavigationBarColor; private final Integer mNavigationBarColor;
private final boolean mIsIncognito; private final boolean mIsIncognito;
...@@ -306,8 +307,10 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -306,8 +307,10 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
} }
} }
mIsTrustedWebActivity = IntentUtils.safeGetBooleanExtra( mActivityType = IntentUtils.safeGetBooleanExtra(
intent, TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false); intent, TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false)
? ActivityType.TRUSTED_WEB_ACTIVITY
: ActivityType.CUSTOM_TAB;
mTrustedWebActivityAdditionalOrigins = IntentUtils.safeGetStringArrayListExtra(intent, mTrustedWebActivityAdditionalOrigins = IntentUtils.safeGetStringArrayListExtra(intent,
TrustedWebActivityIntentBuilder.EXTRA_ADDITIONAL_TRUSTED_ORIGINS); TrustedWebActivityIntentBuilder.EXTRA_ADDITIONAL_TRUSTED_ORIGINS);
mTrustedWebActivityDisplayMode = resolveTwaDisplayMode(); mTrustedWebActivityDisplayMode = resolveTwaDisplayMode();
...@@ -528,6 +531,11 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -528,6 +531,11 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
} }
} }
@Override
public @ActivityType int getActivityType() {
return mActivityType;
}
@Override @Override
@Nullable @Nullable
public Intent getIntent() { public Intent getIntent() {
...@@ -728,11 +736,6 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid ...@@ -728,11 +736,6 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return mIsIncognito; return mIsIncognito;
} }
@Override
public boolean isTrustedWebActivity() {
return mIsTrustedWebActivity;
}
@Nullable @Nullable
@Override @Override
public TrustedWebActivityDisplayMode getTwaDisplayMode() { public TrustedWebActivityDisplayMode getTwaDisplayMode() {
......
...@@ -15,6 +15,7 @@ import androidx.browser.customtabs.CustomTabsSessionToken; ...@@ -15,6 +15,7 @@ import androidx.browser.customtabs.CustomTabsSessionToken;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.net.NetworkChangeNotifier; import org.chromium.net.NetworkChangeNotifier;
...@@ -73,8 +74,7 @@ public class CustomTabIntentHandler { ...@@ -73,8 +74,7 @@ public class CustomTabIntentHandler {
runWhenTabCreated(() -> { runWhenTabCreated(() -> {
if (mTabProvider.getInitialTabCreationMode() != TabCreationMode.RESTORED) { if (mTabProvider.getInitialTabCreationMode() != TabCreationMode.RESTORED) {
mHandlingStrategy.handleInitialIntent(mIntentDataProvider); mHandlingStrategy.handleInitialIntent(mIntentDataProvider);
} else if (mIntentDataProvider.isWebappOrWebApkActivity() } else if (mIntentDataProvider.getActivityType() == ActivityType.WEBAPP
&& !mIntentDataProvider.isWebApkActivity()
&& NetworkChangeNotifier.isOnline()) { && NetworkChangeNotifier.isOnline()) {
mTabProvider.getTab().reloadIgnoringCache(); mTabProvider.getTab().reloadIgnoringCache();
} }
......
...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controll ...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controll
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler.IntentIgnoringCriterion; import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler.IntentIgnoringCriterion;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandlingStrategy; import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandlingStrategy;
import org.chromium.chrome.browser.customtabs.content.DefaultCustomTabIntentHandlingStrategy; import org.chromium.chrome.browser.customtabs.content.DefaultCustomTabIntentHandlingStrategy;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.webapps.AddToHomescreenVerifier; import org.chromium.chrome.browser.webapps.AddToHomescreenVerifier;
import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator; import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator;
import org.chromium.chrome.browser.webapps.WebApkVerifier; import org.chromium.chrome.browser.webapps.WebApkVerifier;
...@@ -26,11 +27,13 @@ import dagger.Reusable; ...@@ -26,11 +27,13 @@ import dagger.Reusable;
@Module @Module
public class BaseCustomTabActivityModule { public class BaseCustomTabActivityModule {
private final BrowserServicesIntentDataProvider mIntentDataProvider; private final BrowserServicesIntentDataProvider mIntentDataProvider;
private final @ActivityType int mActivityType;
private final IntentIgnoringCriterion mIntentIgnoringCriterion; private final IntentIgnoringCriterion mIntentIgnoringCriterion;
public BaseCustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider, public BaseCustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider,
IntentIgnoringCriterion intentIgnoringCriterion) { IntentIgnoringCriterion intentIgnoringCriterion) {
mIntentDataProvider = intentDataProvider; mIntentDataProvider = intentDataProvider;
mActivityType = intentDataProvider.getActivityType();
mIntentIgnoringCriterion = intentIgnoringCriterion; mIntentIgnoringCriterion = intentIgnoringCriterion;
} }
...@@ -43,8 +46,8 @@ public class BaseCustomTabActivityModule { ...@@ -43,8 +46,8 @@ public class BaseCustomTabActivityModule {
public CustomTabIntentHandlingStrategy provideIntentHandler( public CustomTabIntentHandlingStrategy provideIntentHandler(
Lazy<DefaultCustomTabIntentHandlingStrategy> defaultHandler, Lazy<DefaultCustomTabIntentHandlingStrategy> defaultHandler,
Lazy<TwaIntentHandlingStrategy> twaHandler) { Lazy<TwaIntentHandlingStrategy> twaHandler) {
return (mIntentDataProvider.isTrustedWebActivity() return (mActivityType == ActivityType.TRUSTED_WEB_ACTIVITY
|| mIntentDataProvider.isWebApkActivity()) || mActivityType == ActivityType.WEB_APK)
? twaHandler.get() ? twaHandler.get()
: defaultHandler.get(); : defaultHandler.get();
} }
...@@ -52,10 +55,10 @@ public class BaseCustomTabActivityModule { ...@@ -52,10 +55,10 @@ public class BaseCustomTabActivityModule {
@Provides @Provides
public Verifier provideVerifier(Lazy<WebApkVerifier> webApkVerifier, public Verifier provideVerifier(Lazy<WebApkVerifier> webApkVerifier,
Lazy<AddToHomescreenVerifier> addToHomescreenVerifier, Lazy<TwaVerifier> twaVerifier) { Lazy<AddToHomescreenVerifier> addToHomescreenVerifier, Lazy<TwaVerifier> twaVerifier) {
if (mIntentDataProvider.isWebApkActivity()) { if (mActivityType == ActivityType.WEB_APK) {
return webApkVerifier.get(); return webApkVerifier.get();
} }
if (mIntentDataProvider.isWebappOrWebApkActivity()) { if (mActivityType == ActivityType.WEBAPP) {
return addToHomescreenVerifier.get(); return addToHomescreenVerifier.get();
} }
return twaVerifier.get(); return twaVerifier.get();
......
...@@ -4,48 +4,9 @@ ...@@ -4,48 +4,9 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import android.content.Intent;
import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.webapk.lib.common.WebApkConstants;
/** /**
* An Activity is designed for WebAPKs (native Android apps) and displays a webapp in a nearly * An Activity is designed for WebAPKs (native Android apps) and displays a webapp in a nearly
* UI-less Chrome. * UI-less Chrome.
*/ */
public class WebApkActivity extends WebappActivity { public class WebApkActivity extends WebappActivity {
private static final String TAG = "WebApkActivity";
@Override
protected WebappInfo createWebappInfo(Intent intent) {
return (intent == null) ? WebApkInfo.createEmpty() : WebApkInfo.create(intent);
}
@Override
public boolean shouldPreferLightweightFre(Intent intent) {
// We cannot use getWebApkPackageName() because
// {@link WebappActivity#performPreInflationStartup()} may not have been called yet.
String webApkPackageName =
IntentUtils.safeGetStringExtra(intent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME);
// Use the lightweight FRE for unbound WebAPKs.
return webApkPackageName != null
&& !webApkPackageName.startsWith(WebApkConstants.WEBAPK_PACKAGE_PREFIX);
}
@Override
protected void onDestroyInternal() {
// The common case is to be connected to just one WebAPK's services. For the sake of
// simplicity disconnect from the services of all WebAPKs.
ChromeWebApkHost.disconnectFromAllServices(true /* waitForPendingWork */);
super.onDestroyInternal();
}
@Override
@ActivityType
public int getActivityType() {
return ActivityType.WEB_APK;
}
} }
...@@ -8,6 +8,8 @@ import androidx.annotation.Nullable; ...@@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -18,8 +20,8 @@ import dagger.Lazy; ...@@ -18,8 +20,8 @@ import dagger.Lazy;
* Add methods here if other components need to communicate with the WebAPK activity component. * Add methods here if other components need to communicate with the WebAPK activity component.
*/ */
@ActivityScope @ActivityScope
public class WebApkActivityCoordinator { public class WebApkActivityCoordinator implements Destroyable {
private final WebApkActivity mActivity; private final WebappActivity mActivity;
private final Lazy<WebApkUpdateManager> mWebApkUpdateManager; private final Lazy<WebApkUpdateManager> mWebApkUpdateManager;
@Inject @Inject
...@@ -27,12 +29,13 @@ public class WebApkActivityCoordinator { ...@@ -27,12 +29,13 @@ public class WebApkActivityCoordinator {
WebappDeferredStartupWithStorageHandler deferredStartupWithStorageHandler, WebappDeferredStartupWithStorageHandler deferredStartupWithStorageHandler,
WebappDisclosureSnackbarController disclosureSnackbarController, WebappDisclosureSnackbarController disclosureSnackbarController,
WebApkActivityLifecycleUmaTracker webApkActivityLifecycleUmaTracker, WebApkActivityLifecycleUmaTracker webApkActivityLifecycleUmaTracker,
ActivityLifecycleDispatcher lifecycleDispatcher,
Lazy<WebApkUpdateManager> webApkUpdateManager) { Lazy<WebApkUpdateManager> webApkUpdateManager) {
// We don't need to do anything with |disclosureSnackbarController| and // We don't need to do anything with |disclosureSnackbarController| and
// |webApkActivityLifecycleUmaTracker|. We just need to resolve // |webApkActivityLifecycleUmaTracker|. We just need to resolve
// them so that they start working. // them so that they start working.
mActivity = (WebApkActivity) activity; mActivity = (WebappActivity) activity;
mWebApkUpdateManager = webApkUpdateManager; mWebApkUpdateManager = webApkUpdateManager;
deferredStartupWithStorageHandler.addTask((storage, didCreateStorage) -> { deferredStartupWithStorageHandler.addTask((storage, didCreateStorage) -> {
...@@ -40,6 +43,7 @@ public class WebApkActivityCoordinator { ...@@ -40,6 +43,7 @@ public class WebApkActivityCoordinator {
onDeferredStartupWithStorage(storage, didCreateStorage); onDeferredStartupWithStorage(storage, didCreateStorage);
}); });
lifecycleDispatcher.register(this);
} }
public void onDeferredStartupWithStorage( public void onDeferredStartupWithStorage(
...@@ -50,4 +54,11 @@ public class WebApkActivityCoordinator { ...@@ -50,4 +54,11 @@ public class WebApkActivityCoordinator {
WebApkInfo info = (WebApkInfo) mActivity.getWebappInfo(); WebApkInfo info = (WebApkInfo) mActivity.getWebappInfo();
mWebApkUpdateManager.get().updateIfNeeded(storage, info); mWebApkUpdateManager.get().updateIfNeeded(storage, info);
} }
@Override
public void destroy() {
// The common case is to be connected to just one WebAPK's services. For the sake of
// simplicity disconnect from the services of all WebAPKs.
ChromeWebApkHost.disconnectFromAllServices(true /* waitForPendingWork */);
}
} }
...@@ -94,10 +94,6 @@ public class WebApkInfo extends WebappInfo { ...@@ -94,10 +94,6 @@ public class WebApkInfo extends WebappInfo {
} }
} }
public static WebApkInfo createEmpty() {
return create(createEmptyIntentDataProvider());
}
/** /**
* Constructs a WebApkInfo from the passed in Intent and <meta-data> in the WebAPK's Android * Constructs a WebApkInfo from the passed in Intent and <meta-data> in the WebAPK's Android
* manifest. * manifest.
......
...@@ -21,6 +21,7 @@ import androidx.annotation.VisibleForTesting; ...@@ -21,6 +21,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ActivityState; import org.chromium.base.ActivityState;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
...@@ -40,7 +41,6 @@ import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTab ...@@ -40,7 +41,6 @@ import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTab
import org.chromium.chrome.browser.customtabs.features.ImmersiveModeController; import org.chromium.chrome.browser.customtabs.features.ImmersiveModeController;
import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule; import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule;
import org.chromium.chrome.browser.document.ChromeLauncherActivity; import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabBrowserControlsConstraintsHelper; import org.chromium.chrome.browser.tab.TabBrowserControlsConstraintsHelper;
import org.chromium.chrome.browser.tab.TabDelegateFactory; import org.chromium.chrome.browser.tab.TabDelegateFactory;
...@@ -53,6 +53,7 @@ import org.chromium.components.embedder_support.delegate.WebContentsDelegateAndr ...@@ -53,6 +53,7 @@ import org.chromium.components.embedder_support.delegate.WebContentsDelegateAndr
import org.chromium.content_public.browser.NavigationHandle; import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.ScreenOrientationProvider; import org.chromium.content_public.browser.ScreenOrientationProvider;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.webapk.lib.common.WebApkConstants;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -152,12 +153,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -152,12 +153,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
} }
} }
@Override
@ActivityType
public int getActivityType() {
return ActivityType.WEBAPP;
}
protected boolean loadUrlIfPostShareTarget(WebappInfo webappInfo) { protected boolean loadUrlIfPostShareTarget(WebappInfo webappInfo) {
return false; return false;
} }
...@@ -167,7 +162,24 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -167,7 +162,24 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
} }
protected WebappInfo createWebappInfo(Intent intent) { protected WebappInfo createWebappInfo(Intent intent) {
return (intent == null) ? WebappInfo.createEmpty() : WebappInfo.create(intent); if (intent == null) return WebappInfo.createEmpty();
WebappInfo info = WebApkInfo.create(intent);
if (info != null) return info;
return WebappInfo.create(intent);
}
@Override
public boolean shouldPreferLightweightFre(Intent intent) {
// We cannot use WebappInfo#webApkPackageName() because
// {@link WebappActivity#performPreInflationStartup()} may not have been called yet.
String webApkPackageName =
IntentUtils.safeGetStringExtra(intent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME);
// Use the lightweight FRE for unbound WebAPKs.
return webApkPackageName != null
&& !webApkPackageName.startsWith(WebApkConstants.WEBAPK_PACKAGE_PREFIX);
} }
@Override @Override
......
...@@ -18,14 +18,11 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv ...@@ -18,14 +18,11 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
public class WebappInfo { public class WebappInfo {
protected final BrowserServicesIntentDataProvider mProvider; protected final BrowserServicesIntentDataProvider mProvider;
protected static BrowserServicesIntentDataProvider createEmptyIntentDataProvider() {
return new WebappIntentDataProvider(WebappIntentDataProvider.getDefaultToolbarColor(),
false /* hasCustomToolbarColor */, null /* shareData */, WebappExtras.createEmpty(),
WebApkExtras.createEmpty());
}
public static WebappInfo createEmpty() { public static WebappInfo createEmpty() {
return new WebappInfo(createEmptyIntentDataProvider()); return new WebappInfo(
new WebappIntentDataProvider(WebappIntentDataProvider.getDefaultToolbarColor(),
false /* hasCustomToolbarColor */, null /* shareData */,
WebappExtras.createEmpty(), WebApkExtras.createEmpty()));
} }
/** /**
......
...@@ -16,6 +16,7 @@ import androidx.browser.trusted.sharing.ShareData; ...@@ -16,6 +16,7 @@ import androidx.browser.trusted.sharing.ShareData;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.components.browser_ui.widget.TintedDrawable; import org.chromium.components.browser_ui.widget.TintedDrawable;
/** /**
...@@ -28,6 +29,7 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider ...@@ -28,6 +29,7 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
private final ShareData mShareData; private final ShareData mShareData;
private final @NonNull WebappExtras mWebappExtras; private final @NonNull WebappExtras mWebappExtras;
private final @Nullable WebApkExtras mWebApkExtras; private final @Nullable WebApkExtras mWebApkExtras;
private final @ActivityType int mActivityType;
private final Intent mIntent; private final Intent mIntent;
/** /**
...@@ -46,9 +48,15 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider ...@@ -46,9 +48,15 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
mShareData = shareData; mShareData = shareData;
mWebappExtras = webappExtras; mWebappExtras = webappExtras;
mWebApkExtras = webApkExtras; mWebApkExtras = webApkExtras;
mActivityType = (webApkExtras != null) ? ActivityType.WEB_APK : ActivityType.WEBAPP;
mIntent = new Intent(); mIntent = new Intent();
} }
@Override
public @ActivityType int getActivityType() {
return mActivityType;
}
@Override @Override
@Nullable @Nullable
public Intent getIntent() { public Intent getIntent() {
...@@ -81,16 +89,6 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider ...@@ -81,16 +89,6 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
return CustomTabsIntent.SHOW_PAGE_TITLE; return CustomTabsIntent.SHOW_PAGE_TITLE;
} }
@Override
public boolean isWebappOrWebApkActivity() {
return true;
}
@Override
public boolean isWebApkActivity() {
return mWebApkExtras != null;
}
@Override @Override
@Nullable @Nullable
public ShareData getShareData() { public ShareData getShareData() {
......
...@@ -32,6 +32,7 @@ import org.chromium.base.metrics.test.DisableHistogramsRule; ...@@ -32,6 +32,7 @@ import org.chromium.base.metrics.test.DisableHistogramsRule;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebappExtras; import org.chromium.chrome.browser.webapps.WebappExtras;
import org.chromium.content_public.browser.NavigationController; import org.chromium.content_public.browser.NavigationController;
...@@ -78,7 +79,9 @@ public class CloseButtonNavigatorTest { ...@@ -78,7 +79,9 @@ public class CloseButtonNavigatorTest {
mWebappExtras = null; mWebappExtras = null;
} }
doReturn(mWebappExtras).when(mIntentDataProvider).getWebappExtras(); doReturn(mWebappExtras).when(mIntentDataProvider).getWebappExtras();
doReturn(mIsWebapp).when(mIntentDataProvider).isWebappOrWebApkActivity(); doReturn(mIsWebapp ? ActivityType.WEBAPP : ActivityType.CUSTOM_TAB)
.when(mIntentDataProvider)
.getActivityType();
mCloseButtonNavigator = mCloseButtonNavigator =
new CloseButtonNavigator(mTabController, mTabProvider, mIntentDataProvider); new CloseButtonNavigator(mTabController, mTabProvider, mIntentDataProvider);
......
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