Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java |
index c25ccaebbc11b28233f726ba673aa941fe847384..e16c6ba598322f54b0b856ff04ee0e9d4f342b94 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java |
@@ -13,14 +13,17 @@ import android.util.Base64; |
import org.chromium.base.ApiCompatibilityUtils; |
import org.chromium.base.ApplicationStatus; |
+import org.chromium.base.CommandLine; |
import org.chromium.base.ContextUtils; |
import org.chromium.base.Log; |
+import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.IntentHandler; |
import org.chromium.chrome.browser.ShortcutHelper; |
import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
import org.chromium.chrome.browser.metrics.LaunchMetrics; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.util.IntentUtils; |
+import org.chromium.webapk.lib.common.WebApkConstants; |
import java.lang.ref.WeakReference; |
@@ -51,6 +54,7 @@ public class WebappLauncherActivity extends Activity { |
Intent intent = getIntent(); |
String webappId = webappInfo.id(); |
String webappUrl = webappInfo.uri().toString(); |
+ String webApkPackageName = webappInfo.webApkPackageName(); |
int webappSource = webappInfo.source(); |
if (webappId != null && webappUrl != null) { |
@@ -67,6 +71,10 @@ public class WebappLauncherActivity extends Activity { |
ContextUtils.getApplicationContext()); |
boolean isUrlValid = (webappMac != null |
&& WebappAuthenticator.isUrlValid(this, webappUrl, webappMac)); |
+ boolean isValidWebApk = isValidWebApk(webApkPackageName); |
+ if (webApkPackageName != null && !isValidWebApk) { |
+ isUrlValid = false; |
+ } |
if (isTrusted || isUrlValid) { |
LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(webappUrl, webappSource); |
@@ -98,8 +106,12 @@ public class WebappLauncherActivity extends Activity { |
launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource); |
} |
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
- | ApiCompatibilityUtils.getActivityNewDocumentFlag()); |
+ if (!isValidWebApk) { |
+ // For WebAPK, we don't start a new task for WebappActivity, it is just on top |
+ // of the WebAPK's main activity and in the same task. |
+ launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+ | ApiCompatibilityUtils.getActivityNewDocumentFlag()); |
+ } |
startActivity(launchIntent); |
} |
@@ -129,4 +141,17 @@ public class WebappLauncherActivity extends Activity { |
return false; |
} |
+ |
+ /** |
+ * Checks whether the package being targeted is a valid WebAPK. |
+ * @param webapkPackageName The package name of the requested WebAPK. |
+ * @return true iff all validation criteria are met. |
+ */ |
+ private boolean isValidWebApk(String webapkPackageName) { |
+ // TODO(hanxi): Adds more validation checks. For example, whether the WebAPK is signed |
+ // by the WebAPK Minting Server. |
+ return CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK) |
+ && webapkPackageName != null |
+ && webapkPackageName.startsWith(WebApkConstants.WEBAPK_PACKAGE_PREFIX); |
+ } |
} |