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

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

Issue 2762873003: Fix: long-tapping a WebAPK in recents shows Chrome.
Patch Set: yfriedman@'s comments. Created 3 years, 9 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/LaunchWebApkHelper.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/LaunchWebApkHelper.java
similarity index 69%
copy from chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java
copy to chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/LaunchWebApkHelper.java
index 5a0b7d4ad695cdde432daec0b660ab4e1c15195f..5dbdbfba3efc5e742de36d4b36339fe03246c48d 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/LaunchWebApkHelper.java
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,6 @@ 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;
@@ -20,16 +19,10 @@ import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
import java.net.URISyntaxException;
/**
- * WebAPK's main Activity.
+ * A helper class to launch WebAPK.
*/
-public class MainActivity extends Activity {
- private static final String TAG = "cr_MainActivity";
-
- /**
- * Name of class which launches browser in WebAPK mode.
- */
- private static final String HOST_BROWSER_LAUNCHER_CLASS_NAME =
- "org.chromium.webapk.lib.runtime_library.HostBrowserLauncher";
+public class LaunchWebApkHelper {
+ private static final String TAG = "cr_LaunchWebApkHelper";
// Action for launching {@link WebappLauncherActivity}. Must stay in sync with
// {@link WebappLauncherActivity#ACTION_START_WEBAPP}.
@@ -42,11 +35,6 @@ public class MainActivity extends Activity {
"REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB";
/**
- * Key for passing app icon id.
- */
- private static final String KEY_APP_ICON_ID = "app_icon_id";
-
- /**
* Creates install Intent.
* @param packageName Package to install.
* @return The intent.
@@ -56,43 +44,38 @@ public class MainActivity extends Activity {
return new Intent(Intent.ACTION_VIEW, Uri.parse(marketUrl));
}
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- launch();
- finish();
- }
-
/**
- * Launches WebAPK.
+ * Launches WebAPK, returns whether the the host browser is launched in WebAPK mode.
*/
- private void launch() {
- String overrideUrl = getOverrideUrl();
- String startUrl = (overrideUrl != null) ? overrideUrl : getStartUrl();
+ public static boolean launch(Activity activity) {
+ String overrideUrl = getOverrideUrl(activity);
+ String startUrl = (overrideUrl != null) ? overrideUrl : getStartUrl(activity);
if (startUrl == null) {
- return;
+ return false;
}
- if (launchHostBrowserInWebApkMode(startUrl, overrideUrl)) {
- return;
+ if (launchHostBrowserInWebApkMode(activity, startUrl, overrideUrl)) {
+ return true;
}
- if (launchBrowser(startUrl)) {
- return;
+ if (launchBrowser(activity, startUrl)) {
+ return false;
}
- installBrowser();
+ installBrowser(activity);
+ return false;
}
/**
* Launches host browser in WebAPK mode.
* @return True if successful.
*/
- private boolean launchHostBrowserInWebApkMode(String startUrl, String overrideUrl) {
+ private static boolean launchHostBrowserInWebApkMode(
+ Activity activity, String startUrl, String overrideUrl) {
Log.v(TAG, "Url of the WebAPK: " + startUrl);
- String packageName = getPackageName();
+ String packageName = activity.getPackageName();
Log.v(TAG, "Package name of the WebAPK:" + packageName);
- String runtimeHost = WebApkUtils.getHostBrowserPackageName(this);
- int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0);
+ String runtimeHost = WebApkUtils.getHostBrowserPackageName(activity);
+ int source = activity.getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0);
// The override URL is non null when the WebAPK is launched from a deep link. The WebAPK
// should navigate to the URL in the deep link even if the WebAPK is already open.
@@ -105,7 +88,7 @@ public class MainActivity extends Activity {
.putExtra(WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, (overrideUrl != null));
try {
- startActivity(intent);
+ activity.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch browser in WebAPK mode.");
@@ -119,7 +102,7 @@ public class MainActivity extends Activity {
* @param startUrl URL to navigate browser to.
* @return True if successful.
*/
- private boolean launchBrowser(String startUrl) {
+ private static boolean launchBrowser(Activity activity, String startUrl) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(startUrl));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
@@ -133,13 +116,13 @@ public class MainActivity extends Activity {
}
// Add extras in case that the URL is launched in Chrome.
- int source =
- getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, Intent.URI_INTENT_SCHEME);
+ int source = activity.getIntent().getIntExtra(
+ WebApkConstants.EXTRA_SOURCE, Intent.URI_INTENT_SCHEME);
intent.putExtra(REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true)
- .putExtra(WebApkConstants.EXTRA_SOURCE, source);
+ .putExtra(WebApkConstants.EXTRA_SOURCE, source);
try {
- startActivity(intent);
+ activity.startActivity(intent);
} catch (ActivityNotFoundException e) {
return false;
}
@@ -149,21 +132,21 @@ public class MainActivity extends Activity {
/**
* Launches the Play Store with the host browser's page.
*/
- private void installBrowser() {
- String hostBrowserPackageName = WebApkUtils.getHostBrowserPackageName(this);
+ private static void installBrowser(Activity activity) {
+ String hostBrowserPackageName = WebApkUtils.getHostBrowserPackageName(activity);
if (hostBrowserPackageName == null) {
return;
}
try {
- startActivity(createInstallIntent(hostBrowserPackageName));
+ activity.startActivity(createInstallIntent(hostBrowserPackageName));
} catch (ActivityNotFoundException e) {
}
}
/** Retrieves URL from the intent's data. Returns null if a URL could not be retrieved. */
- private String getOverrideUrl() {
- String overrideUrl = getIntent().getDataString();
+ private static String getOverrideUrl(Activity activity) {
+ String overrideUrl = activity.getIntent().getDataString();
if (overrideUrl != null && overrideUrl.startsWith("https:")) {
return overrideUrl;
}
@@ -171,11 +154,11 @@ public class MainActivity extends Activity {
}
/** Returns the start URL from the Android Manifest. */
- private String getStartUrl() {
+ private static String getStartUrl(Activity activity) {
ApplicationInfo appInfo;
try {
- appInfo = getPackageManager().getApplicationInfo(
- getPackageName(), PackageManager.GET_META_DATA);
+ appInfo = activity.getPackageManager().getApplicationInfo(
+ activity.getPackageName(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
return null;
}

Powered by Google App Engine
This is Rietveld 408576698