Index: chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
index c802135a5303df580a024e02a15553d8eec8776e..216b1c521a7a91fad9dfc4394e5ee83782202c57 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java |
@@ -5,6 +5,7 @@ |
package org.chromium.chrome.browser; |
import android.app.Activity; |
+import android.content.Context; |
import android.content.Intent; |
import android.net.Uri; |
import android.provider.Browser; |
@@ -21,6 +22,7 @@ import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
+import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
import org.chromium.chrome.browser.webapps.WebappDataStorage; |
import org.chromium.chrome.browser.webapps.WebappRegistry; |
import org.chromium.content_public.browser.LoadUrlParams; |
@@ -29,6 +31,7 @@ import org.chromium.content_public.common.Referrer; |
import org.chromium.content_public.common.ResourceRequestBody; |
import org.chromium.ui.base.PageTransition; |
import org.chromium.ui.mojom.WindowOpenDisposition; |
+import org.chromium.webapk.lib.client.WebApkIdentityServiceClient; |
import org.chromium.webapk.lib.client.WebApkNavigationClient; |
import org.chromium.webapk.lib.client.WebApkValidator; |
@@ -58,9 +61,9 @@ public class ServiceTabLauncher { |
* @param postData Post-data to include in the tab URL's request body. |
*/ |
@CalledByNative |
- public static void launchTab(final int requestId, final boolean incognito, final String url, |
- final int disposition, final String referrerUrl, final int referrerPolicy, |
- final String extraHeaders, final ResourceRequestBody postData) { |
+ public static void launchTab(final int requestId, boolean incognito, String url, |
+ int disposition, String referrerUrl, int referrerPolicy, String extraHeaders, |
+ ResourceRequestBody postData) { |
// Open popup window in custom tab. |
// Note that this is used by PaymentRequestEvent.openWindow(). |
if (disposition == WindowOpenDisposition.NEW_POPUP) { |
@@ -75,38 +78,63 @@ public class ServiceTabLauncher { |
return; |
} |
- // 1. Launch WebAPK if one matches the target URL. |
String webApkPackageName = |
WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url); |
- if (webApkPackageName != null) { |
- Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( |
- webApkPackageName, url, true /* forceNavigation */); |
- if (intent != null) { |
- intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION); |
- ContextUtils.getApplicationContext().startActivity(intent); |
- } |
+ if (webApkPackageName == null) { |
+ launchTabOrWebapp( |
+ requestId, incognito, url, referrerUrl, referrerPolicy, extraHeaders, postData); |
return; |
} |
- // 2. Launch WebappActivity if one matches the target URL and was opened recently. |
+ tryLaunchWebApk(webApkPackageName, requestId, incognito, url, referrerUrl, referrerPolicy, |
+ extraHeaders, postData); |
+ } |
+ |
+ /** Launches a WebAPK if it is owned by the Chrome. Otherwise, launches a tab for the |url|. */ |
pkotwicz
2017/07/19 16:09:13
Nits:
"owned by" -> "backed by"
"the Chrome" -> "C
Xi Han
2017/07/21 20:36:33
Done.
|
+ private static void tryLaunchWebApk(final String webApkPackageName, final int requestId, |
+ final boolean incognito, final String url, final String referrerUrl, |
+ final int referrerPolicy, final String extraHeaders, |
+ final ResourceRequestBody postData) { |
+ final Context context = ContextUtils.getApplicationContext(); |
+ |
+ // Launch WebAPK if one matches the target URL. |
pkotwicz
2017/07/19 16:09:13
This comment is no longer valid
|
+ WebApkIdentityServiceClient.CheckBacksWebApkCallback callback = |
+ new WebApkIdentityServiceClient.CheckBacksWebApkCallback() { |
+ @Override |
+ public void onChecked(boolean isValid) { |
+ if (isValid) { |
+ Intent intent = WebApkNavigationClient.createLaunchWebApkIntent( |
+ webApkPackageName, url, true /* forceNavigation */); |
+ if (intent != null) { |
+ intent.putExtra( |
+ ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION); |
+ context.startActivity(intent); |
+ return; |
+ } |
+ } |
+ launchTab(requestId, incognito, url, referrerUrl, referrerPolicy, |
+ extraHeaders, postData); |
pkotwicz
2017/07/19 16:09:13
Sorry for flip flopping. We should call launchTabO
Xi Han
2017/07/21 20:36:33
Acknowledged.
|
+ } |
+ }; |
+ ChromeWebApkHost.checkChromeBacksWebApkAsync(context, webApkPackageName, callback); |
+ } |
+ |
+ /** Launches the WebappActivity or a tab for the |url|. */ |
+ private static void launchTabOrWebapp(int requestId, final boolean incognito, final String url, |
+ String referrerUrl, int referrerPolicy, String extraHeaders, |
+ ResourceRequestBody postData) { |
+ // Launch WebappActivity if one matches the target URL and was opened recently. |
// Otherwise, open the URL in a tab. |
WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorageForUrl(url); |
- TabDelegate tabDelegate = new TabDelegate(incognito); |
// Open a new tab if: |
// - We did not find a WebappDataStorage corresponding to this URL. |
// OR |
// - The WebappDataStorage hasn't been opened recently enough. |
if (storage == null || !storage.wasUsedRecently()) { |
- LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK); |
- loadUrlParams.setPostData(postData); |
- loadUrlParams.setVerbatimHeaders(extraHeaders); |
- loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy)); |
- |
- AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams, |
- requestId); |
- tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, |
- Tab.INVALID_TAB_ID); |
+ launchTab( |
+ requestId, incognito, url, referrerUrl, referrerPolicy, extraHeaders, postData); |
+ return; |
} else { |
// The URL is within the scope of a recently launched standalone-capable web app |
// on the home screen, so open it a standalone web app frame. |
@@ -118,10 +146,25 @@ public class ServiceTabLauncher { |
// webapp's scope, so it is valid. |
intent.putExtra(ShortcutHelper.EXTRA_URL, url); |
intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION); |
+ TabDelegate tabDelegate = new TabDelegate(incognito); |
tabDelegate.createNewStandaloneFrame(intent); |
} |
} |
+ /** Launches a tab for the |url|. */ |
+ private static void launchTab(int requestId, boolean incognito, String url, String referrerUrl, |
+ int referrerPolicy, String extraHeaders, ResourceRequestBody postData) { |
+ TabDelegate tabDelegate = new TabDelegate(incognito); |
+ |
+ LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK); |
+ loadUrlParams.setPostData(postData); |
+ loadUrlParams.setVerbatimHeaders(extraHeaders); |
+ loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy)); |
+ |
+ AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams, requestId); |
+ tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID); |
+ } |
+ |
/** |
* Creates a popup custom tab to open the url. The popup tab is animated in from bottom to top |
* and out from top to bottom. |