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