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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
10 | 10 |
11 import org.chromium.base.CommandLine; | 11 import org.chromium.base.CommandLine; |
12 import org.chromium.chrome.browser.tab.Tab; | 12 import org.chromium.chrome.browser.tab.Tab; |
13 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 13 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
14 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; | 14 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
15 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 15 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
16 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 16 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
17 import org.chromium.chrome.browser.webapps.WebappRegistry; | 17 import org.chromium.chrome.browser.webapps.WebappRegistry; |
18 import org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorage
Callback; | 18 import org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorage
Callback; |
19 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; | 19 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; |
20 import org.chromium.content_public.browser.LoadUrlParams; | 20 import org.chromium.content_public.browser.LoadUrlParams; |
21 import org.chromium.content_public.common.Referrer; | 21 import org.chromium.content_public.common.Referrer; |
22 import org.chromium.content_public.common.ResourceRequestBody; | 22 import org.chromium.content_public.common.ResourceRequestBody; |
23 import org.chromium.ui.base.PageTransition; | 23 import org.chromium.ui.base.PageTransition; |
24 import org.chromium.webapk.lib.client.NavigationClient; | 24 import org.chromium.webapk.lib.client.WebApkNavigationClient; |
25 import org.chromium.webapk.lib.client.WebApkValidator; | 25 import org.chromium.webapk.lib.client.WebApkValidator; |
26 | 26 |
27 /** | 27 /** |
28 * Service Tab Launcher implementation for Chrome. Provides the ability for Andr
oid Services | 28 * Service Tab Launcher implementation for Chrome. Provides the ability for Andr
oid Services |
29 * running in Chrome to launch URLs, without having access to an activity. | 29 * running in Chrome to launch URLs, without having access to an activity. |
30 * | 30 * |
31 * This class is referred to from the ServiceTabLauncher implementation in Chrom
ium using a | 31 * This class is referred to from the ServiceTabLauncher implementation in Chrom
ium using a |
32 * meta-data value in the Android manifest file. The ServiceTabLauncher class ha
s more | 32 * meta-data value in the Android manifest file. The ServiceTabLauncher class ha
s more |
33 * documentation about why this is necessary. | 33 * documentation about why this is necessary. |
34 * | 34 * |
35 * URLs within the scope of a recently launched standalone-capable web app on th
e Android home | 35 * URLs within the scope of a recently launched standalone-capable web app on th
e Android home |
36 * screen are launched in the standalone web app frame. | 36 * screen are launched in the standalone web app frame. |
37 * | 37 * |
38 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove
reflection calls | 38 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove
reflection calls |
39 * in ServiceTabLauncher. | 39 * in ServiceTabLauncher. |
40 */ | 40 */ |
41 public class ChromeServiceTabLauncher extends ServiceTabLauncher { | 41 public class ChromeServiceTabLauncher extends ServiceTabLauncher { |
42 @Override | 42 @Override |
43 public void launchTab(final Context context, final int requestId, final bool
ean incognito, | 43 public void launchTab(final Context context, final int requestId, final bool
ean incognito, |
44 final String url, final int disposition, final String referrerUrl, | 44 final String url, final int disposition, final String referrerUrl, |
45 final int referrerPolicy, final String extraHeaders, | 45 final int referrerPolicy, final String extraHeaders, |
46 final ResourceRequestBody postData) { | 46 final ResourceRequestBody postData) { |
47 final TabDelegate tabDelegate = new TabDelegate(incognito); | 47 final TabDelegate tabDelegate = new TabDelegate(incognito); |
48 | 48 |
49 // 1. Launch WebAPK if one matches the target URL. | 49 // 1. Launch WebAPK if one matches the target URL. |
50 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) { | 50 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) { |
51 String webApkPackageName = WebApkValidator.queryWebApkPackage(contex
t, url); | 51 String webApkPackageName = WebApkValidator.queryWebApkPackage(contex
t, url); |
52 if (webApkPackageName != null) { | 52 if (webApkPackageName != null) { |
53 NavigationClient.launchWebApk(context, webApkPackageName, url); | 53 Intent intent = |
54 return; | 54 WebApkNavigationClient.createLaunchWebApkIntent(webApkPa
ckageName, url); |
| 55 if (intent != null) { |
| 56 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.
NOTIFICATION); |
| 57 context.startActivity(intent); |
| 58 return; |
| 59 } |
55 } | 60 } |
56 } | 61 } |
57 | 62 |
58 // 2. Launch WebappActivity if one matches the target URL and was opened
recently. | 63 // 2. Launch WebappActivity if one matches the target URL and was opened
recently. |
59 // Otherwise, open the URL in a tab. | 64 // Otherwise, open the URL in a tab. |
60 FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCall
back() { | 65 FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCall
back() { |
61 @Override | 66 @Override |
62 public void onWebappDataStorageRetrieved(final WebappDataStorage sto
rage) { | 67 public void onWebappDataStorageRetrieved(final WebappDataStorage sto
rage) { |
63 // If we do not find a WebappDataStorage corresponding to this U
RL, or if it hasn't | 68 // If we do not find a WebappDataStorage corresponding to this U
RL, or if it hasn't |
64 // been opened recently enough, open the URL in a tab. | 69 // been opened recently enough, open the URL in a tab. |
(...skipping 27 matching lines...) Expand all Loading... |
92 ShortcutSource.NOTIFICATION); | 97 ShortcutSource.NOTIFICATION); |
93 tabDelegate.createNewStandaloneFrame(intent); | 98 tabDelegate.createNewStandaloneFrame(intent); |
94 } | 99 } |
95 }.execute(); | 100 }.execute(); |
96 } | 101 } |
97 } | 102 } |
98 }; | 103 }; |
99 WebappRegistry.getWebappDataStorageForUrl(context, url, callback); | 104 WebappRegistry.getWebappDataStorageForUrl(context, url, callback); |
100 } | 105 } |
101 } | 106 } |
OLD | NEW |