Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInfo.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInfo.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInfo.java |
| index 27893265b23d0f08c6023e93ea3af21442ace207..10682a35ad95987488616736c65ab35f3155fd0c 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInfo.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInfo.java |
| @@ -31,6 +31,7 @@ import java.util.Map; |
| public class WebApkInfo extends WebappInfo { |
| private static final String TAG = "WebApkInfo"; |
| + private boolean mShouldNavigateIfAlreadyRunning; |
|
dominickn
2017/03/21 02:09:33
I would call this mForceNavigation;
|
| private String mWebApkPackageName; |
| private int mShellApkVersion; |
| private String mManifestUrl; |
| @@ -55,7 +56,10 @@ public class WebApkInfo extends WebappInfo { |
| String url = urlFromIntent(intent); |
| int source = sourceFromIntent(intent); |
| - return create(webApkPackageName, url, source); |
| + boolean navigateIfAlreadyRunning = IntentUtils.safeGetBooleanExtra( |
| + intent, WebApkConstants.EXTRA_WEBAPK_NAVIGATE_IF_ALREADY_OPEN, false); |
| + |
| + return create(webApkPackageName, url, navigateIfAlreadyRunning, source); |
| } |
| /** |
| @@ -64,9 +68,12 @@ public class WebApkInfo extends WebappInfo { |
| * |
| * @param webApkPackageName The package name of the WebAPK. |
| * @param url Url that the WebAPK should navigate to when launched. |
| + * @param navigateIfAlreadyRunning Whether the WebAPK should navigate to {@link uri} if it is |
| + * already running. |
| * @param source Source that the WebAPK was launched from. |
| */ |
| - public static WebApkInfo create(String webApkPackageName, String url, int source) { |
| + public static WebApkInfo create( |
| + String webApkPackageName, String url, boolean navigateIfAlreadyRunning, int source) { |
|
dominickn
2017/03/21 02:09:33
Nit: I would put the boolean last.
Nit: I would c
|
| // Unlike non-WebAPK web apps, WebAPK ids are predictable. A malicious actor may send an |
| // intent with a valid start URL and arbitrary other data. Only use the start URL, the |
| // package name and the ShortcutSource from the launch intent and extract the remaining data |
| @@ -100,38 +107,41 @@ public class WebApkInfo extends WebappInfo { |
| int iconId = IntentUtils.safeGetInt(bundle, WebApkMetaDataKeys.ICON_ID, 0); |
| Bitmap icon = decodeImageResource(webApkPackageName, iconId); |
| - return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, scope, |
| - new Icon(icon), name, shortName, displayMode, orientation, source, themeColor, |
| - backgroundColor, webApkPackageName, shellApkVersion, manifestUrl, manifestStartUrl, |
| - iconUrlToMurmur2HashMap); |
| + return create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url, |
| + navigateIfAlreadyRunning, scope, new Icon(icon), name, shortName, displayMode, |
| + orientation, source, themeColor, backgroundColor, webApkPackageName, |
| + shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap); |
| } |
| /** |
| * Construct a {@link WebApkInfo} instance. |
| * |
| - * @param id ID for the WebAPK. |
| - * @param url URL that the WebAPK should navigate to when launched. |
| - * @param scope Scope for the WebAPK. |
| - * @param icon Icon to show for the WebAPK. |
| - * @param name Name of the WebAPK. |
| - * @param shortName The short name of the WebAPK. |
| - * @param displayMode Display mode of the WebAPK. |
| - * @param orientation Orientation of the WebAPK. |
| - * @param source Source that the WebAPK was launched from. |
| - * @param themeColor The theme color of the WebAPK. |
| - * @param backgroundColor The background color of the WebAPK. |
| - * @param webApkPackageName The package of the WebAPK. |
| - * @param shellApkVersion Version of the code in //chrome/android/webapk/shell_apk. |
| - * @param manifestUrl URL of the Web Manifest. |
| - * @param manifestStartUrl URL that the WebAPK should navigate to when launched from the |
| - * homescreen. Different from the {@link url} parameter if the |
| - * WebAPK is launched from a deep link. |
| - * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 hashes of the |
| - * icon untransformed bytes. |
| + * @param id ID for the WebAPK. |
| + * @param url URL that the WebAPK should navigate to when launched. |
| + * @param navigateIfAlreadyRunning Whether the WebAPK should navigate to {@link uri} if the |
| + * WebAPK is already open. |
| + * @param scope Scope for the WebAPK. |
| + * @param icon Icon to show for the WebAPK. |
| + * @param name Name of the WebAPK. |
| + * @param shortName The short name of the WebAPK. |
| + * @param displayMode Display mode of the WebAPK. |
| + * @param orientation Orientation of the WebAPK. |
| + * @param source Source that the WebAPK was launched from. |
| + * @param themeColor The theme color of the WebAPK. |
| + * @param backgroundColor The background color of the WebAPK. |
| + * @param webApkPackageName The package of the WebAPK. |
| + * @param shellApkVersion Version of the code in //chrome/android/webapk/shell_apk. |
| + * @param manifestUrl URL of the Web Manifest. |
| + * @param manifestStartUrl URL that the WebAPK should navigate to when launched from the |
| + * homescreen. Different from the {@link url} parameter if the |
| + * WebAPK is launched from a deep link. |
| + * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 hashes of the |
| + * icon untransformed bytes. |
| */ |
| - public static WebApkInfo create(String id, String url, String scope, Icon icon, String name, |
| - String shortName, int displayMode, int orientation, int source, long themeColor, |
| - long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, |
| + public static WebApkInfo create(String id, String url, boolean navigateIfAlreadyRunning, |
| + String scope, Icon icon, String name, String shortName, int displayMode, |
| + int orientation, int source, long themeColor, long backgroundColor, |
| + String webApkPackageName, int shellApkVersion, String manifestUrl, |
| String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) { |
| if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) { |
| Log.e(TAG, |
| @@ -147,17 +157,19 @@ public class WebApkInfo extends WebappInfo { |
| scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl); |
| } |
| - return new WebApkInfo(id, url, scope, icon, name, shortName, displayMode, |
| - orientation, source, themeColor, backgroundColor, webApkPackageName, |
| + return new WebApkInfo(id, url, navigateIfAlreadyRunning, scope, icon, name, shortName, |
| + displayMode, orientation, source, themeColor, backgroundColor, webApkPackageName, |
| shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap); |
| } |
| - protected WebApkInfo(String id, String url, String scope, Icon icon, String name, |
| - String shortName, int displayMode, int orientation, int source, long themeColor, |
| - long backgroundColor, String webApkPackageName, int shellApkVersion, String manifestUrl, |
| - String manifestStartUrl, Map<String, String> iconUrlToMurmur2HashMap) { |
| + protected WebApkInfo(String id, String url, boolean navigateIfAlreadyRunning, String scope, |
| + Icon icon, String name, String shortName, int displayMode, int orientation, int source, |
| + long themeColor, long backgroundColor, String webApkPackageName, int shellApkVersion, |
| + String manifestUrl, String manifestStartUrl, |
| + Map<String, String> iconUrlToMurmur2HashMap) { |
| super(id, url, scope, icon, name, shortName, displayMode, orientation, source, themeColor, |
| backgroundColor, false); |
| + mShouldNavigateIfAlreadyRunning = navigateIfAlreadyRunning; |
| mWebApkPackageName = webApkPackageName; |
| mShellApkVersion = shellApkVersion; |
| mManifestUrl = manifestUrl; |
| @@ -168,6 +180,11 @@ public class WebApkInfo extends WebappInfo { |
| protected WebApkInfo() {} |
| @Override |
| + public boolean shouldNavigateIfAlreadyRunning() { |
|
dominickn
2017/03/21 02:09:32
shouldForceNavigation()
|
| + return mShouldNavigateIfAlreadyRunning; |
| + } |
| + |
| + @Override |
| public String webApkPackageName() { |
| return mWebApkPackageName; |
| } |
| @@ -194,6 +211,8 @@ public class WebApkInfo extends WebappInfo { |
| intent.putExtra(ShortcutHelper.EXTRA_URL, uri().toString()); |
| intent.putExtra(ShortcutHelper.EXTRA_SOURCE, source()); |
| intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackageName()); |
| + intent.putExtra(WebApkConstants.EXTRA_WEBAPK_NAVIGATE_IF_ALREADY_OPEN, |
| + mShouldNavigateIfAlreadyRunning); |
| } |
| /** |