| 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 4e34d936ccdf456a3faa1880d0a55f90b309b9da..96c69211bfaccaae228056555b88fc95c4d9124c 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.os.AsyncTask;
|
| @@ -59,9 +60,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) {
|
| @@ -76,22 +77,50 @@ public class ServiceTabLauncher {
|
| return;
|
| }
|
|
|
| - final TabDelegate tabDelegate = new TabDelegate(incognito);
|
| -
|
| - // 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|. */
|
| + 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.
|
| + WebApkValidator.IsOwnedCheckCallback callback = new WebApkValidator.IsOwnedCheckCallback() {
|
| + @Override
|
| + public void onIsOwnedChecked(boolean isOwned) {
|
| + if (isOwned) {
|
| + 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);
|
| + }
|
| + };
|
| + WebApkValidator.isOwnedWebApkAsync(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.
|
| final WebappDataStorage storage =
|
| WebappRegistry.getInstance().getWebappDataStorageForUrl(url);
|
| @@ -101,40 +130,48 @@ public class ServiceTabLauncher {
|
| // 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);
|
| - } 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. An AsyncTask is
|
| - // used because WebappDataStorage.createWebappLaunchIntent contains a Bitmap
|
| - // decode operation and should not be run on the UI thread.
|
| - //
|
| - // This currently assumes that the only source is notifications; any future use
|
| - // which adds a different source will need to change this.
|
| - new AsyncTask<Void, Void, Intent>() {
|
| - @Override
|
| - protected final Intent doInBackground(Void... nothing) {
|
| - return storage.createWebappLaunchIntent();
|
| - }
|
| -
|
| - @Override
|
| - protected final void onPostExecute(Intent intent) {
|
| - // Replace the web app URL with the URL from the notification. This is
|
| - // within the webapp's scope, so it is valid.
|
| - intent.putExtra(ShortcutHelper.EXTRA_URL, url);
|
| - intent.putExtra(ShortcutHelper.EXTRA_SOURCE,
|
| - ShortcutSource.NOTIFICATION);
|
| - tabDelegate.createNewStandaloneFrame(intent);
|
| - }
|
| - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
| + launchTab(
|
| + requestId, incognito, url, referrerUrl, referrerPolicy, extraHeaders, postData);
|
| + return;
|
| }
|
| +
|
| + // 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. An AsyncTask is
|
| + // used because WebappDataStorage.createWebappLaunchIntent contains a Bitmap
|
| + // decode operation and should not be run on the UI thread.
|
| + //
|
| + // This currently assumes that the only source is notifications; any future use
|
| + // which adds a different source will need to change this.
|
| + new AsyncTask<Void, Void, Intent>() {
|
| + @Override
|
| + protected final Intent doInBackground(Void... nothing) {
|
| + return storage.createWebappLaunchIntent();
|
| + }
|
| +
|
| + @Override
|
| + protected final void onPostExecute(Intent intent) {
|
| + // Replace the web app URL with the URL from the notification. This is
|
| + // within the 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);
|
| + }
|
| + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
| + }
|
| +
|
| + /** 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);
|
| }
|
|
|
| /**
|
|
|