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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappLauncherActivity.java

Issue 2385413002: Move Webapp launch code to WebappLauncherActivity#launch() to enable early returns (Closed)
Patch Set: Merge branch 'master' into security0 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f2f38a715fc5eb87ea72d75add2c80c9b1f1dc38..cdd3ab68c7f1d5aeb00fd9fcaed0623f9b2965eb 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
@@ -42,52 +42,50 @@ public class WebappLauncherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
- WebappInfo webappInfo = WebappInfo.create(getIntent());
- if (webappInfo == null) {
- // {@link WebappInfo#create()} returns null if the intent does not specify the id or the
- // uri.
- super.onCreate(null);
- ApiCompatibilityUtils.finishAndRemoveTask(this);
- return;
- }
-
super.onCreate(savedInstanceState);
+ launchActivity();
+ ApiCompatibilityUtils.finishAndRemoveTask(this);
+ }
+
+ public void launchActivity() {
Intent intent = getIntent();
+ WebappInfo webappInfo = WebappInfo.create(intent);
+
+ // {@link WebappInfo#create()} returns null if the intent does not specify the id or the
+ // uri.
+ if (webappInfo == null) return;
+
String webappUrl = webappInfo.uri().toString();
String webApkPackageName = webappInfo.webApkPackageName();
int webappSource = webappInfo.source();
+ String webappMac = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_MAC);
- Intent launchIntent = null;
+ ChromeWebApkHost.init();
+ boolean isValidWebApk = isValidWebApk(webApkPackageName, webappUrl);
// Permit the launch to a standalone web app frame if any of the following are true:
// - the request was for a WebAPK that is valid;
// - the MAC is present and valid for the homescreen shortcut to be opened;
// - the intent was sent by Chrome.
- ChromeWebApkHost.init();
- boolean isValidWebApk = isValidWebApk(webApkPackageName, webappUrl);
-
- if (isValidWebApk
- || isValidMacForUrl(webappUrl, IntentUtils.safeGetStringExtra(
- intent, ShortcutHelper.EXTRA_MAC))
+ if (isValidWebApk || isValidMacForUrl(webappUrl, webappMac)
|| wasIntentFromChrome(intent)) {
LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(webappUrl, webappSource);
- launchIntent = createWebappLaunchIntent(webappInfo, webappSource, isValidWebApk);
- } else {
- Log.e(TAG, "Shortcut (%s) opened in Chrome.", webappUrl);
-
- // The shortcut data doesn't match the current encoding. Change the intent action
- // launch the URL with a VIEW Intent in the regular browser.
- launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webappUrl));
- launchIntent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
- launchIntent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
- launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource);
- launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | ApiCompatibilityUtils.getActivityNewDocumentFlag());
+ Intent launchIntent = createWebappLaunchIntent(webappInfo, webappSource, isValidWebApk);
+ startActivity(launchIntent);
+ return;
}
- startActivity(launchIntent);
+ Log.e(TAG, "Shortcut (%s) opened in Chrome.", webappUrl);
- ApiCompatibilityUtils.finishAndRemoveTask(this);
+ // The shortcut data doesn't match the current encoding. Change the intent action to
+ // launch the URL with a VIEW Intent in the regular browser.
+ Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webappUrl));
+ launchIntent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
+ launchIntent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
+ launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource);
+ launchIntent.setFlags(
+ Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());
+ startActivity(launchIntent);
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698