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.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
13 import org.chromium.chrome.browser.tab.Tab; | 13 import org.chromium.chrome.browser.tab.Tab; |
14 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 14 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
15 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; | 15 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
16 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 16 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
17 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 17 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
18 import org.chromium.chrome.browser.webapps.WebappRegistry; | 18 import org.chromium.chrome.browser.webapps.WebappRegistry; |
19 import org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorage
Callback; | |
20 import org.chromium.content_public.browser.LoadUrlParams; | 19 import org.chromium.content_public.browser.LoadUrlParams; |
21 import org.chromium.content_public.browser.WebContents; | 20 import org.chromium.content_public.browser.WebContents; |
22 import org.chromium.content_public.common.Referrer; | 21 import org.chromium.content_public.common.Referrer; |
23 import org.chromium.content_public.common.ResourceRequestBody; | 22 import org.chromium.content_public.common.ResourceRequestBody; |
24 import org.chromium.ui.base.PageTransition; | 23 import org.chromium.ui.base.PageTransition; |
25 import org.chromium.webapk.lib.client.WebApkNavigationClient; | 24 import org.chromium.webapk.lib.client.WebApkNavigationClient; |
26 import org.chromium.webapk.lib.client.WebApkValidator; | 25 import org.chromium.webapk.lib.client.WebApkValidator; |
27 | 26 |
28 /** | 27 /** |
29 * Tab Launcher to be used to launch new tabs from background Android Services, | 28 * Tab Launcher to be used to launch new tabs from background Android Services, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (intent != null) { | 66 if (intent != null) { |
68 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.
NOTIFICATION); | 67 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.
NOTIFICATION); |
69 context.startActivity(intent); | 68 context.startActivity(intent); |
70 return; | 69 return; |
71 } | 70 } |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 // 2. Launch WebappActivity if one matches the target URL and was opened
recently. | 74 // 2. Launch WebappActivity if one matches the target URL and was opened
recently. |
76 // Otherwise, open the URL in a tab. | 75 // Otherwise, open the URL in a tab. |
77 FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCall
back() { | 76 final WebappDataStorage storage = |
78 @Override | 77 WebappRegistry.getInstance().getWebappDataStorageForUrl(url); |
79 public void onWebappDataStorageRetrieved(final WebappDataStorage sto
rage) { | |
80 // If we do not find a WebappDataStorage corresponding to this U
RL, or if it hasn't | |
81 // been opened recently enough, open the URL in a tab. | |
82 if (storage == null || !storage.wasLaunchedRecently()) { | |
83 LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTra
nsition.LINK); | |
84 loadUrlParams.setPostData(postData); | |
85 loadUrlParams.setVerbatimHeaders(extraHeaders); | |
86 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrer
Policy)); | |
87 | 78 |
88 AsyncTabCreationParams asyncParams = new AsyncTabCreationPar
ams(loadUrlParams, | 79 // If we do not find a WebappDataStorage corresponding to this URL, or i
f it hasn't |
89 requestId); | 80 // been opened recently enough, open the URL in a tab. |
90 tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHR
OME_UI, | 81 if (storage == null || !storage.wasLaunchedRecently()) { |
91 Tab.INVALID_TAB_ID); | 82 LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.
LINK); |
92 } else { | 83 loadUrlParams.setPostData(postData); |
93 // The URL is within the scope of a recently launched standa
lone-capable web app | 84 loadUrlParams.setVerbatimHeaders(extraHeaders); |
94 // on the home screen, so open it a standalone web app frame
. An AsyncTask is | 85 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy))
; |
95 // used because WebappDataStorage.createWebappLaunchIntent c
ontains a Bitmap | |
96 // decode operation and should not be run on the UI thread. | |
97 // | |
98 // This currently assumes that the only source is notificati
ons; any future use | |
99 // which adds a different source will need to change this. | |
100 new AsyncTask<Void, Void, Intent>() { | |
101 @Override | |
102 protected final Intent doInBackground(Void... nothing) { | |
103 return storage.createWebappLaunchIntent(); | |
104 } | |
105 | 86 |
106 @Override | 87 AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(load
UrlParams, |
107 protected final void onPostExecute(Intent intent) { | 88 requestId); |
108 // Replace the web app URL with the URL from the not
ification. This is | 89 tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, |
109 // within the webapp's scope, so it is valid. | 90 Tab.INVALID_TAB_ID); |
110 intent.putExtra(ShortcutHelper.EXTRA_URL, url); | 91 } else { |
111 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, | 92 // The URL is within the scope of a recently launched standalone-cap
able web app |
112 ShortcutSource.NOTIFICATION); | 93 // on the home screen, so open it a standalone web app frame. An Asy
ncTask is |
113 tabDelegate.createNewStandaloneFrame(intent); | 94 // used because WebappDataStorage.createWebappLaunchIntent contains
a Bitmap |
114 } | 95 // decode operation and should not be run on the UI thread. |
115 }.execute(); | 96 // |
| 97 // This currently assumes that the only source is notifications; any
future use |
| 98 // which adds a different source will need to change this. |
| 99 new AsyncTask<Void, Void, Intent>() { |
| 100 @Override |
| 101 protected final Intent doInBackground(Void... nothing) { |
| 102 return storage.createWebappLaunchIntent(); |
116 } | 103 } |
117 } | 104 |
118 }; | 105 @Override |
119 WebappRegistry.getWebappDataStorageForUrl(url, callback); | 106 protected final void onPostExecute(Intent intent) { |
| 107 // Replace the web app URL with the URL from the notificatio
n. This is |
| 108 // within the webapp's scope, so it is valid. |
| 109 intent.putExtra(ShortcutHelper.EXTRA_URL, url); |
| 110 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, |
| 111 ShortcutSource.NOTIFICATION); |
| 112 tabDelegate.createNewStandaloneFrame(intent); |
| 113 } |
| 114 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 115 } |
120 } | 116 } |
121 | 117 |
122 /** | 118 /** |
123 * To be called by the activity when the WebContents for |requestId| has bee
n created, or has | 119 * To be called by the activity when the WebContents for |requestId| has bee
n created, or has |
124 * been recycled from previous use. The |webContents| must not yet have star
ted provisional | 120 * been recycled from previous use. The |webContents| must not yet have star
ted provisional |
125 * load for the main frame. | 121 * load for the main frame. |
126 * | 122 * |
127 * @param requestId Id of the tab launching request which has been fulfilled
. | 123 * @param requestId Id of the tab launching request which has been fulfilled
. |
128 * @param webContents The WebContents instance associated with this request. | 124 * @param webContents The WebContents instance associated with this request. |
129 */ | 125 */ |
130 public static void onWebContentsForRequestAvailable(int requestId, WebConten
ts webContents) { | 126 public static void onWebContentsForRequestAvailable(int requestId, WebConten
ts webContents) { |
131 nativeOnWebContentsForRequestAvailable(requestId, webContents); | 127 nativeOnWebContentsForRequestAvailable(requestId, webContents); |
132 } | 128 } |
133 | 129 |
134 private static native void nativeOnWebContentsForRequestAvailable( | 130 private static native void nativeOnWebContentsForRequestAvailable( |
135 int requestId, WebContents webContents); | 131 int requestId, WebContents webContents); |
136 } | 132 } |
OLD | NEW |