Commit 4bb5896c authored by zpeng's avatar zpeng Committed by Commit bot

Skip installation process if WebAPK is already installed.

BUG=638614

Review-Url: https://codereview.chromium.org/2363183002
Cr-Commit-Position: refs/heads/master@{#422677}
parent 2a6b869d
...@@ -458,16 +458,22 @@ public class ShortcutHelper { ...@@ -458,16 +458,22 @@ public class ShortcutHelper {
} }
/** /**
* Returns true if WebAPKs are enabled and there is a WebAPK installed which can handle * Returns the package name of the WebAPK if WebAPKs are enabled and there is an installed
* WebAPK which can handle {@link url}. Returns null otherwise.
*/
@CalledByNative
private static String queryWebApkPackage(String url) {
if (!ChromeWebApkHost.isEnabled()) return null;
return WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url);
}
/**
* Returns true if WebAPKs are enabled and there is an installed WebAPK which can handle
* {@link url}. * {@link url}.
*/ */
@CalledByNative @CalledByNative
private static boolean isWebApkInstalled(String url) { private static boolean isWebApkInstalled(String url) {
if (!ChromeWebApkHost.isEnabled()) { return queryWebApkPackage(url) != null;
return false;
}
return WebApkValidator.queryWebApkPackage(ContextUtils.getApplicationContext(), url)
!= null;
} }
/** /**
......
...@@ -191,26 +191,36 @@ bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( ...@@ -191,26 +191,36 @@ bool AppBannerInfoBarDelegateAndroid::AcceptWebApk(
return true; return true;
} }
// Request install the WebAPK. // Check whether the WebAPK has been installed.
install_state_ = INSTALLING; std::string installed_webapk_package_name =
TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL());
webapk::TrackInstallSource(webapk_install_source_); if (installed_webapk_package_name.empty()) {
AppBannerSettingsHelper::RecordBannerInstallEvent( // Request install the WebAPK.
web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); install_state_ = INSTALLING;
TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
webapk::TrackInstallSource(webapk_install_source_);
AppBannerSettingsHelper::RecordBannerInstallEvent(
web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
env, java_delegate_, true); env, java_delegate_, true);
UpdateInstallState(env, nullptr); UpdateInstallState(env, nullptr);
WebApkInstaller::FinishCallback callback = WebApkInstaller::FinishCallback callback =
base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
*shortcut_info_, *shortcut_info_,
*icon_.get(), callback); *icon_.get(), callback);
SendBannerAccepted(web_contents, "web"); SendBannerAccepted(web_contents, "web");
// Prevent the infobar from disappearing, because the infobar will show
// "Adding" during the installation process.
return false;
}
// Prevent the infobar from disappearing, because the infobar will show // Bypass the installation since WebAPK is already installed.
// "Adding" during the installation process. TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
OnWebApkInstallFinished(true, installed_webapk_package_name);
return false; return false;
} }
......
...@@ -243,6 +243,22 @@ SkBitmap ShortcutHelper::FinalizeLauncherIconInBackground( ...@@ -243,6 +243,22 @@ SkBitmap ShortcutHelper::FinalizeLauncherIconInBackground(
: SkBitmap(); : SkBitmap();
} }
// static
std::string ShortcutHelper::QueryWebApkPackage(const GURL& url) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jstring> java_url =
base::android::ConvertUTF8ToJavaString(env, url.spec());
ScopedJavaLocalRef<jstring> java_webapk_package_name =
Java_ShortcutHelper_queryWebApkPackage(env, java_url);
std::string webapk_package_name = "";
if (java_webapk_package_name.obj()) {
webapk_package_name = base::android::ConvertJavaStringToUTF8(
env, java_webapk_package_name);
}
return webapk_package_name;
}
// static // static
bool ShortcutHelper::IsWebApkInstalled(const GURL& url) { bool ShortcutHelper::IsWebApkInstalled(const GURL& url) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
......
...@@ -96,7 +96,11 @@ class ShortcutHelper { ...@@ -96,7 +96,11 @@ class ShortcutHelper {
const GURL& url, const GURL& url,
bool* is_generated); bool* is_generated);
// Returns true if WebAPKs are enabled and there is a WebAPK installed which // Returns the package name of the WebAPK if WebAPKs are enabled and there is
// an installed WebAPK which can handle |url|. Returns empty string otherwise.
static std::string QueryWebApkPackage(const GURL& url);
// Returns true if WebAPKs are enabled and there is an installed WebAPK which
// can handle |url|. // can handle |url|.
static bool IsWebApkInstalled(const GURL& url); static bool IsWebApkInstalled(const GURL& url);
......
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