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

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

Issue 2762873003: Fix: long-tapping a WebAPK in recents shows Chrome.
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.net.Uri; 9 import android.net.Uri;
10 import android.os.Build; 10 import android.os.Build;
(...skipping 22 matching lines...) Expand all
33 public class WebappLauncherActivity extends Activity { 33 public class WebappLauncherActivity extends Activity {
34 /** 34 /**
35 * Action fired when an Intent is trying to launch a WebappActivity. 35 * Action fired when an Intent is trying to launch a WebappActivity.
36 * Never change the package name or the Intents will fail to launch. 36 * Never change the package name or the Intents will fail to launch.
37 */ 37 */
38 public static final String ACTION_START_WEBAPP = 38 public static final String ACTION_START_WEBAPP =
39 "com.google.android.apps.chrome.webapps.WebappManager.ACTION_START_W EBAPP"; 39 "com.google.android.apps.chrome.webapps.WebappManager.ACTION_START_W EBAPP";
40 40
41 private static final String TAG = "webapps"; 41 private static final String TAG = "webapps";
42 42
43 /**
44 * We remove android:documentLaunchMode="intoExisting" attribute from WebApk Activity since this
45 * version.
46 */
47 private static final int SHELL_APK_VERSION_BEFROE_REMOVE_DOCUMENT_LAUNCH_MOD E = 1;
gone 2017/03/22 22:20:07 BEFORE
48
43 @Override 49 @Override
44 public void onCreate(Bundle savedInstanceState) { 50 public void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState); 51 super.onCreate(savedInstanceState);
46 launchActivity(); 52 launchActivity();
47 ApiCompatibilityUtils.finishAndRemoveTask(this); 53 ApiCompatibilityUtils.finishAndRemoveTask(this);
48 } 54 }
49 55
50 public void launchActivity() { 56 public void launchActivity() {
51 Intent intent = getIntent(); 57 Intent intent = getIntent();
52 58
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Create an intent to launch the Webapp in an unmapped WebappActivity. 148 // Create an intent to launch the Webapp in an unmapped WebappActivity.
143 Intent launchIntent = new Intent(); 149 Intent launchIntent = new Intent();
144 launchIntent.setClassName(this, activityName); 150 launchIntent.setClassName(this, activityName);
145 info.setWebappIntentExtras(launchIntent); 151 info.setWebappIntentExtras(launchIntent);
146 152
147 // On L+, firing intents with the exact same data should relaunch a part icular 153 // On L+, firing intents with the exact same data should relaunch a part icular
148 // Activity. 154 // Activity.
149 launchIntent.setAction(Intent.ACTION_VIEW); 155 launchIntent.setAction(Intent.ACTION_VIEW);
150 launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + in fo.id())); 156 launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + in fo.id()));
151 157
152 if (!isWebApk) { 158 if ((isWebApk && info instanceof WebApkInfo
153 // For WebAPK, we don't start a new task for WebApkActivity, it is j ust on top 159 && ((WebApkInfo) info).shellApkVersion()
154 // of the WebAPK's main activity and in the same task. 160 > SHELL_APK_VERSION_BEFROE_REMOVE_DOCUMENT_LAUNCH_MO DE)
155 launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 161 || source == ShortcutSource.NOTIFICATION) {
156 | ApiCompatibilityUtils.getActivityNewDocumentFlag()); 162 // Since shell APK version 2, we removes the android:documentLaunchM ode="intoExisting"
163 // attribute from WebApkActivity. Instead, flag {@link FLAG_ACTIVITY _CLEAR_TOP} is used
164 // to deliver this intent to the WebApkActivity instance if it is al ready running on the
165 // top of the stack via onNewIntent(). WebApkActivity should be on t op of the WebAPK's
166 // main activity in the same task stack. See crbug.com/700157.
157 167
158 // If this is launching from a notification, we want to ensure that the URL being 168 // If this is launching from a notification, we want to ensure that the URL being
159 // launched is the URL in the intent. If a paused WebappActivity exi sts for this id, 169 // launched is the URL in the intent. If a paused WebappActivity exi sts for this id,
160 // then by default it will be focused and we have no way of sending the desired URL to 170 // then by default it will be focused and we have no way of sending the desired URL to
161 // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that 171 // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that
162 // the existing Activity is cleared and relaunched with this intent. 172 // the existing Activity is cleared and relaunched with this intent.
163 // TODO(dominickn): ideally, we want be able to route an intent to 173 // TODO(dominickn): ideally, we want be able to route an intent to
164 // WebappActivity.onNewIntent instead of restarting the Activity. 174 // WebappActivity.onNewIntent instead of restarting the Activity.
165 if (source == ShortcutSource.NOTIFICATION) { 175 launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
166 launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 176 } else {
gone 2017/03/22 22:20:07 You've changed this logic here so that non WebApks
gone 2017/03/22 22:23:28 Well, I can see how this would stay the same logic
167 } 177 launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
178 | ApiCompatibilityUtils.getActivityNewDocumentFlag());
168 } 179 }
169 return launchIntent; 180 return launchIntent;
170 } 181 }
171 182
172 /** 183 /**
173 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID. 184 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID.
174 * @param tabId ID of the Tab to bring back to the foreground. 185 * @param tabId ID of the Tab to bring back to the foreground.
175 * @return True if a live WebappActivity was found, false otherwise. 186 * @return True if a live WebappActivity was found, false otherwise.
176 */ 187 */
177 public static boolean bringWebappToFront(int tabId) { 188 public static boolean bringWebappToFront(int tabId) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL); 221 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL);
211 if (TextUtils.isEmpty(url)) return false; 222 if (TextUtils.isEmpty(url)) return false;
212 223
213 if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url)) ) { 224 if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url)) ) {
214 Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage ); 225 Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage );
215 return false; 226 return false;
216 } 227 }
217 return true; 228 return true;
218 } 229 }
219 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698