Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1988)

Unified Diff: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java

Issue 2409483002: Read the bare minimum of data from the WebAPK launch intent. (Closed)
Patch Set: Merge branch 'startup_crash0' into security Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
diff --git a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
index a99304ef3b8417a86aed263f9a72749595574467..a2a62a32c9e9d47466f3c17ad5dccb561faf9d84 100644
--- a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
+++ b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
@@ -6,7 +6,7 @@ package org.chromium.webapk.shell_apk;
import android.app.Activity;
import android.content.ActivityNotFoundException;
-import android.content.Context;
+import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -18,7 +18,6 @@ import android.util.Log;
import org.chromium.webapk.lib.common.WebApkConstants;
import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
-import java.lang.reflect.Method;
import java.net.URISyntaxException;
/**
@@ -64,13 +63,13 @@ public class MainActivity extends Activity {
* Launches WebAPK.
*/
private void launch() {
- if (launchHostBrowserInWebApkMode()) {
- return;
- }
String startUrl = getStartUrl();
if (startUrl == null) {
return;
}
+ if (launchHostBrowserInWebApkMode(startUrl)) {
+ return;
+ }
if (launchBrowser(startUrl)) {
return;
}
@@ -81,25 +80,25 @@ public class MainActivity extends Activity {
* Launches host browser in WebAPK mode.
* @return True if successful.
*/
- private boolean launchHostBrowserInWebApkMode() {
- ClassLoader webApkClassLoader = HostBrowserClassLoader.getClassLoaderInstance(
- this, HOST_BROWSER_LAUNCHER_CLASS_NAME);
- if (webApkClassLoader == null) {
- Log.w(TAG, "Unable to create ClassLoader.");
- return false;
- }
+ private boolean launchHostBrowserInWebApkMode(String startUrl) {
+ Log.v(TAG, "Url of the WebAPK: " + startUrl);
+ String packageName = getPackageName();
+ Log.v(TAG, "Package name of the WebAPK:" + packageName);
+
+ String runtimeHost = WebApkUtils.getHostBrowserPackageName(this);
+ int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0);
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(
+ runtimeHost, "org.chromium.chrome.browser.webapps.WebappLauncherActivity"));
+ intent.putExtra(WebApkConstants.EXTRA_ID, WebApkConstants.WEBAPK_ID_PREFIX + packageName)
+ .putExtra(WebApkConstants.EXTRA_URL, startUrl)
+ .putExtra(WebApkConstants.EXTRA_SOURCE, source)
+ .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName);
try {
- Class<?> hostBrowserLauncherClass =
- webApkClassLoader.loadClass(HOST_BROWSER_LAUNCHER_CLASS_NAME);
- Method launchMethod = hostBrowserLauncherClass.getMethod(
- "launch", Context.class, Intent.class, Bundle.class);
- Object hostBrowserLauncherInstance = hostBrowserLauncherClass.newInstance();
- Bundle bundle = new Bundle();
- bundle.putInt(KEY_APP_ICON_ID, R.mipmap.app_icon);
- launchMethod.invoke(hostBrowserLauncherInstance, this, getIntent(), bundle);
+ startActivity(intent);
return true;
- } catch (Exception e) {
+ } catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
e.printStackTrace();
return false;

Powered by Google App Engine
This is Rietveld 408576698