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;
import androidx.browser.trusted.sharing.ShareTarget;
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.WebappExtras;
......@@ -29,9 +30,9 @@ import java.util.Collections;
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.
@IntDef({CustomTabsUiType.DEFAULT, CustomTabsUiType.MEDIA_VIEWER,
CustomTabsUiType.PAYMENT_REQUEST, CustomTabsUiType.INFO_PAGE,
......@@ -48,6 +49,11 @@ public class BrowserServicesIntentDataProvider {
int OFFLINE_PAGE = 6;
}
/**
* @return The type of the Activity;
*/
public abstract @ActivityType int getActivityType();
/**
* @return the Intent this instance was created with.
*/
......@@ -299,22 +305,23 @@ public class BrowserServicesIntentDataProvider {
/**
* @return Whether the Activity should attempt to display a Trusted Web Activity.
*/
public boolean isTrustedWebActivity() {
return false;
public final boolean isTrustedWebActivity() {
return getActivityType() == ActivityType.TRUSTED_WEB_ACTIVITY;
}
/**
* @return Whether the Activity is either a Webapp or a WebAPK activity.
*/
public boolean isWebappOrWebApkActivity() {
return false;
public final boolean isWebappOrWebApkActivity() {
return getActivityType() == ActivityType.WEBAPP
|| getActivityType() == ActivityType.WEB_APK;
}
/**
* @return Whether the Activity is a WebAPK activity.
*/
public boolean isWebApkActivity() {
return false;
public final boolean isWebApkActivity() {
return getActivityType() == ActivityType.WEB_APK;
}
/**
......
......@@ -114,6 +114,12 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo
return mTabFactory.createTabCreators();
}
@Override
@ActivityType
public int getActivityType() {
return getIntentDataProvider().getActivityType();
}
@Override
public void initializeCompositor() {
super.initializeCompositor();
......
......@@ -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.dependency_injection.ChromeActivityCommonsModule;
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.infobar.InfoBarContainer;
import org.chromium.chrome.browser.night_mode.NightModeStateProvider;
......@@ -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
public void performPreInflationStartup() {
// 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;
import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.TintedDrawable;
......@@ -165,7 +166,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
private final int mInitialBackgroundColor;
private final boolean mDisableStar;
private final boolean mDisableDownload;
private final boolean mIsTrustedWebActivity;
private final @ActivityType int mActivityType;
@Nullable
private final Integer mNavigationBarColor;
private final boolean mIsIncognito;
......@@ -306,8 +307,10 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
}
}
mIsTrustedWebActivity = IntentUtils.safeGetBooleanExtra(
intent, TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false);
mActivityType = IntentUtils.safeGetBooleanExtra(
intent, TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false)
? ActivityType.TRUSTED_WEB_ACTIVITY
: ActivityType.CUSTOM_TAB;
mTrustedWebActivityAdditionalOrigins = IntentUtils.safeGetStringArrayListExtra(intent,
TrustedWebActivityIntentBuilder.EXTRA_ADDITIONAL_TRUSTED_ORIGINS);
mTrustedWebActivityDisplayMode = resolveTwaDisplayMode();
......@@ -528,6 +531,11 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
}
}
@Override
public @ActivityType int getActivityType() {
return mActivityType;
}
@Override
@Nullable
public Intent getIntent() {
......@@ -728,11 +736,6 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return mIsIncognito;
}
@Override
public boolean isTrustedWebActivity() {
return mIsTrustedWebActivity;
}
@Nullable
@Override
public TrustedWebActivityDisplayMode getTwaDisplayMode() {
......
......@@ -15,6 +15,7 @@ import androidx.browser.customtabs.CustomTabsSessionToken;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
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.net.NetworkChangeNotifier;
......@@ -73,8 +74,7 @@ public class CustomTabIntentHandler {
runWhenTabCreated(() -> {
if (mTabProvider.getInitialTabCreationMode() != TabCreationMode.RESTORED) {
mHandlingStrategy.handleInitialIntent(mIntentDataProvider);
} else if (mIntentDataProvider.isWebappOrWebApkActivity()
&& !mIntentDataProvider.isWebApkActivity()
} else if (mIntentDataProvider.getActivityType() == ActivityType.WEBAPP
&& NetworkChangeNotifier.isOnline()) {
mTabProvider.getTab().reloadIgnoringCache();
}
......
......@@ -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.CustomTabIntentHandlingStrategy;
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.WebApkPostShareTargetNavigator;
import org.chromium.chrome.browser.webapps.WebApkVerifier;
......@@ -26,11 +27,13 @@ import dagger.Reusable;
@Module
public class BaseCustomTabActivityModule {
private final BrowserServicesIntentDataProvider mIntentDataProvider;
private final @ActivityType int mActivityType;
private final IntentIgnoringCriterion mIntentIgnoringCriterion;
public BaseCustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider,
IntentIgnoringCriterion intentIgnoringCriterion) {
mIntentDataProvider = intentDataProvider;
mActivityType = intentDataProvider.getActivityType();
mIntentIgnoringCriterion = intentIgnoringCriterion;
}
......@@ -43,8 +46,8 @@ public class BaseCustomTabActivityModule {
public CustomTabIntentHandlingStrategy provideIntentHandler(
Lazy<DefaultCustomTabIntentHandlingStrategy> defaultHandler,
Lazy<TwaIntentHandlingStrategy> twaHandler) {
return (mIntentDataProvider.isTrustedWebActivity()
|| mIntentDataProvider.isWebApkActivity())
return (mActivityType == ActivityType.TRUSTED_WEB_ACTIVITY
|| mActivityType == ActivityType.WEB_APK)
? twaHandler.get()
: defaultHandler.get();
}
......@@ -52,10 +55,10 @@ public class BaseCustomTabActivityModule {
@Provides
public Verifier provideVerifier(Lazy<WebApkVerifier> webApkVerifier,
Lazy<AddToHomescreenVerifier> addToHomescreenVerifier, Lazy<TwaVerifier> twaVerifier) {
if (mIntentDataProvider.isWebApkActivity()) {
if (mActivityType == ActivityType.WEB_APK) {
return webApkVerifier.get();
}
if (mIntentDataProvider.isWebappOrWebApkActivity()) {
if (mActivityType == ActivityType.WEBAPP) {
return addToHomescreenVerifier.get();
}
return twaVerifier.get();
......
......@@ -4,48 +4,9 @@
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
* UI-less Chrome.
*/
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;
import org.chromium.chrome.browser.ChromeActivity;
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;
......@@ -18,8 +20,8 @@ import dagger.Lazy;
* Add methods here if other components need to communicate with the WebAPK activity component.
*/
@ActivityScope
public class WebApkActivityCoordinator {
private final WebApkActivity mActivity;
public class WebApkActivityCoordinator implements Destroyable {
private final WebappActivity mActivity;
private final Lazy<WebApkUpdateManager> mWebApkUpdateManager;
@Inject
......@@ -27,12 +29,13 @@ public class WebApkActivityCoordinator {
WebappDeferredStartupWithStorageHandler deferredStartupWithStorageHandler,
WebappDisclosureSnackbarController disclosureSnackbarController,
WebApkActivityLifecycleUmaTracker webApkActivityLifecycleUmaTracker,
ActivityLifecycleDispatcher lifecycleDispatcher,
Lazy<WebApkUpdateManager> webApkUpdateManager) {
// We don't need to do anything with |disclosureSnackbarController| and
// |webApkActivityLifecycleUmaTracker|. We just need to resolve
// them so that they start working.
mActivity = (WebApkActivity) activity;
mActivity = (WebappActivity) activity;
mWebApkUpdateManager = webApkUpdateManager;
deferredStartupWithStorageHandler.addTask((storage, didCreateStorage) -> {
......@@ -40,6 +43,7 @@ public class WebApkActivityCoordinator {
onDeferredStartupWithStorage(storage, didCreateStorage);
});
lifecycleDispatcher.register(this);
}
public void onDeferredStartupWithStorage(
......@@ -50,4 +54,11 @@ public class WebApkActivityCoordinator {
WebApkInfo info = (WebApkInfo) mActivity.getWebappInfo();
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 {
}
}
public static WebApkInfo createEmpty() {
return create(createEmptyIntentDataProvider());
}
/**
* Constructs a WebApkInfo from the passed in Intent and <meta-data> in the WebAPK's Android
* manifest.
......
......@@ -21,6 +21,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ActivityState;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.PostTask;
......@@ -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.dependency_injection.ChromeActivityCommonsModule;
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.TabBrowserControlsConstraintsHelper;
import org.chromium.chrome.browser.tab.TabDelegateFactory;
......@@ -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.ScreenOrientationProvider;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.webapk.lib.common.WebApkConstants;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
......@@ -152,12 +153,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
}
}
@Override
@ActivityType
public int getActivityType() {
return ActivityType.WEBAPP;
}
protected boolean loadUrlIfPostShareTarget(WebappInfo webappInfo) {
return false;
}
......@@ -167,7 +162,24 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
}
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
......
......@@ -18,14 +18,11 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
public class WebappInfo {
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() {
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;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.components.browser_ui.widget.TintedDrawable;
/**
......@@ -28,6 +29,7 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
private final ShareData mShareData;
private final @NonNull WebappExtras mWebappExtras;
private final @Nullable WebApkExtras mWebApkExtras;
private final @ActivityType int mActivityType;
private final Intent mIntent;
/**
......@@ -46,9 +48,15 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
mShareData = shareData;
mWebappExtras = webappExtras;
mWebApkExtras = webApkExtras;
mActivityType = (webApkExtras != null) ? ActivityType.WEB_APK : ActivityType.WEBAPP;
mIntent = new Intent();
}
@Override
public @ActivityType int getActivityType() {
return mActivityType;
}
@Override
@Nullable
public Intent getIntent() {
......@@ -81,16 +89,6 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
return CustomTabsIntent.SHOW_PAGE_TITLE;
}
@Override
public boolean isWebappOrWebApkActivity() {
return true;
}
@Override
public boolean isWebApkActivity() {
return mWebApkExtras != null;
}
@Override
@Nullable
public ShareData getShareData() {
......
......@@ -32,6 +32,7 @@ import org.chromium.base.metrics.test.DisableHistogramsRule;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController;
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.webapps.WebappExtras;
import org.chromium.content_public.browser.NavigationController;
......@@ -78,7 +79,9 @@ public class CloseButtonNavigatorTest {
mWebappExtras = null;
}
doReturn(mWebappExtras).when(mIntentDataProvider).getWebappExtras();
doReturn(mIsWebapp).when(mIntentDataProvider).isWebappOrWebApkActivity();
doReturn(mIsWebapp ? ActivityType.WEBAPP : ActivityType.CUSTOM_TAB)
.when(mIntentDataProvider)
.getActivityType();
mCloseButtonNavigator =
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