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

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

Issue 1867543002: Enable deep-linking from notifications for recently used web apps on the Android home screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bulk-webappdatastorage
Patch Set: Address nits Created 4 years, 8 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 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;
18 import org.chromium.chrome.browser.webapps.WebappRegistry.FetchWebappDataStorage Callback;
14 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; 19 import org.chromium.components.service_tab_launcher.ServiceTabLauncher;
15 import org.chromium.content_public.browser.LoadUrlParams; 20 import org.chromium.content_public.browser.LoadUrlParams;
16 import org.chromium.content_public.common.Referrer; 21 import org.chromium.content_public.common.Referrer;
17 import org.chromium.ui.base.PageTransition; 22 import org.chromium.ui.base.PageTransition;
18 23
19 /** 24 /**
20 * Service Tab Launcher implementation for Chrome. Provides the ability for Andr oid Services 25 * 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. 26 * running in Chrome to launch URLs, without having access to an activity.
22 * 27 *
23 * This class is referred to from the ServiceTabLauncher implementation in Chrom ium using a 28 * 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 29 * meta-data value in the Android manifest file. The ServiceTabLauncher class ha s more
25 * documentation about why this is necessary. 30 * documentation about why this is necessary.
26 * 31 *
32 * URLs within the scope of a recently launched standalone-capable web app on th e Android home
33 * screen are launched in the standalone web app frame.
34 *
27 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove reflection calls 35 * TODO(peter): after upstreaming, merge this with ServiceTabLauncher and remove reflection calls
28 * in ServiceTabLauncher. 36 * in ServiceTabLauncher.
29 */ 37 */
30 public class ChromeServiceTabLauncher extends ServiceTabLauncher { 38 public class ChromeServiceTabLauncher extends ServiceTabLauncher {
31 @Override 39 @Override
32 public void launchTab(Context context, int requestId, boolean incognito, Str ing url, 40 public void launchTab(final Context context, final int requestId, final bool ean incognito,
33 int disposition, String referrerUrl, int referrerPolic y, 41 final String url, final int disposition, final String referrerUrl,
34 String extraHeaders, byte[] postData) { 42 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 43 final TabDelegate tabDelegate = new TabDelegate(incognito);
36 // tab is being launched. Right now this is gated by a check in the nati ve implementation.
37 int intentSource = DocumentMetricIds.STARTED_BY_WINDOW_OPEN;
38 44
39 LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK ); 45 // Try and retrieve a WebappDataStorage object with scope corresponding to the URL to be
40 loadUrlParams.setPostData(postData); 46 // opened. If one is found, and it has been opened recently, create an i ntent to launch the
41 loadUrlParams.setVerbatimHeaders(extraHeaders); 47 // URL in a standalone web app frame. Otherwise, open the URL in a tab.
42 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy)); 48 FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCall back() {
49 @Override
50 public void onWebappDataStorageRetrieved(final WebappDataStorage sto rage) {
51 // If we do not find a WebappDataStorage corresponding to this U RL, or if it hasn't
52 // been opened recently enough, open the URL in a tab.
53 if (storage == null || !storage.wasLaunchedRecently()) {
54 // TODO(peter): Determine the intent source based on the |di sposition| with
55 // which the tab is being launched. Right now this is gated by a check in the
56 // native implementation.
57 int intentSource = DocumentMetricIds.STARTED_BY_WINDOW_OPEN;
43 58
44 AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlP arams, requestId); 59 LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTra nsition.LINK);
45 asyncParams.setDocumentStartedBy(intentSource); 60 loadUrlParams.setPostData(postData);
61 loadUrlParams.setVerbatimHeaders(extraHeaders);
62 loadUrlParams.setReferrer(new Referrer(referrerUrl, referrer Policy));
46 63
47 TabDelegate tabDelegate = new TabDelegate(incognito); 64 AsyncTabCreationParams asyncParams = new AsyncTabCreationPar ams(loadUrlParams,
48 tabDelegate.createNewTab( 65 requestId);
49 asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID); 66 asyncParams.setDocumentStartedBy(intentSource);
67
68 tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHR OME_UI,
69 Tab.INVALID_TAB_ID);
70 } else {
71 // The URL is within the scope of a recently launched standa lone-capable web app
72 // on the home screen, so open it a standalone web app frame . An AsyncTask is
73 // used because WebappDataStorage.createWebappLaunchIntent c ontains a Bitmap
74 // decode operation and should not be run on the UI thread.
75 //
76 // This currently assumes that the only source is notificati ons; any future use
77 // which adds a different source will need to change this.
78 new AsyncTask<Void, Void, Intent>() {
79 @Override
80 protected final Intent doInBackground(Void... nothing) {
81 return storage.createWebappLaunchIntent();
82 }
83
84 @Override
85 protected final void onPostExecute(Intent intent) {
86 intent.putExtra(ShortcutHelper.EXTRA_SOURCE,
87 ShortcutSource.NOTIFICATION);
88 tabDelegate.createNewStandaloneFrame(intent);
89 }
90 }.execute();
91 }
92 }
93 };
94 WebappRegistry.getWebappDataStorageForUrl(context, url, callback);
50 } 95 }
51 } 96 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698