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

[Refactor Android WebAPK] Make WebAPKs use TwaSharingController

This CL makes WebAPKs use TwaSharingController as part of merging the
WebAPK and TWA codebases.

BUG=1059580

Change-Id: I32db42b90854937318b06ed2a295078659ae7bd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100817
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@{#755112}
parent 9369fdcc
...@@ -30,20 +30,25 @@ public class TwaIntentHandlingStrategy implements CustomTabIntentHandlingStrateg ...@@ -30,20 +30,25 @@ public class TwaIntentHandlingStrategy implements CustomTabIntentHandlingStrateg
@Override @Override
public void handleInitialIntent(BrowserServicesIntentDataProvider intentDataProvider) { public void handleInitialIntent(BrowserServicesIntentDataProvider intentDataProvider) {
handleIntent(intentDataProvider); handleIntent(intentDataProvider, true /* isInitialIntent */);
} }
@Override @Override
public void handleNewIntent(BrowserServicesIntentDataProvider intentDataProvider) { public void handleNewIntent(BrowserServicesIntentDataProvider intentDataProvider) {
// TODO(pshmakov): we can have a significant delay here in case of POST sharing. // TODO(pshmakov): we can have a significant delay here in case of POST sharing.
// Allow showing splash screen, if it's provided in the intent. // Allow showing splash screen, if it's provided in the intent.
handleIntent(intentDataProvider); handleIntent(intentDataProvider, false /* isInitialIntent */);
} }
private void handleIntent(BrowserServicesIntentDataProvider intentDataProvider) { private void handleIntent(
BrowserServicesIntentDataProvider intentDataProvider, boolean isInitialIntent) {
mSharingController.deliverToShareTarget(intentDataProvider).then((delivered) -> { mSharingController.deliverToShareTarget(intentDataProvider).then((delivered) -> {
if (!delivered) { if (delivered) return;
if (isInitialIntent) {
mDefaultStrategy.handleInitialIntent(intentDataProvider); mDefaultStrategy.handleInitialIntent(intentDataProvider);
} else {
mDefaultStrategy.handleNewIntent(intentDataProvider);
} }
}); });
} }
......
...@@ -8,6 +8,7 @@ import android.net.Uri; ...@@ -8,6 +8,7 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.Nullable;
import androidx.browser.trusted.sharing.ShareData; import androidx.browser.trusted.sharing.ShareData;
import androidx.browser.trusted.sharing.ShareTarget; import androidx.browser.trusted.sharing.ShareTarget;
...@@ -16,11 +17,12 @@ import org.chromium.base.Promise; ...@@ -16,11 +17,12 @@ import org.chromium.base.Promise;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.TrustedWebActivityUmaRecorder; import org.chromium.chrome.browser.browserservices.TrustedWebActivityUmaRecorder;
import org.chromium.chrome.browser.browserservices.TrustedWebActivityUmaRecorder.ShareRequestMethod; import org.chromium.chrome.browser.browserservices.TrustedWebActivityUmaRecorder.ShareRequestMethod;
import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.TwaVerifier; import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.Verifier;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebApkExtras;
import org.chromium.chrome.browser.webapps.WebApkInfo; import org.chromium.chrome.browser.webapps.WebApkInfo;
import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator; import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator;
...@@ -37,14 +39,13 @@ public class TwaSharingController { ...@@ -37,14 +39,13 @@ public class TwaSharingController {
private final CustomTabActivityTabProvider mTabProvider; private final CustomTabActivityTabProvider mTabProvider;
private final CustomTabActivityNavigationController mNavigationController; private final CustomTabActivityNavigationController mNavigationController;
private final WebApkPostShareTargetNavigator mPostNavigator; private final WebApkPostShareTargetNavigator mPostNavigator;
private final TwaVerifier mVerifierDelegate; private final Verifier mVerifierDelegate;
private final TrustedWebActivityUmaRecorder mUmaRecorder; private final TrustedWebActivityUmaRecorder mUmaRecorder;
@Inject @Inject
public TwaSharingController(CustomTabActivityTabProvider tabProvider, public TwaSharingController(CustomTabActivityTabProvider tabProvider,
CustomTabActivityNavigationController navigationController, CustomTabActivityNavigationController navigationController,
WebApkPostShareTargetNavigator postNavigator, WebApkPostShareTargetNavigator postNavigator, Verifier verifierDelegate,
TwaVerifier verifierDelegate,
TrustedWebActivityUmaRecorder umaRecorder) { TrustedWebActivityUmaRecorder umaRecorder) {
mTabProvider = tabProvider; mTabProvider = tabProvider;
mNavigationController = navigationController; mNavigationController = navigationController;
...@@ -63,19 +64,21 @@ public class TwaSharingController { ...@@ -63,19 +64,21 @@ public class TwaSharingController {
public Promise<Boolean> deliverToShareTarget( public Promise<Boolean> deliverToShareTarget(
BrowserServicesIntentDataProvider intentDataProvider) { BrowserServicesIntentDataProvider intentDataProvider) {
ShareData shareData = intentDataProvider.getShareData(); ShareData shareData = intentDataProvider.getShareData();
ShareTarget shareTarget = intentDataProvider.getShareTarget(); WebApkExtras webApkExtras = intentDataProvider.getWebApkExtras();
WebApkInfo.ShareTarget shareTarget = (webApkExtras != null)
? webApkExtras.shareTarget
: toShareTargetInternal(intentDataProvider.getShareTarget());
if (shareTarget == null || shareData == null) { if (shareTarget == null || shareData == null) {
return Promise.fulfilled(false); return Promise.fulfilled(false);
} }
return mVerifierDelegate.verify(shareTarget.action) return mVerifierDelegate.verify(shareTarget.getAction())
.then((Function<Boolean, Boolean>) (verified) -> { .then((Function<Boolean, Boolean>) (verified) -> {
if (!verified) { if (!verified) {
return false; return false;
} }
WebApkInfo.ShareTarget target = toShareTargetInternal(shareTarget); if (shareTarget.isShareMethodPost()) {
if (target.isShareMethodPost()) { boolean success = sendPost(shareData, shareTarget);
boolean success = sendPost(shareData, target);
if (success) { if (success) {
mUmaRecorder.recordShareTargetRequest(ShareRequestMethod.POST); mUmaRecorder.recordShareTargetRequest(ShareRequestMethod.POST);
} }
...@@ -83,7 +86,7 @@ public class TwaSharingController { ...@@ -83,7 +86,7 @@ public class TwaSharingController {
} }
mNavigationController.navigate( mNavigationController.navigate(
computeStartUrlForGETShareTarget(shareData, target)); computeStartUrlForGETShareTarget(shareData, shareTarget));
mUmaRecorder.recordShareTargetRequest(ShareRequestMethod.GET); mUmaRecorder.recordShareTargetRequest(ShareRequestMethod.GET);
return true; return true;
}); });
...@@ -94,7 +97,9 @@ public class TwaSharingController { ...@@ -94,7 +97,9 @@ public class TwaSharingController {
* TODO(pshmakov): pull WebApkInfo.ShareTarget out of WebApkInfo and rename to * TODO(pshmakov): pull WebApkInfo.ShareTarget out of WebApkInfo and rename to
* ShareTargetInternal. Also, replace WebApkInfo.ShareData with ShareData from TWA API. * ShareTargetInternal. Also, replace WebApkInfo.ShareData with ShareData from TWA API.
*/ */
private WebApkInfo.ShareTarget toShareTargetInternal(ShareTarget shareTarget) { private WebApkInfo.ShareTarget toShareTargetInternal(@Nullable ShareTarget shareTarget) {
if (shareTarget == null) return null;
ShareTarget.Params params = shareTarget.params; ShareTarget.Params params = shareTarget.params;
String action = shareTarget.action; String action = shareTarget.action;
String paramTitle = params.title; String paramTitle = params.title;
...@@ -132,7 +137,6 @@ public class TwaSharingController { ...@@ -132,7 +137,6 @@ public class TwaSharingController {
// Since the latter is in the WebAPK client code, we can't reuse it. // Since the latter is in the WebAPK client code, we can't reuse it.
private static String computeStartUrlForGETShareTarget( private static String computeStartUrlForGETShareTarget(
ShareData data, WebApkInfo.ShareTarget target) { ShareData data, WebApkInfo.ShareTarget target) {
// These can be null, they are checked downstream. // These can be null, they are checked downstream.
ArrayList<Pair<String, String>> entryList = new ArrayList<>(); ArrayList<Pair<String, String>> entryList = new ArrayList<>();
entryList.add(new Pair<>(target.getParamTitle(), data.title)); entryList.add(new Pair<>(target.getParamTitle(), data.title));
......
...@@ -20,6 +20,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv ...@@ -20,6 +20,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabFactory; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabFactory;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler;
import org.chromium.chrome.browser.customtabs.content.TabCreationMode; import org.chromium.chrome.browser.customtabs.content.TabCreationMode;
import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityComponent; import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityComponent;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarColorController; import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarColorController;
...@@ -47,6 +48,7 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo ...@@ -47,6 +48,7 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo
protected CustomTabToolbarColorController mToolbarColorController; protected CustomTabToolbarColorController mToolbarColorController;
protected CustomTabStatusBarColorProvider mStatusBarColorProvider; protected CustomTabStatusBarColorProvider mStatusBarColorProvider;
protected CustomTabActivityTabFactory mTabFactory; protected CustomTabActivityTabFactory mTabFactory;
protected CustomTabIntentHandler mCustomTabIntentHandler;
protected @Nullable WebappActivityCoordinator mWebappActivityCoordinator; protected @Nullable WebappActivityCoordinator mWebappActivityCoordinator;
// This is to give the right package name while using the client's resources during an // This is to give the right package name while using the client's resources during an
...@@ -77,6 +79,7 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo ...@@ -77,6 +79,7 @@ public abstract class BaseCustomTabActivity<C extends BaseCustomTabActivityCompo
mToolbarColorController = component.resolveToolbarColorController(); mToolbarColorController = component.resolveToolbarColorController();
mStatusBarColorProvider = component.resolveCustomTabStatusBarColorProvider(); mStatusBarColorProvider = component.resolveCustomTabStatusBarColorProvider();
mTabFactory = component.resolveTabFactory(); mTabFactory = component.resolveTabFactory();
mCustomTabIntentHandler = component.resolveIntentHandler();
component.resolveCompositorContentInitializer(); component.resolveCompositorContentInitializer();
component.resolveTaskDescriptionHelper(); component.resolveTaskDescriptionHelper();
......
...@@ -37,7 +37,6 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv ...@@ -37,7 +37,6 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider.CustomTabsUiType; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider.CustomTabsUiType;
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.customtabs.content.CustomTabIntentHandler;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler.IntentIgnoringCriterion; import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler.IntentIgnoringCriterion;
import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityModule; import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityModule;
import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityComponent; import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityComponent;
...@@ -68,7 +67,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo ...@@ -68,7 +67,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo
private CustomTabIntentDataProvider mIntentDataProvider; private CustomTabIntentDataProvider mIntentDataProvider;
private CustomTabsSessionToken mSession; private CustomTabsSessionToken mSession;
private CustomTabActivityTabController mTabController; private CustomTabActivityTabController mTabController;
private CustomTabIntentHandler mCustomTabIntentHandler;
private final CustomTabsConnection mConnection = CustomTabsConnection.getInstance(); private final CustomTabsConnection mConnection = CustomTabsConnection.getInstance();
...@@ -362,9 +360,10 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo ...@@ -362,9 +360,10 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo
(intent) -> mIntentHandler.shouldIgnoreIntent(intent); (intent) -> mIntentHandler.shouldIgnoreIntent(intent);
BaseCustomTabActivityModule baseCustomTabsModule = BaseCustomTabActivityModule baseCustomTabsModule =
new BaseCustomTabActivityModule(mIntentDataProvider); new BaseCustomTabActivityModule(mIntentDataProvider, intentIgnoringCriterion);
CustomTabActivityModule customTabsModule = new CustomTabActivityModule(mIntentDataProvider, CustomTabActivityModule customTabsModule =
mNightModeStateController, intentIgnoringCriterion, getStartupTabPreloader()); new CustomTabActivityModule(mNightModeStateController, getStartupTabPreloader());
CustomTabActivityComponent component = CustomTabActivityComponent component =
ChromeApplication.getComponent().createCustomTabActivityComponent( ChromeApplication.getComponent().createCustomTabActivityComponent(
commonsModule, baseCustomTabsModule, customTabsModule); commonsModule, baseCustomTabsModule, customTabsModule);
...@@ -379,7 +378,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo ...@@ -379,7 +378,6 @@ public class CustomTabActivity extends BaseCustomTabActivity<CustomTabActivityCo
if (reason == USER_NAVIGATION) connectionKeeper.recordClientConnectionStatus(); if (reason == USER_NAVIGATION) connectionKeeper.recordClientConnectionStatus();
handleFinishAndClose(); handleFinishAndClose();
}); });
mCustomTabIntentHandler = component.resolveIntentHandler();
component.resolveSessionHandler(); component.resolveSessionHandler();
component.resolveCustomTabIncognitoManager(); component.resolveCustomTabIncognitoManager();
......
...@@ -159,29 +159,31 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ ...@@ -159,29 +159,31 @@ public class CustomTabActivityNavigationController implements StartStopWithNativ
* (see {@link CustomTabObserver}). * (see {@link CustomTabObserver}).
*/ */
public void navigate(final LoadUrlParams params, long timeStamp) { public void navigate(final LoadUrlParams params, long timeStamp) {
assert mIntentDataProvider.getWebappExtras() == null;
Tab tab = mTabProvider.getTab(); Tab tab = mTabProvider.getTab();
if (tab == null) { if (tab == null) {
assert false; assert false;
return; return;
} }
mCustomTabObserver.get().trackNextPageLoadFromTimestamp(tab, timeStamp); // TODO(pkotwicz): Figure out whether we want to record these metrics for WebAPKs.
if (mIntentDataProvider.getWebappExtras() == null) {
mCustomTabObserver.get().trackNextPageLoadFromTimestamp(tab, timeStamp);
}
IntentHandler.addReferrerAndHeaders(params, mIntentDataProvider.getIntent()); IntentHandler.addReferrerAndHeaders(params, mIntentDataProvider.getIntent());
if (params.getReferrer() == null) { if (params.getReferrer() == null) {
params.setReferrer(mConnection.getReferrerForSession(mIntentDataProvider.getSession())); params.setReferrer(mConnection.getReferrerForSession(mIntentDataProvider.getSession()));
} }
// Launching a TWA would count as a TOPLEVEL transition since it opens up an app-like // Launching a TWA, WebAPK or a standalone-mode homescreen shortcut counts as a TOPLEVEL
// experience, and should count towards site engagement scores. This matches WebAPK // transition since it opens up an app-like experience, and should count towards site
// behaviour. CCTs on the other hand still count as LINK transitions. // engagement scores. CCTs on the other hand still count as LINK transitions.
int transition; int transition;
if (mIntentDataProvider.isTrustedWebActivity()) { if (mIntentDataProvider.isTrustedWebActivity()
transition = PageTransition.AUTO_TOPLEVEL | PageTransition.FROM_API; || mIntentDataProvider.isWebappOrWebApkActivity()) {
transition = PageTransition.AUTO_TOPLEVEL | PageTransition.FROM_API;
} else { } else {
transition = PageTransition.LINK | PageTransition.FROM_API; transition = PageTransition.LINK | PageTransition.FROM_API;
} }
params.setTransitionType(IntentHandler.getTransitionTypeFromIntent( params.setTransitionType(IntentHandler.getTransitionTypeFromIntent(
......
...@@ -16,6 +16,7 @@ import androidx.browser.customtabs.CustomTabsSessionToken; ...@@ -16,6 +16,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.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.net.NetworkChangeNotifier;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -72,6 +73,10 @@ public class CustomTabIntentHandler { ...@@ -72,6 +73,10 @@ 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()
&& !mIntentDataProvider.isWebApkActivity()
&& NetworkChangeNotifier.isOnline()) {
mTabProvider.getTab().reloadIgnoringCache();
} }
}); });
} }
...@@ -86,7 +91,8 @@ public class CustomTabIntentHandler { ...@@ -86,7 +91,8 @@ public class CustomTabIntentHandler {
public boolean onNewIntent(BrowserServicesIntentDataProvider intentDataProvider) { public boolean onNewIntent(BrowserServicesIntentDataProvider intentDataProvider) {
Intent intent = intentDataProvider.getIntent(); Intent intent = intentDataProvider.getIntent();
CustomTabsSessionToken session = intentDataProvider.getSession(); CustomTabsSessionToken session = intentDataProvider.getSession();
if (session == null || !session.equals(mIntentDataProvider.getSession())) { if (!intentDataProvider.isWebappOrWebApkActivity()
&& (session == null || !session.equals(mIntentDataProvider.getSession()))) {
assert false : "New intent delivered into a Custom Tab with a different session"; assert false : "New intent delivered into a Custom Tab with a different session";
int flagsToRemove = Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP; int flagsToRemove = Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.setFlags((intent.getFlags() & ~flagsToRemove) | Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags((intent.getFlags() & ~flagsToRemove) | Intent.FLAG_ACTIVITY_NEW_TASK);
......
...@@ -91,6 +91,15 @@ public class DefaultCustomTabIntentHandlingStrategy implements CustomTabIntentHa ...@@ -91,6 +91,15 @@ public class DefaultCustomTabIntentHandlingStrategy implements CustomTabIntentHa
String url = intentDataProvider.getUrlToLoad(); String url = intentDataProvider.getUrlToLoad();
if (TextUtils.isEmpty(url)) return; if (TextUtils.isEmpty(url)) return;
LoadUrlParams params = new LoadUrlParams(url); LoadUrlParams params = new LoadUrlParams(url);
if (intentDataProvider.isWebApkActivity()) {
// The back stack should be cleared when a WebAPK receives a deep link intent. This is
// unnecessary for Trusted Web Activities and new-style WebAPKs because Trusted Web
// Activities and new-style WebAPKs are restarted when they receive an intent from a
// deep link.
params.setShouldClearHistoryList(true);
}
mNavigationController.navigate(params, getTimestamp(intentDataProvider)); mNavigationController.navigate(params, getTimestamp(intentDataProvider));
} }
......
...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.customtabs.CustomTabTaskDescriptionHelper; ...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.customtabs.CustomTabTaskDescriptionHelper;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabFactory; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabFactory;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabProvider;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler;
import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar; import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarColorController; import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarColorController;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarCoordinator; import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarCoordinator;
...@@ -32,6 +33,7 @@ public interface BaseCustomTabActivityComponent extends ChromeActivityComponent ...@@ -32,6 +33,7 @@ public interface BaseCustomTabActivityComponent extends ChromeActivityComponent
CustomTabActivityTabProvider resolveTabProvider(); CustomTabActivityTabProvider resolveTabProvider();
CustomTabCompositorContentInitializer resolveCompositorContentInitializer(); CustomTabCompositorContentInitializer resolveCompositorContentInitializer();
CustomTabDelegateFactory resolveTabDelegateFactory(); CustomTabDelegateFactory resolveTabDelegateFactory();
CustomTabIntentHandler resolveIntentHandler();
CustomTabStatusBarColorProvider resolveCustomTabStatusBarColorProvider(); CustomTabStatusBarColorProvider resolveCustomTabStatusBarColorProvider();
CustomTabToolbarColorController resolveToolbarColorController(); CustomTabToolbarColorController resolveToolbarColorController();
CustomTabTaskDescriptionHelper resolveTaskDescriptionHelper(); CustomTabTaskDescriptionHelper resolveTaskDescriptionHelper();
......
...@@ -5,14 +5,20 @@ ...@@ -5,14 +5,20 @@
package org.chromium.chrome.browser.customtabs.dependency_injection; package org.chromium.chrome.browser.customtabs.dependency_injection;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider; import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.trustedwebactivityui.TwaIntentHandlingStrategy;
import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.TwaVerifier; import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.TwaVerifier;
import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.Verifier; import org.chromium.chrome.browser.browserservices.trustedwebactivityui.controller.Verifier;
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.webapps.AddToHomescreenVerifier; import org.chromium.chrome.browser.webapps.AddToHomescreenVerifier;
import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator;
import org.chromium.chrome.browser.webapps.WebApkVerifier; import org.chromium.chrome.browser.webapps.WebApkVerifier;
import dagger.Lazy; import dagger.Lazy;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.Reusable;
/** /**
* Module for bindings shared between custom tabs and webapps. * Module for bindings shared between custom tabs and webapps.
...@@ -20,9 +26,12 @@ import dagger.Provides; ...@@ -20,9 +26,12 @@ import dagger.Provides;
@Module @Module
public class BaseCustomTabActivityModule { public class BaseCustomTabActivityModule {
private final BrowserServicesIntentDataProvider mIntentDataProvider; private final BrowserServicesIntentDataProvider mIntentDataProvider;
private final IntentIgnoringCriterion mIntentIgnoringCriterion;
public BaseCustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider) { public BaseCustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider,
IntentIgnoringCriterion intentIgnoringCriterion) {
mIntentDataProvider = intentDataProvider; mIntentDataProvider = intentDataProvider;
mIntentIgnoringCriterion = intentIgnoringCriterion;
} }
@Provides @Provides
...@@ -30,6 +39,16 @@ public class BaseCustomTabActivityModule { ...@@ -30,6 +39,16 @@ public class BaseCustomTabActivityModule {
return mIntentDataProvider; return mIntentDataProvider;
} }
@Provides
public CustomTabIntentHandlingStrategy provideIntentHandler(
Lazy<DefaultCustomTabIntentHandlingStrategy> defaultHandler,
Lazy<TwaIntentHandlingStrategy> twaHandler) {
return (mIntentDataProvider.isTrustedWebActivity()
|| mIntentDataProvider.isWebApkActivity())
? twaHandler.get()
: defaultHandler.get();
}
@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) {
...@@ -41,4 +60,15 @@ public class BaseCustomTabActivityModule { ...@@ -41,4 +60,15 @@ public class BaseCustomTabActivityModule {
} }
return twaVerifier.get(); return twaVerifier.get();
} }
@Provides
public IntentIgnoringCriterion provideIntentIgnoringCriterion() {
return mIntentIgnoringCriterion;
}
@Provides
@Reusable
public WebApkPostShareTargetNavigator providePostShareTargetNavigator() {
return new WebApkPostShareTargetNavigator();
}
} }
...@@ -14,7 +14,6 @@ import org.chromium.chrome.browser.customtabs.CustomTabTabPersistencePolicy; ...@@ -14,7 +14,6 @@ import org.chromium.chrome.browser.customtabs.CustomTabTabPersistencePolicy;
import org.chromium.chrome.browser.customtabs.CustomTabUmaRecorder; import org.chromium.chrome.browser.customtabs.CustomTabUmaRecorder;
import org.chromium.chrome.browser.customtabs.ReparentingTaskProvider; import org.chromium.chrome.browser.customtabs.ReparentingTaskProvider;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler;
import org.chromium.chrome.browser.customtabs.features.ImmersiveModeController; import org.chromium.chrome.browser.customtabs.features.ImmersiveModeController;
import org.chromium.chrome.browser.dependency_injection.ActivityScope; import org.chromium.chrome.browser.dependency_injection.ActivityScope;
import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule; import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule;
...@@ -34,7 +33,6 @@ public interface CustomTabActivityComponent extends BaseCustomTabActivityCompone ...@@ -34,7 +33,6 @@ public interface CustomTabActivityComponent extends BaseCustomTabActivityCompone
CustomTabBottomBarDelegate resolveBottomBarDelegate(); CustomTabBottomBarDelegate resolveBottomBarDelegate();
CustomTabActivityTabController resolveTabController(); CustomTabActivityTabController resolveTabController();
CustomTabActivityLifecycleUmaTracker resolveUmaTracker(); CustomTabActivityLifecycleUmaTracker resolveUmaTracker();
CustomTabIntentHandler resolveIntentHandler();
CustomTabIncognitoManager resolveCustomTabIncognitoManager(); CustomTabIncognitoManager resolveCustomTabIncognitoManager();
CustomTabUmaRecorder resolveCustomTabUmaRecorder(); CustomTabUmaRecorder resolveCustomTabUmaRecorder();
CustomTabSessionHandler resolveSessionHandler(); CustomTabSessionHandler resolveSessionHandler();
......
...@@ -5,39 +5,25 @@ ...@@ -5,39 +5,25 @@
package org.chromium.chrome.browser.customtabs.dependency_injection; package org.chromium.chrome.browser.customtabs.dependency_injection;
import org.chromium.chrome.browser.browserservices.BrowserServicesActivityTabController; import org.chromium.chrome.browser.browserservices.BrowserServicesActivityTabController;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.ClientAppDataRegister; import org.chromium.chrome.browser.browserservices.ClientAppDataRegister;
import org.chromium.chrome.browser.browserservices.trustedwebactivityui.TwaIntentHandlingStrategy;
import org.chromium.chrome.browser.customtabs.CustomTabNightModeStateController; import org.chromium.chrome.browser.customtabs.CustomTabNightModeStateController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController; import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController;
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.init.StartupTabPreloader; import org.chromium.chrome.browser.init.StartupTabPreloader;
import org.chromium.chrome.browser.webapps.WebApkPostShareTargetNavigator;
import dagger.Lazy;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.Reusable;
/** /**
* Module for custom tab specific bindings. * Module for custom tab specific bindings.
*/ */
@Module @Module
public class CustomTabActivityModule { public class CustomTabActivityModule {
private final BrowserServicesIntentDataProvider mIntentDataProvider;
private final CustomTabNightModeStateController mNightModeController; private final CustomTabNightModeStateController mNightModeController;
private final IntentIgnoringCriterion mIntentIgnoringCriterion;
private final StartupTabPreloader mStartupTabPreloader; private final StartupTabPreloader mStartupTabPreloader;
public CustomTabActivityModule(BrowserServicesIntentDataProvider intentDataProvider, public CustomTabActivityModule(CustomTabNightModeStateController nightModeController,
CustomTabNightModeStateController nightModeController,
IntentIgnoringCriterion intentIgnoringCriterion,
StartupTabPreloader startupTabPreloader) { StartupTabPreloader startupTabPreloader) {
mIntentDataProvider = intentDataProvider;
mNightModeController = nightModeController; mNightModeController = nightModeController;
mIntentIgnoringCriterion = intentIgnoringCriterion;
mStartupTabPreloader = startupTabPreloader; mStartupTabPreloader = startupTabPreloader;
} }
...@@ -57,24 +43,6 @@ public class CustomTabActivityModule { ...@@ -57,24 +43,6 @@ public class CustomTabActivityModule {
return mNightModeController; return mNightModeController;
} }
@Provides
public CustomTabIntentHandlingStrategy provideIntentHandler(
Lazy<DefaultCustomTabIntentHandlingStrategy> defaultHandler,
Lazy<TwaIntentHandlingStrategy> twaHandler) {
return mIntentDataProvider.isTrustedWebActivity() ? twaHandler.get() : defaultHandler.get();
}
@Provides
public IntentIgnoringCriterion provideIntentIgnoringCriterion() {
return mIntentIgnoringCriterion;
}
@Provides
@Reusable
public WebApkPostShareTargetNavigator providePostShareTargetNavigator() {
return new WebApkPostShareTargetNavigator();
}
@Provides @Provides
public StartupTabPreloader provideStartupTabPreloader() { public StartupTabPreloader provideStartupTabPreloader() {
return mStartupTabPreloader; return mStartupTabPreloader;
......
...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.webapps; ...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.webapps;
import android.content.Intent; import android.content.Intent;
import androidx.browser.trusted.sharing.ShareData;
import org.chromium.base.IntentUtils; import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.flags.ActivityType; import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
...@@ -45,18 +43,6 @@ public class WebApkActivity extends WebappActivity { ...@@ -45,18 +43,6 @@ public class WebApkActivity extends WebappActivity {
super.onDestroyInternal(); super.onDestroyInternal();
} }
@Override
protected boolean loadUrlIfPostShareTarget(WebappInfo webappInfo) {
WebApkInfo webApkInfo = (WebApkInfo) webappInfo;
ShareData shareData = webApkInfo.shareData();
if (shareData == null) {
return false;
}
return new WebApkPostShareTargetNavigator().navigateIfPostShareTarget(
webApkInfo.url(), webApkInfo.shareTarget(), shareData,
getActivityTab().getWebContents());
}
@Override @Override
@ActivityType @ActivityType
public int getActivityType() { public int getActivityType() {
......
...@@ -12,7 +12,6 @@ import android.graphics.PixelFormat; ...@@ -12,7 +12,6 @@ import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -34,6 +33,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv ...@@ -34,6 +33,7 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.customtabs.BaseCustomTabActivity; import org.chromium.chrome.browser.customtabs.BaseCustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabAppMenuPropertiesDelegate; import org.chromium.chrome.browser.customtabs.CustomTabAppMenuPropertiesDelegate;
import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory; import org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory;
import org.chromium.chrome.browser.customtabs.content.CustomTabIntentHandler.IntentIgnoringCriterion;
import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar; import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar;
import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar.CustomTabTabObserver; import org.chromium.chrome.browser.customtabs.content.TabObserverRegistrar.CustomTabTabObserver;
import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityModule; import org.chromium.chrome.browser.customtabs.dependency_injection.BaseCustomTabActivityModule;
...@@ -50,12 +50,9 @@ import org.chromium.chrome.browser.util.AndroidTaskUtils; ...@@ -50,12 +50,9 @@ import org.chromium.chrome.browser.util.AndroidTaskUtils;
import org.chromium.chrome.browser.webapps.dependency_injection.WebappActivityComponent; import org.chromium.chrome.browser.webapps.dependency_injection.WebappActivityComponent;
import org.chromium.chrome.browser.webapps.dependency_injection.WebappActivityModule; import org.chromium.chrome.browser.webapps.dependency_injection.WebappActivityModule;
import org.chromium.components.embedder_support.delegate.WebContentsDelegateAndroid; import org.chromium.components.embedder_support.delegate.WebContentsDelegateAndroid;
import org.chromium.content_public.browser.LoadUrlParams;
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.net.NetworkChangeNotifier;
import org.chromium.ui.base.PageTransition;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -151,7 +148,7 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -151,7 +148,7 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
Log.e(TAG, "Failed to parse new Intent: " + intent); Log.e(TAG, "Failed to parse new Intent: " + intent);
ApiCompatibilityUtils.finishAndRemoveTask(this); ApiCompatibilityUtils.finishAndRemoveTask(this);
} else if (newWebappInfo.shouldForceNavigation() && mIsInitialized) { } else if (newWebappInfo.shouldForceNavigation() && mIsInitialized) {
loadUrl(newWebappInfo, getActivityTab()); mCustomTabIntentHandler.onNewIntent(newWebappInfo.getProvider());
} }
} }
...@@ -165,16 +162,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -165,16 +162,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
return false; return false;
} }
protected void loadUrl(WebappInfo webappInfo, Tab tab) {
if (loadUrlIfPostShareTarget(webappInfo)) {
// Web Share Target Post was successful, so don't load anything.
return;
}
LoadUrlParams params = new LoadUrlParams(webappInfo.url(), PageTransition.AUTO_TOPLEVEL);
params.setShouldClearHistoryList(true);
tab.loadUrl(params);
}
protected boolean isInitialized() { protected boolean isInitialized() {
return mIsInitialized; return mIsInitialized;
} }
...@@ -188,7 +175,7 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -188,7 +175,7 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
super.initializeState(); super.initializeState();
mTabController.initializeState(); mTabController.initializeState();
initializeUI(getSavedInstanceState()); mTabObserverRegistrar.registerActivityTabObserver(createTabObserver());
} }
@VisibleForTesting @VisibleForTesting
...@@ -249,22 +236,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -249,22 +236,6 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
onInitialLayoutInflationComplete(); onInitialLayoutInflationComplete();
} }
protected void initializeUI(Bundle savedInstanceState) {
Tab tab = getActivityTab();
// We do not load URL when restoring from saved instance states. However, it's possible that
// we saved instance state before loading a URL, so even after restoring from
// SavedInstanceState we might not have a URL and should initialize from the intent.
if (tab.getUrlString().isEmpty()) {
loadUrl(mWebappInfo, tab);
} else {
if (!mWebappInfo.isForWebApk() && NetworkChangeNotifier.isOnline()) {
tab.reloadIgnoringCache();
}
}
mTabObserverRegistrar.registerActivityTabObserver(createTabObserver());
}
@Override @Override
public void performPreInflationStartup() { public void performPreInflationStartup() {
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -327,9 +298,12 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen ...@@ -327,9 +298,12 @@ public class WebappActivity extends BaseCustomTabActivity<WebappActivityComponen
@Override @Override
protected WebappActivityComponent createComponent(ChromeActivityCommonsModule commonsModule) { protected WebappActivityComponent createComponent(ChromeActivityCommonsModule commonsModule) {
IntentIgnoringCriterion intentIgnoringCriterion =
(intent) -> mIntentHandler.shouldIgnoreIntent(intent);
mIntentDataProvider = mWebappInfo.getProvider(); mIntentDataProvider = mWebappInfo.getProvider();
BaseCustomTabActivityModule baseCustomTabModule = BaseCustomTabActivityModule baseCustomTabModule =
new BaseCustomTabActivityModule(mIntentDataProvider); new BaseCustomTabActivityModule(mIntentDataProvider, intentIgnoringCriterion);
WebappActivityModule webappModule = new WebappActivityModule(); WebappActivityModule webappModule = new WebappActivityModule();
WebappActivityComponent component = WebappActivityComponent component =
ChromeApplication.getComponent().createWebappActivityComponent( ChromeApplication.getComponent().createWebappActivityComponent(
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
...@@ -27,6 +28,7 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider ...@@ -27,6 +28,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 Intent mIntent;
/** /**
* Returns the toolbar color to use if a custom color is not specified by the webapp. * Returns the toolbar color to use if a custom color is not specified by the webapp.
...@@ -44,6 +46,13 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider ...@@ -44,6 +46,13 @@ public class WebappIntentDataProvider extends BrowserServicesIntentDataProvider
mShareData = shareData; mShareData = shareData;
mWebappExtras = webappExtras; mWebappExtras = webappExtras;
mWebApkExtras = webApkExtras; mWebApkExtras = webApkExtras;
mIntent = new Intent();
}
@Override
@Nullable
public Intent getIntent() {
return mIntent;
} }
@Override @Override
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes # //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect # Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk # Chrome.apk
current_shell_apk_version = 124 current_shell_apk_version = 125
...@@ -176,6 +176,9 @@ public class HostBrowserLauncherParams { ...@@ -176,6 +176,9 @@ public class HostBrowserLauncherParams {
*/ */
protected static String createGETWebShareTargetUriString( protected static String createGETWebShareTargetUriString(
String action, ArrayList<Pair<String, String>> entryList) { String action, ArrayList<Pair<String, String>> entryList) {
// Building the query string here is unnecessary if the host browser is M83+. M83+ Chrome
// builds the query string from the WebAPK's <meta-data>.
Uri.Builder queryBuilder = new Uri.Builder(); Uri.Builder queryBuilder = new Uri.Builder();
for (Pair<String, String> nameValue : entryList) { for (Pair<String, String> nameValue : entryList) {
if (!TextUtils.isEmpty(nameValue.first) && !TextUtils.isEmpty(nameValue.second)) { if (!TextUtils.isEmpty(nameValue.first) && !TextUtils.isEmpty(nameValue.second)) {
......
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