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.Intent; | 7 import android.content.Intent; |
8 import android.os.AsyncTask; | 8 import android.os.AsyncTask; |
9 import android.support.annotation.Nullable; | |
10 import android.text.TextUtils; | |
9 | 11 |
10 import org.chromium.base.ContextUtils; | 12 import org.chromium.base.ContextUtils; |
13 import org.chromium.base.ThreadUtils; | |
11 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.chrome.browser.tab.Tab; | 15 import org.chromium.chrome.browser.tab.Tab; |
13 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 16 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
14 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; | 17 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
15 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 18 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
16 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; | 19 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
17 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 20 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
18 import org.chromium.chrome.browser.webapps.WebappRegistry; | 21 import org.chromium.chrome.browser.webapps.WebappRegistry; |
19 import org.chromium.content_public.browser.LoadUrlParams; | 22 import org.chromium.content_public.browser.LoadUrlParams; |
20 import org.chromium.content_public.browser.WebContents; | 23 import org.chromium.content_public.browser.WebContents; |
21 import org.chromium.content_public.common.Referrer; | 24 import org.chromium.content_public.common.Referrer; |
22 import org.chromium.content_public.common.ResourceRequestBody; | 25 import org.chromium.content_public.common.ResourceRequestBody; |
23 import org.chromium.ui.base.PageTransition; | 26 import org.chromium.ui.base.PageTransition; |
27 import org.chromium.ui.mojom.WindowOpenDisposition; | |
24 import org.chromium.webapk.lib.client.WebApkNavigationClient; | 28 import org.chromium.webapk.lib.client.WebApkNavigationClient; |
25 import org.chromium.webapk.lib.client.WebApkValidator; | 29 import org.chromium.webapk.lib.client.WebApkValidator; |
26 | 30 |
27 /** | 31 /** |
28 * Tab Launcher to be used to launch new tabs from background Android Services, | 32 * Tab Launcher to be used to launch new tabs from background Android Services, |
29 * when it is not known whether an activity is available. It will send an intent to launch the | 33 * when it is not known whether an activity is available. It will send an intent to launch the |
30 * activity. | 34 * activity. |
31 * | 35 * |
32 * URLs within the scope of a recently launched standalone-capable web app on th e Android home | 36 * 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. | 37 * screen are launched in the standalone web app frame. |
34 */ | 38 */ |
35 public class ServiceTabLauncher { | 39 public class ServiceTabLauncher { |
36 // Name of the extra containing the Id of a tab launch request id. | 40 // Name of the extra containing the Id of a tab launch request id. |
37 public static final String LAUNCH_REQUEST_ID_EXTRA = | 41 public static final String LAUNCH_REQUEST_ID_EXTRA = |
38 "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; | 42 "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; |
39 | 43 |
40 /** | 44 /** |
41 * Launches the browser activity and launches a tab for |url|. | 45 * Launches the browser activity and launches a tab for |url|. |
42 * @param requestId Id of the request for launching this tab. | 46 * @param requestId Id of the request for launching this tab. |
43 * @param incognito Whether the tab should be launched in incognito mode. | 47 * @param incognito Whether the tab should be launched in incognito mod e. |
44 * @param url The URL which should be launched in a tab. | 48 * @param redirectUrl The last redirect URL that occured before |url|. |
45 * @param disposition The disposition requested by the navigation source. | 49 * @param url The URL which should be launched in a tab. |
46 * @param referrerUrl URL of the referrer which is opening the page. | 50 * @param disposition The disposition requested by the navigation source. |
51 * @param referrerUrl URL of the referrer which is opening the page. | |
47 * @param referrerPolicy The referrer policy to consider when applying the r eferrer. | 52 * @param referrerPolicy The referrer policy to consider when applying the r eferrer. |
48 * @param extraHeaders Extra headers to apply when requesting the tab's URL. | 53 * @param extraHeaders Extra headers to apply when requesting the tab's UR L. |
49 * @param postData Post-data to include in the tab URL's request body. | 54 * @param postData Post-data to include in the tab URL's request body. |
50 */ | 55 */ |
51 @CalledByNative | 56 @CalledByNative |
52 public static void launchTab(final int requestId, final boolean incognito, f inal String url, | 57 public static void launchTab(final int requestId, final boolean incognito, |
53 final int disposition, final String referrerUrl, final int referrerP olicy, | 58 final String redirectUrl, final String url, final int disposition, |
54 final String extraHeaders, final ResourceRequestBody postData) { | 59 final String referrerUrl, final int referrerPolicy, final String ext raHeaders, |
60 final ResourceRequestBody postData) { | |
55 final TabDelegate tabDelegate = new TabDelegate(incognito); | 61 final TabDelegate tabDelegate = new TabDelegate(incognito); |
56 | 62 |
63 // Open the url in popup custom tab over the tab showing the redirect ur l. | |
64 if (disposition == WindowOpenDisposition.NEW_POPUP && !TextUtils.isEmpty (redirectUrl)) { | |
please use gerrit instead
2017/06/01 17:50:37
I recommend to use an enum for the reason why the
gogerald1
2017/06/02 03:33:11
Acknowledged.
| |
65 if (!tabDelegate.createPopupCustomTab(requestId, redirectUrl, url)) { | |
66 ThreadUtils.postOnUiThread(new Runnable() { | |
67 @Override | |
68 public void run() { | |
69 onWebContentsForRequestAvailable(requestId, null); | |
70 } | |
71 }); | |
72 } | |
73 return; | |
74 } | |
75 | |
57 // 1. Launch WebAPK if one matches the target URL. | 76 // 1. Launch WebAPK if one matches the target URL. |
58 if (ChromeWebApkHost.isEnabled()) { | 77 if (ChromeWebApkHost.isEnabled()) { |
59 String webApkPackageName = | 78 String webApkPackageName = |
60 WebApkValidator.queryWebApkPackage(ContextUtils.getApplicati onContext(), url); | 79 WebApkValidator.queryWebApkPackage(ContextUtils.getApplicati onContext(), url); |
61 if (webApkPackageName != null) { | 80 if (webApkPackageName != null) { |
62 Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( | 81 Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( |
63 webApkPackageName, url, true /* forceNavigation */); | 82 webApkPackageName, url, true /* forceNavigation */); |
64 if (intent != null) { | 83 if (intent != null) { |
65 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource. NOTIFICATION); | 84 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource. NOTIFICATION); |
66 ContextUtils.getApplicationContext().startActivity(intent); | 85 ContextUtils.getApplicationContext().startActivity(intent); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 tabDelegate.createNewStandaloneFrame(intent); | 134 tabDelegate.createNewStandaloneFrame(intent); |
116 } | 135 } |
117 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 136 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
118 } | 137 } |
119 } | 138 } |
120 | 139 |
121 /** | 140 /** |
122 * To be called by the activity when the WebContents for |requestId| has bee n created, or has | 141 * To be called by the activity when the WebContents for |requestId| has bee n created, or has |
123 * been recycled from previous use. The |webContents| must not yet have star ted provisional | 142 * been recycled from previous use. The |webContents| must not yet have star ted provisional |
124 * load for the main frame. | 143 * load for the main frame. |
144 * The |webContents| could be null if the request is failed. | |
125 * | 145 * |
126 * @param requestId Id of the tab launching request which has been fulfilled . | 146 * @param requestId Id of the tab launching request which has been fulfilled . |
127 * @param webContents The WebContents instance associated with this request. | 147 * @param webContents The WebContents instance associated with this request. |
128 */ | 148 */ |
129 public static void onWebContentsForRequestAvailable(int requestId, WebConten ts webContents) { | 149 public static void onWebContentsForRequestAvailable( |
150 int requestId, @Nullable WebContents webContents) { | |
130 nativeOnWebContentsForRequestAvailable(requestId, webContents); | 151 nativeOnWebContentsForRequestAvailable(requestId, webContents); |
131 } | 152 } |
132 | 153 |
133 private static native void nativeOnWebContentsForRequestAvailable( | 154 private static native void nativeOnWebContentsForRequestAvailable( |
134 int requestId, WebContents webContents); | 155 int requestId, WebContents webContents); |
135 } | 156 } |
OLD | NEW |