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; | |
9 import android.os.AsyncTask; | |
8 | 10 |
9 import org.chromium.chrome.browser.document.DocumentMetricIds; | 11 import org.chromium.chrome.browser.document.DocumentMetricIds; |
10 import org.chromium.chrome.browser.tab.Tab; | 12 import org.chromium.chrome.browser.tab.Tab; |
11 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 13 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
12 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; | 14 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
13 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; | |
17 import org.chromium.chrome.browser.webapps.WebappRegistry; | |
14 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; | 18 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; |
15 import org.chromium.content_public.browser.LoadUrlParams; | 19 import org.chromium.content_public.browser.LoadUrlParams; |
16 import org.chromium.content_public.common.Referrer; | 20 import org.chromium.content_public.common.Referrer; |
17 import org.chromium.ui.base.PageTransition; | 21 import org.chromium.ui.base.PageTransition; |
18 | 22 |
19 /** | 23 /** |
20 * Service Tab Launcher implementation for Chrome. Provides the ability for Andr oid Services | 24 * Service Tab Launcher implementation for Chrome. Provides the ability for Andr oid Services |
21 * running in Chrome to launch tabs, without having access to an activity. | 25 * running in Chrome to launch URLs, without having access to an activity. |
22 * | 26 * |
23 * This class is referred to from the ServiceTabLauncher implementation in Chrom ium using a | 27 * This class is referred to from the ServiceTabLauncher implementation in Chrom ium using a |
24 * meta-data value in the Android manifest file. The ServiceTabLauncher class ha s more | 28 * meta-data value in the Android manifest file. The ServiceTabLauncher class ha s more |
25 * documentation about why this is necessary. | 29 * documentation about why this is necessary. |
26 * | 30 * |
31 * URLs within the scope of a recently launched standalone-capable web app on th e Android homescreen | |
32 * are launched in the standalone web app frame. | |
33 * | |
27 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove reflection calls | 34 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove reflection calls |
28 * in ServiceTabLauncher. | 35 * in ServiceTabLauncher. |
29 */ | 36 */ |
30 public class ChromeServiceTabLauncher extends ServiceTabLauncher { | 37 public class ChromeServiceTabLauncher extends ServiceTabLauncher { |
31 @Override | 38 @Override |
32 public void launchTab(Context context, int requestId, boolean incognito, Str ing url, | 39 public void launchTab(final Context context, final int requestId, final bool ean incognito, |
33 int disposition, String referrerUrl, int referrerPolic y, | 40 final String url, final int disposition, final String referrerUrl, |
34 String extraHeaders, byte[] postData) { | 41 final int referrerPolicy, final String extraHeaders, final byte[] po stData) { |
35 // TODO(peter): Determine the intent source based on the |disposition| w ith which the | 42 WebappRegistry.getWebappDataStorageForUrl(context, url, |
36 // tab is being launched. Right now this is gated by a check in the nati ve implementation. | 43 new WebappRegistry.FetchWebappDataStorageCallback() { |
gone
2016/04/07 19:10:44
To avoid the extra indentation, could you create t
dominickn
2016/04/08 01:10:45
Done.
| |
37 int intentSource = DocumentMetricIds.STARTED_BY_WINDOW_OPEN; | 44 @Override |
45 public void onWebappDataStorageRetrieved(final WebappDataSto rage storage) { | |
46 final TabDelegate tabDelegate = new TabDelegate(incognit o); | |
47 if (storage == null || !storage.wasLaunchedRecently()) { | |
48 // TODO(peter): Determine the intent source based on the |disposition| | |
49 // with which the tab is being launched. Right now t his is gated by a | |
50 // check in the native implementation. | |
51 int intentSource = DocumentMetricIds.STARTED_BY_WIND OW_OPEN; | |
38 | 52 |
39 LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK ); | 53 LoadUrlParams loadUrlParams = new LoadUrlParams(url, |
40 loadUrlParams.setPostData(postData); | 54 PageTransition.LINK); |
41 loadUrlParams.setVerbatimHeaders(extraHeaders); | 55 loadUrlParams.setPostData(postData); |
42 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy)); | 56 loadUrlParams.setVerbatimHeaders(extraHeaders); |
57 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy)); | |
43 | 58 |
44 AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlP arams, requestId); | 59 AsyncTabCreationParams asyncParams = new AsyncTabCre ationParams( |
45 asyncParams.setDocumentStartedBy(intentSource); | 60 loadUrlParams, requestId); |
61 asyncParams.setDocumentStartedBy(intentSource); | |
46 | 62 |
47 TabDelegate tabDelegate = new TabDelegate(incognito); | 63 tabDelegate.createNewTab( |
48 tabDelegate.createNewTab( | 64 asyncParams, TabLaunchType.FROM_CHROME_UI, T ab.INVALID_TAB_ID); |
49 asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID); | 65 } else { |
66 // The URL is within the scope of a recently launche d standalone-capable | |
67 // web app on the homescreen, so open it in the stan dalone frame. | |
68 // WebappDataStorage.createWebappLaunchIntent should not be run on the | |
69 // UI thread as it contains a Bitmap decode operatio n, so the intent | |
70 // creation is wrapped in an AsyncTask. | |
71 // | |
72 // This currently assumes that the only source is no tifications; any | |
73 // future use which adds a different source will nee d to change this. | |
74 new AsyncTask<Void, Void, Intent>() { | |
75 @Override | |
76 protected final Intent doInBackground(Void... no thing) { | |
77 return storage.createWebappLaunchIntent(); | |
78 } | |
79 | |
80 @Override | |
81 protected final void onPostExecute(Intent intent ) { | |
82 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, | |
83 ShortcutSource.NOTIFICATION); | |
84 tabDelegate.createNewStandaloneFrame(intent) ; | |
85 } | |
86 }.execute(); | |
87 } | |
88 } | |
89 } | |
90 ); | |
91 | |
50 } | 92 } |
51 } | 93 } |
OLD | NEW |