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

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

Issue 2114173002: Launch Chrome in non-WebAPK mode if WebAPK runtime library cannot be loaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_more_meta2_loader2 Created 4 years, 5 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
« no previous file with comments | « chrome/android/webapk/libs/runtime_library/src/org/chromium/webapk/lib/runtime_library/HostBrowserLauncher.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 012c4c61e96bd8c179d153991596cdb70bf98d69..52b1b1faf88ef43922a1f06016e6def098856895 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
@@ -7,9 +7,16 @@ package org.chromium.webapk.shell_apk;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import org.chromium.webapk.lib.common.WebApkConstants;
+import org.chromium.webapk.lib.common.WebApkUtils;
+
import java.lang.reflect.Method;
/**
@@ -24,6 +31,14 @@ public class MainActivity extends Activity {
private static final String HOST_BROWSER_LAUNCHER_CLASS_NAME =
"org.chromium.webapk.lib.runtime_library.HostBrowserLauncher";
+ // Must stay in sync with
+ // {@link org.chromium.chrome.browser.ShortcutHelper#REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB}.
+ private static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB =
+ "REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB";
+
+ // Key for start URL in Android Manifest.
+ private static final String META_DATA_START_URL = "startUrl";
+
/**
* Key for passing app icon id.
*/
@@ -32,19 +47,23 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- launchHostBrowser();
+ if (!launchHostBrowserInWebApkMode()) {
+ // Launch browser in non-WebAPK mode.
+ launchHostBrowser();
+ }
finish();
}
/**
* Launches host browser in WebAPK mode.
+ * @return True if successful.
*/
- public void launchHostBrowser() {
+ public boolean launchHostBrowserInWebApkMode() {
ClassLoader webApkClassLoader = HostBrowserClassLoader.getClassLoaderInstance(
this, HOST_BROWSER_LAUNCHER_CLASS_NAME);
if (webApkClassLoader == null) {
Log.w(TAG, "Unable to create ClassLoader.");
- return;
+ return false;
}
try {
@@ -56,9 +75,46 @@ public class MainActivity extends Activity {
Bundle bundle = new Bundle();
bundle.putInt(KEY_APP_ICON_ID, R.drawable.app_icon);
launchMethod.invoke(hostBrowserLauncherInstance, this, getIntent(), bundle);
+ return true;
} catch (Exception e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Launches host browser in non-WebAPK mode.
+ */
+ public void launchHostBrowser() {
+ String startUrl = getStartUrl();
+ if (startUrl == null) {
+ return;
+ }
+ int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0);
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(startUrl));
+ intent.setPackage(WebApkUtils.getHostBrowserPackageName(this));
+ intent.putExtra(REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true)
+ .putExtra(WebApkConstants.EXTRA_SOURCE, source);
+ startActivity(intent);
+ }
+
+ /**
+ * Returns the URL that the browser should navigate to.
+ */
+ public String getStartUrl() {
+ String overrideUrl = getIntent().getDataString();
+ if (overrideUrl != null && overrideUrl.startsWith("https:")) {
+ return overrideUrl;
+ }
+
+ ApplicationInfo appInfo;
+ try {
+ appInfo = getPackageManager().getApplicationInfo(
+ getPackageName(), PackageManager.GET_META_DATA);
+ } catch (NameNotFoundException e) {
+ return null;
}
+ return appInfo.metaData.getString(META_DATA_START_URL);
}
}
« no previous file with comments | « chrome/android/webapk/libs/runtime_library/src/org/chromium/webapk/lib/runtime_library/HostBrowserLauncher.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698