Commit 8c10ae7e authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Launch WebAPK if notification opens URL within WebAPK scope

BUG=609122

Review-Url: https://codereview.chromium.org/2010633004
Cr-Commit-Position: refs/heads/master@{#397853}
parent dd7060eb
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import org.chromium.base.CommandLine;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
......@@ -19,6 +20,8 @@ import org.chromium.components.service_tab_launcher.ServiceTabLauncher;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.Referrer;
import org.chromium.ui.base.PageTransition;
import org.chromium.webapk.lib.client.NavigationClient;
import org.chromium.webapk.lib.client.WebApkValidator;
/**
* Service Tab Launcher implementation for Chrome. Provides the ability for Android Services
......@@ -41,9 +44,17 @@ public class ChromeServiceTabLauncher extends ServiceTabLauncher {
final int referrerPolicy, final String extraHeaders, final byte[] postData) {
final TabDelegate tabDelegate = new TabDelegate(incognito);
// Try and retrieve a WebappDataStorage object with scope corresponding to the URL to be
// opened. If one is found, and it has been opened recently, create an intent to launch the
// URL in a standalone web app frame. Otherwise, open the URL in a tab.
// 1. Launch WebAPK if one matches the target URL.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
String webApkPackageName = WebApkValidator.queryWebApkPackage(context, url);
if (webApkPackageName != null) {
NavigationClient.launchWebApk(context, webApkPackageName, url);
return;
}
}
// 2. Launch WebappActivity if one matches the target URL and was opened recently.
// Otherwise, open the URL in a tab.
FetchWebappDataStorageCallback callback = new FetchWebappDataStorageCallback() {
@Override
public void onWebappDataStorageRetrieved(final WebappDataStorage storage) {
......
......@@ -8,6 +8,7 @@ import("//chrome/android/webapk/libs/runtime_library_version.gni")
android_library("client") {
java_files = [
"src/org/chromium/webapk/lib/client/DexOptimizer.java",
"src/org/chromium/webapk/lib/client/NavigationClient.java",
"src/org/chromium/webapk/lib/client/WebApkServiceConnectionManager.java",
"src/org/chromium/webapk/lib/client/WebApkValidator.java",
]
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.webapk.lib.client;
import android.content.Context;
import android.content.Intent;
/**
* NavigationClient provides an API to launch a WebAPK.
*/
public class NavigationClient {
/**
* Launches a WebAPK.
* @param context Application context.
* @param webApkPackageName Package name of the WebAPK to launch.
* @param url URL to navigate WebAPK to.
*/
public static void launchWebApk(Context context, String webApkPackageName, String url) {
Intent intent;
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (Exception e) {
return;
}
intent.setPackage(webApkPackageName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment