Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ServiceTabLauncher.java

Issue 2974573002: Refactor WebApkServiceConnectionManager. (Closed)
Patch Set: pkotwicz@‘s comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2709a682e0aab869108e705f9e673b444d63fefc 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,20 +78,51 @@ 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);
- }
+ tryLaunchWebApk(webApkPackageName, requestId, incognito, url, referrerUrl,
+ referrerPolicy, extraHeaders, postData);
return;
}
- // 2. Launch WebappActivity if one matches the target URL and was opened recently.
+ launchTabOrWebapp(
+ requestId, incognito, url, referrerUrl, referrerPolicy, extraHeaders, postData);
+ }
+
+ /** Launches a WebAPK if it is backed by 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();
+
+ WebApkIdentityServiceClient.CheckBrowserBacksWebApkCallback callback =
+ new WebApkIdentityServiceClient.CheckBrowserBacksWebApkCallback() {
+ @Override
+ public void onChecked(boolean doesBrowserBackWebApk) {
+ if (doesBrowserBackWebApk) {
+ Intent intent = WebApkNavigationClient.createLaunchWebApkIntent(
+ webApkPackageName, url, true /* forceNavigation */);
+ if (intent != null) {
+ intent.putExtra(
+ ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
+ context.startActivity(intent);
+ return;
+ }
+ }
+ launchTabOrWebapp(requestId, incognito, url, referrerUrl, referrerPolicy,
+ extraHeaders, postData);
+ }
+ };
+ ChromeWebApkHost.checkChromeBacksWebApkAsync(webApkPackageName, callback);
+ }
+
+ /** Launches 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);
@@ -105,8 +139,7 @@ public class ServiceTabLauncher {
AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams,
requestId);
- tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI,
- Tab.INVALID_TAB_ID);
+ 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.

Powered by Google App Engine
This is Rietveld 408576698