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

Fix SecurityException when using v2 share with a new-style WebAPK

This CL moves the grantUriPermissionToHostBrowser() call to
TransparentLauncherActivity/H2OTransparentLauncherActivity which receive
the share intent from the sharer app (vs SplashActivity which receives a copy
of the share intent from H2OTransparentLauncherActivity)

BUG=982394

Change-Id: I37ca0f168e312e03e58158b9b858879cc5771fb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715534Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680439}
parent 8bcdeeeb
......@@ -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 = 98
current_shell_apk_version = 99
......@@ -13,8 +13,6 @@ import android.util.Log;
import org.chromium.webapk.lib.common.WebApkConstants;
import java.util.ArrayList;
/** Contains methods for launching host browser. */
public class HostBrowserLauncher {
private static final String TAG = "cr_HostBrowserLauncher";
......@@ -30,22 +28,6 @@ public class HostBrowserLauncher {
private static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB =
"REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB";
private static void grantUriPermissionToHostBrowser(
Context context, Intent launchIntent, String hostBrowserPackageName) {
ArrayList<Uri> uris = launchIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris == null) {
uris = new ArrayList<>();
Uri uri = launchIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
uris.add(uri);
}
}
for (Uri uri : uris) {
context.grantUriPermission(
hostBrowserPackageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
/**
* Launches host browser in WebAPK mode if the browser is WebAPK-compatible.
* Otherwise, launches the host browser in tabbed mode.
......@@ -65,11 +47,6 @@ public class HostBrowserLauncher {
/** Launches host browser in WebAPK mode. */
public static void launchBrowserInWebApkMode(
Context context, HostBrowserLauncherParams params, Bundle extraExtras, int flags) {
if (params.getSelectedShareTargetActivityClassName() != null) {
grantUriPermissionToHostBrowser(
context, params.getOriginalIntent(), params.getHostBrowserPackageName());
}
Intent intent = new Intent();
intent.setAction(ACTION_START_WEBAPK);
intent.setPackage(params.getHostBrowserPackageName());
......
......@@ -39,6 +39,7 @@ public class TransparentLauncherActivity extends Activity {
protected void onHostBrowserSelected(HostBrowserLauncherParams params) {
if (params != null) {
WebApkUtils.grantUriPermissionToHostBrowserIfShare(getApplicationContext(), params);
HostBrowserLauncher.launch(getApplicationContext(), params);
}
}
......
......@@ -31,6 +31,7 @@ import android.widget.TextView;
import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -333,4 +334,24 @@ public class WebApkUtils {
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}
}
/** Grants the host browser permission to the shared files if any. */
public static void grantUriPermissionToHostBrowserIfShare(
Context context, HostBrowserLauncherParams params) {
if (params.getSelectedShareTargetActivityClassName() == null) return;
Intent originalIntent = params.getOriginalIntent();
ArrayList<Uri> uris = originalIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris == null) {
uris = new ArrayList<>();
Uri uri = originalIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
uris.add(uri);
}
}
for (Uri uri : uris) {
context.grantUriPermission(
params.getHostBrowserPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
}
......@@ -10,6 +10,7 @@ import android.content.Context;
import org.chromium.webapk.shell_apk.HostBrowserLauncher;
import org.chromium.webapk.shell_apk.HostBrowserLauncherParams;
import org.chromium.webapk.shell_apk.TransparentLauncherActivity;
import org.chromium.webapk.shell_apk.WebApkUtils;
/**
* UI-less activity which launches host browser. Relaunches itself if the android.intent.action.MAIN
......@@ -22,6 +23,8 @@ public class H2OTransparentLauncherActivity extends TransparentLauncherActivity
return;
}
WebApkUtils.grantUriPermissionToHostBrowserIfShare(getApplicationContext(), params);
boolean shouldLaunchSplash = H2OLauncher.shouldIntentLaunchSplashActivity(params);
if (relaunchIfNeeded(params, shouldLaunchSplash)) {
return;
......
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