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

[Android WebAPK Refactor] Send activity name in intent only for share targets 8/X

This CL changes the WebAPK to send the name of the launching activity only for
share targets. The goal of this CL are:
- In an upcoming CL I will send an intent to Chrome to relaunch the WebAPK. This CL removes the need
  to send the action which launched the WebAPK to Chrome. (ACTION_SEND can be assumed if the
  org.chromium.webapk.selected_share_target_activity_class_name extra is set.)
- Add a layer of defense in depth for POST share targets. An incoming intent is for a POST share
  target if:
  1) org.chromium.webapk.selected_share_target_activity_class_name is set on the intent
  2) The <meta-data> for the passed in activity has a org.chromium.webapk.shell_apk.shareEnctype
     key.

BUG=817263, 885313

Change-Id: I3667d257f711f1e474a44e3fd9aaf5c41552f30c
Reviewed-on: https://chromium-review.googlesource.com/c/1307075
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604656}
parent 791f38e8
......@@ -20,8 +20,8 @@ public final class WebApkConstants {
public static final String EXTRA_SOURCE = "org.chromium.chrome.browser.webapp_source";
public static final String EXTRA_WEBAPK_PACKAGE_NAME =
"org.chromium.chrome.browser.webapk_package_name";
public static final String EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME =
"org.chromium.webapk.launching_activity_class_name";
public static final String EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME =
"org.chromium.webapk.selected_share_target_activity_class_name";
public static final String EXTRA_FORCE_NAVIGATION =
"org.chromium.chrome.browser.webapk_force_navigation";
// Activity launch time for uma tracking of Chrome web apk startup
......
......@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk
current_shell_apk_version = 70
current_shell_apk_version = 71
......@@ -147,7 +147,7 @@ public final class LaunchTest {
Intent browserLaunchIntent = launchedIntents.get(launchedIntents.size() - 1);
Assert.assertEquals(SHARE_ACTIVITY1_CLASS_NAME,
browserLaunchIntent.getStringExtra(
WebApkConstants.EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME));
WebApkConstants.EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME));
}
/**
......
......@@ -65,8 +65,8 @@ public class HostBrowserLauncher {
intent.putExtra(WebApkConstants.EXTRA_URL, params.getStartUrl())
.putExtra(WebApkConstants.EXTRA_SOURCE, params.getSource())
.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, context.getPackageName())
.putExtra(WebApkConstants.EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME,
params.getLaunchingActivityClassName())
.putExtra(WebApkConstants.EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME,
params.getSelectedShareTargetActivityClassName())
.putExtra(WebApkConstants.EXTRA_FORCE_NAVIGATION, params.getForceNavigation());
// Only pass on the start time if no user action was required between launching the webapk
......
......@@ -30,7 +30,7 @@ public class HostBrowserLauncherParams {
private int mSource;
private boolean mForceNavigation;
private long mLaunchTimeMs;
private String mLaunchingActivityClassName;
private String mSelectedShareTargetActivityClassName;
/**
* Constructs a HostBrowserLauncherParams object from the passed in Intent and from <meta-data>
......@@ -44,21 +44,21 @@ public class HostBrowserLauncherParams {
int hostBrowserMajorChromiumVersion = HostBrowserUtils.queryHostBrowserMajorChromiumVersion(
context, hostBrowserPackageName);
ComponentName launchingActivityComponent = intent.getComponent();
if (intent.getStringExtra(WebApkConstants.EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME)
!= null) {
launchingActivityComponent = new ComponentName(context.getPackageName(),
intent.getStringExtra(
WebApkConstants.EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME));
}
String startUrl = null;
int source = WebApkConstants.SHORTCUT_SOURCE_UNKNOWN;
boolean forceNavigation = false;
String selectedShareTargetActivityClassName = intent.getStringExtra(
WebApkConstants.EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME);
if (Intent.ACTION_SEND.equals(intent.getAction())
|| Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
Bundle shareTargetMetaData = fetchActivityMetaData(context, launchingActivityComponent);
selectedShareTargetActivityClassName = intent.getComponent().getClassName();
}
if (selectedShareTargetActivityClassName != null) {
Bundle shareTargetMetaData = fetchActivityMetaData(context,
new ComponentName(
context.getPackageName(), selectedShareTargetActivityClassName));
startUrl = computeStartUrlForShareTarget(shareTargetMetaData, intent);
source = WebApkConstants.SHORTCUT_SOURCE_SHARE;
forceNavigation = true;
......@@ -82,7 +82,7 @@ public class HostBrowserLauncherParams {
return new HostBrowserLauncherParams(hostBrowserPackageName,
hostBrowserMajorChromiumVersion, dialogShown, intent, startUrl, source,
forceNavigation, launchTimeMs, launchingActivityComponent.getClassName());
forceNavigation, launchTimeMs, selectedShareTargetActivityClassName);
}
private static Bundle fetchActivityMetaData(
......@@ -191,7 +191,7 @@ public class HostBrowserLauncherParams {
private HostBrowserLauncherParams(String hostBrowserPackageName,
int hostBrowserMajorChromiumVersion, boolean dialogShown, Intent originalIntent,
String startUrl, int source, boolean forceNavigation, long launchTimeMs,
String launchingActivityClassName) {
String selectedShareTargetActivityClassName) {
mHostBrowserPackageName = hostBrowserPackageName;
mHostBrowserMajorChromiumVersion = hostBrowserMajorChromiumVersion;
mDialogShown = dialogShown;
......@@ -200,7 +200,7 @@ public class HostBrowserLauncherParams {
mSource = source;
mForceNavigation = forceNavigation;
mLaunchTimeMs = launchTimeMs;
mLaunchingActivityClassName = launchingActivityClassName;
mSelectedShareTargetActivityClassName = selectedShareTargetActivityClassName;
}
/** Returns the chosen host browser. */
......@@ -249,8 +249,8 @@ public class HostBrowserLauncherParams {
return mLaunchTimeMs;
}
/** Returns the class name of the activity which received the intent.*/
public String getLaunchingActivityClassName() {
return mLaunchingActivityClassName;
/** Returns the class name of the share activity that the user selected. */
public String getSelectedShareTargetActivityClassName() {
return mSelectedShareTargetActivityClassName;
}
}
......@@ -73,11 +73,9 @@ public class H2OLauncher {
}
/** Launches the given component, passing extras from the given intent. */
public static void copyIntentExtrasAndLaunch(
Context context, Intent intentToCopy, ComponentName launchComponent) {
Intent intent = new Intent();
intent.setAction(intentToCopy.getAction());
intent.setData(intentToCopy.getData());
public static void copyIntentExtrasAndLaunch(Context context, Intent intentToCopy,
String selectedShareTargetActivity, ComponentName launchComponent) {
Intent intent = new Intent(Intent.ACTION_VIEW, intentToCopy.getData());
intent.setComponent(launchComponent);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
......@@ -85,8 +83,12 @@ public class H2OLauncher {
if (copiedExtras != null) {
intent.putExtras(copiedExtras);
}
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_LAUNCHING_ACTIVITY_CLASS_NAME,
intentToCopy.getComponent().getClassName());
// If the intent is a share, propagate which share target activity the user selected.
if (selectedShareTargetActivity != null) {
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_SELECTED_SHARE_TARGET_ACTIVITY_CLASS_NAME,
selectedShareTargetActivity);
}
context.startActivity(intent);
}
......
......@@ -36,8 +36,9 @@ public class H2OTransparentLauncherActivity extends TransparentLauncherActivity
// brings the WebAPK activity stack to the foreground and does not create a
// new activity stack.
Context appContext = getApplicationContext();
H2OLauncher.copyIntentExtrasAndLaunch(
appContext, getIntent(), new ComponentName(appContext, SplashActivity.class));
H2OLauncher.copyIntentExtrasAndLaunch(appContext, getIntent(),
params.getSelectedShareTargetActivityClassName(),
new ComponentName(appContext, SplashActivity.class));
finish();
return;
}
......@@ -70,8 +71,8 @@ public class H2OTransparentLauncherActivity extends TransparentLauncherActivity
return false;
}
H2OLauncher.copyIntentExtrasAndLaunch(
getApplicationContext(), getIntent(), relaunchComponent);
H2OLauncher.copyIntentExtrasAndLaunch(getApplicationContext(), getIntent(),
params.getSelectedShareTargetActivityClassName(), relaunchComponent);
return true;
}
}
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