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.app.Activity; |
7 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.net.Uri; |
8 import android.os.AsyncTask; | 10 import android.os.AsyncTask; |
| 11 import android.provider.Browser; |
| 12 import android.support.annotation.Nullable; |
| 13 import android.support.customtabs.CustomTabsIntent; |
9 | 14 |
| 15 import org.chromium.base.ApplicationStatus; |
10 import org.chromium.base.ContextUtils; | 16 import org.chromium.base.ContextUtils; |
| 17 import org.chromium.base.ThreadUtils; |
11 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
| 19 import org.chromium.chrome.R; |
12 import org.chromium.chrome.browser.tab.Tab; | 20 import org.chromium.chrome.browser.tab.Tab; |
13 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 21 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
14 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; | 22 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
15 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 23 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
16 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; | 24 import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
17 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 25 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
18 import org.chromium.chrome.browser.webapps.WebappRegistry; | 26 import org.chromium.chrome.browser.webapps.WebappRegistry; |
19 import org.chromium.content_public.browser.LoadUrlParams; | 27 import org.chromium.content_public.browser.LoadUrlParams; |
20 import org.chromium.content_public.browser.WebContents; | 28 import org.chromium.content_public.browser.WebContents; |
21 import org.chromium.content_public.common.Referrer; | 29 import org.chromium.content_public.common.Referrer; |
22 import org.chromium.content_public.common.ResourceRequestBody; | 30 import org.chromium.content_public.common.ResourceRequestBody; |
23 import org.chromium.ui.base.PageTransition; | 31 import org.chromium.ui.base.PageTransition; |
| 32 import org.chromium.ui.mojom.WindowOpenDisposition; |
24 import org.chromium.webapk.lib.client.WebApkNavigationClient; | 33 import org.chromium.webapk.lib.client.WebApkNavigationClient; |
25 import org.chromium.webapk.lib.client.WebApkValidator; | 34 import org.chromium.webapk.lib.client.WebApkValidator; |
26 | 35 |
27 /** | 36 /** |
28 * Tab Launcher to be used to launch new tabs from background Android Services, | 37 * 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 | 38 * when it is not known whether an activity is available. It will send an intent
to launch the |
30 * activity. | 39 * activity. |
31 * | 40 * |
32 * URLs within the scope of a recently launched standalone-capable web app on th
e Android home | 41 * 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. | 42 * screen are launched in the standalone web app frame. |
34 */ | 43 */ |
35 public class ServiceTabLauncher { | 44 public class ServiceTabLauncher { |
36 // Name of the extra containing the Id of a tab launch request id. | 45 // Name of the extra containing the Id of a tab launch request id. |
37 public static final String LAUNCH_REQUEST_ID_EXTRA = | 46 public static final String LAUNCH_REQUEST_ID_EXTRA = |
38 "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; | 47 "org.chromium.chrome.browser.ServiceTabLauncher.LAUNCH_REQUEST_ID"; |
39 | 48 |
40 /** | 49 /** |
41 * Launches the browser activity and launches a tab for |url|. | 50 * Launches the browser activity and launches a tab for |url|. |
42 * @param requestId Id of the request for launching this tab. | 51 * |
43 * @param incognito Whether the tab should be launched in incognito mode. | 52 * @param requestId Id of the request for launching this tab. |
44 * @param url The URL which should be launched in a tab. | 53 * @param incognito Whether the tab should be launched in incognito mod
e. |
45 * @param disposition The disposition requested by the navigation source. | 54 * @param url The URL which should be launched in a tab. |
46 * @param referrerUrl URL of the referrer which is opening the page. | 55 * @param disposition The disposition requested by the navigation source. |
| 56 * @param referrerUrl URL of the referrer which is opening the page. |
47 * @param referrerPolicy The referrer policy to consider when applying the r
eferrer. | 57 * @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. | 58 * @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. | 59 * @param postData Post-data to include in the tab URL's request body. |
50 */ | 60 */ |
51 @CalledByNative | 61 @CalledByNative |
52 public static void launchTab(final int requestId, final boolean incognito, f
inal String url, | 62 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, | 63 final int disposition, final String referrerUrl, final int referrerP
olicy, |
54 final String extraHeaders, final ResourceRequestBody postData) { | 64 final String extraHeaders, final ResourceRequestBody postData) { |
| 65 // Open popup window in custom tab. |
| 66 // Note that this is used by PaymentRequestEvent.openWindow(). |
| 67 if (disposition == WindowOpenDisposition.NEW_POPUP) { |
| 68 if (!createPopupCustomTab(requestId, url, incognito)) { |
| 69 ThreadUtils.postOnUiThread(new Runnable() { |
| 70 @Override |
| 71 public void run() { |
| 72 onWebContentsForRequestAvailable(requestId, null); |
| 73 } |
| 74 }); |
| 75 } |
| 76 return; |
| 77 } |
| 78 |
55 final TabDelegate tabDelegate = new TabDelegate(incognito); | 79 final TabDelegate tabDelegate = new TabDelegate(incognito); |
56 | 80 |
57 // 1. Launch WebAPK if one matches the target URL. | 81 // 1. Launch WebAPK if one matches the target URL. |
58 if (ChromeWebApkHost.isEnabled()) { | 82 if (ChromeWebApkHost.isEnabled()) { |
59 String webApkPackageName = | 83 String webApkPackageName = |
60 WebApkValidator.queryWebApkPackage(ContextUtils.getApplicati
onContext(), url); | 84 WebApkValidator.queryWebApkPackage(ContextUtils.getApplicati
onContext(), url); |
61 if (webApkPackageName != null) { | 85 if (webApkPackageName != null) { |
62 Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( | 86 Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( |
63 webApkPackageName, url, true /* forceNavigation */); | 87 webApkPackageName, url, true /* forceNavigation */); |
64 if (intent != null) { | 88 if (intent != null) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 intent.putExtra(ShortcutHelper.EXTRA_URL, url); | 136 intent.putExtra(ShortcutHelper.EXTRA_URL, url); |
113 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, | 137 intent.putExtra(ShortcutHelper.EXTRA_SOURCE, |
114 ShortcutSource.NOTIFICATION); | 138 ShortcutSource.NOTIFICATION); |
115 tabDelegate.createNewStandaloneFrame(intent); | 139 tabDelegate.createNewStandaloneFrame(intent); |
116 } | 140 } |
117 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 141 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
118 } | 142 } |
119 } | 143 } |
120 | 144 |
121 /** | 145 /** |
| 146 * Creates a popup custom tab to open the url. The popup tab is animated in
from bottom to top |
| 147 * and out from top to bottom. |
| 148 * Note that this is used by PaymentRequestEvent.openWindow(). |
| 149 * |
| 150 * @param requestId The tab launch request ID from the {@link ServiceTabLa
uncher}. |
| 151 * @param url The url to open in the new tab. |
| 152 */ |
| 153 private static boolean createPopupCustomTab(int requestId, String url, boole
an incognito) { |
| 154 // Do not open the popup custom tab if the chrome activity is not in the
forground. |
| 155 Activity lastTrackedActivity = ApplicationStatus.getLastTrackedFocusedAc
tivity(); |
| 156 if (!(lastTrackedActivity instanceof ChromeActivity)) return false; |
| 157 |
| 158 CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); |
| 159 builder.setShowTitle(true); |
| 160 builder.setStartAnimations(lastTrackedActivity, R.anim.slide_in_up, 0); |
| 161 builder.setExitAnimations(lastTrackedActivity, 0, R.anim.slide_out_down)
; |
| 162 CustomTabsIntent customTabsIntent = builder.build(); |
| 163 customTabsIntent.intent.setPackage(ContextUtils.getApplicationContext().
getPackageName()); |
| 164 customTabsIntent.intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EX
TRA, requestId); |
| 165 customTabsIntent.intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_
TAB, incognito); |
| 166 customTabsIntent.intent.putExtra(Browser.EXTRA_APPLICATION_ID, |
| 167 ContextUtils.getApplicationContext().getPackageName()); |
| 168 |
| 169 customTabsIntent.launchUrl(lastTrackedActivity, Uri.parse(url)); |
| 170 |
| 171 return true; |
| 172 } |
| 173 |
| 174 /** |
122 * To be called by the activity when the WebContents for |requestId| has bee
n created, or has | 175 * 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 | 176 * been recycled from previous use. The |webContents| must not yet have star
ted provisional |
124 * load for the main frame. | 177 * load for the main frame. |
| 178 * The |webContents| could be null if the request is failed. |
125 * | 179 * |
126 * @param requestId Id of the tab launching request which has been fulfilled
. | 180 * @param requestId Id of the tab launching request which has been fulfilled
. |
127 * @param webContents The WebContents instance associated with this request. | 181 * @param webContents The WebContents instance associated with this request. |
128 */ | 182 */ |
129 public static void onWebContentsForRequestAvailable(int requestId, WebConten
ts webContents) { | 183 public static void onWebContentsForRequestAvailable( |
| 184 int requestId, @Nullable WebContents webContents) { |
130 nativeOnWebContentsForRequestAvailable(requestId, webContents); | 185 nativeOnWebContentsForRequestAvailable(requestId, webContents); |
131 } | 186 } |
132 | 187 |
133 private static native void nativeOnWebContentsForRequestAvailable( | 188 private static native void nativeOnWebContentsForRequestAvailable( |
134 int requestId, WebContents webContents); | 189 int requestId, WebContents webContents); |
135 } | 190 } |
OLD | NEW |