OLD | NEW |
---|---|
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 Intent launchIntent = new Intent(); | 189 Intent launchIntent = new Intent(); |
190 launchIntent.setClassName(this, activityName); | 190 launchIntent.setClassName(this, activityName); |
191 info.setWebappIntentExtras(launchIntent); | 191 info.setWebappIntentExtras(launchIntent); |
192 | 192 |
193 // On L+, firing intents with the exact same data should relaunch a part icular | 193 // On L+, firing intents with the exact same data should relaunch a part icular |
194 // Activity. | 194 // Activity. |
195 launchIntent.setAction(Intent.ACTION_VIEW); | 195 launchIntent.setAction(Intent.ACTION_VIEW); |
196 launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + in fo.id())); | 196 launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + in fo.id())); |
197 launchIntent.setFlags( | 197 launchIntent.setFlags( |
198 Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivit yNewDocumentFlag()); | 198 Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivit yNewDocumentFlag()); |
199 | 199 // Setting FLAG_ACTIVITY_CLEAR_TOP handles 2 edge cases: |
200 if (!isWebApk) { | 200 // - If a legacy PWA is launching from a notification, we want to ensure that the URL being |
201 // If this is launching from a notification, we want to ensure that the URL being | 201 // launched is the URL in the intent. If a paused WebappActivity exists for this id, |
202 // launched is the URL in the intent. If a paused WebappActivity exi sts for this id, | 202 // then by default it will be focused and we have no way of sending the desired URL to |
203 // then by default it will be focused and we have no way of sending the desired URL to | 203 // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that |
204 // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that | 204 // the existing Activity is cleared and relaunched with this intent. |
205 // the existing Activity is cleared and relaunched with this intent. | 205 // - If a WebAPK is having a CustomTabActivity on top of it in the same Task, and user |
206 // TODO(dominickn): ideally, we want be able to route an intent to | 206 // clicks a link to takes them back to the scope of a WebAPK, we want to destroy the |
207 // WebappActivity.onNewIntent instead of restarting the Activity. | 207 // CustomTabActivity activity and go back to the WebAPK activity. It is intentional that |
208 if (source == ShortcutSource.NOTIFICATION) { | 208 // Custom Tab will not be reachable with a back button. |
pkotwicz
2017/05/26 05:13:01
Given that this CL was reverted (not by me!) it is
piotrs
2017/05/26 05:39:31
Done.
| |
209 launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | 209 // TODO(dominickn): ideally, we want be able to route an intent to onNew Intent() instead of |
210 } | 210 // restarting the Activity. |
211 } | 211 launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
212 return launchIntent; | 212 return launchIntent; |
213 } | 213 } |
214 | 214 |
215 /** | 215 /** |
216 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID. | 216 * Brings a live WebappActivity back to the foreground if one exists for the given tab ID. |
217 * @param tabId ID of the Tab to bring back to the foreground. | 217 * @param tabId ID of the Tab to bring back to the foreground. |
218 * @return True if a live WebappActivity was found, false otherwise. | 218 * @return True if a live WebappActivity was found, false otherwise. |
219 */ | 219 */ |
220 public static boolean bringWebappToFront(int tabId) { | 220 public static boolean bringWebappToFront(int tabId) { |
221 if (tabId == Tab.INVALID_TAB_ID) return false; | 221 if (tabId == Tab.INVALID_TAB_ID) return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL); | 253 String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA _URL); |
254 if (TextUtils.isEmpty(url)) return false; | 254 if (TextUtils.isEmpty(url)) return false; |
255 | 255 |
256 if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url)) ) { | 256 if (!webApkPackage.equals(WebApkValidator.queryWebApkPackage(this, url)) ) { |
257 Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage ); | 257 Log.d(TAG, "%s is not within scope of %s WebAPK", url, webApkPackage ); |
258 return false; | 258 return false; |
259 } | 259 } |
260 return true; | 260 return true; |
261 } | 261 } |
262 } | 262 } |
OLD | NEW |