This CL changes the behavior of
ShortcutHelper::InstallWebApkInBackgroundWithSkBitmap()
- To talk to WebAPK server (https://webapk.googleapis.com/v1alpha/webApks?alt=proto)
to generate WebAPK
- To download WebAPK from URL returned by WebAPK server
This CL also:
- Adds stub for talking to Google Play client to install WebAPK
- Introduces manifest_util.h with methods for converting blink::WebDisplayMode
and blink::WebScreenOrientationLockType to and from string
BUG=619739
TEST=WebApkInstallerTest.*
R=dominickn,scottkirkwood,yfriedman,rsesek,hanxi,dfalcantara
TBR=brettw (for third_party/smhasher/BUILD.gn)
Review-Url: https://codereview.chromium.org/2138973002
Cr-Commit-Position: refs/heads/master@{#410233}
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc
index 50c6cad..9afc815 100644
--- a/chrome/browser/android/shortcut_helper.cc
+++ b/chrome/browser/android/shortcut_helper.cc
@@ -14,6 +14,7 @@
#include "base/command_line.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/android/webapk/webapk_installer.h"
#include "chrome/browser/manifest/manifest_icon_downloader.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
@@ -64,6 +65,7 @@
// static
void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap(
+ content::BrowserContext* browser_context,
const ShortcutInfo& info,
const std::string& webapp_id,
const SkBitmap& icon_bitmap,
@@ -74,7 +76,7 @@
info.display == blink::WebDisplayModeFullscreen) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableWebApk)) {
- InstallWebApkInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap);
+ InstallWebApkInBackgroundWithSkBitmap(browser_context, info, icon_bitmap);
return;
}
AddWebappInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap,
@@ -86,43 +88,14 @@
// static
void ShortcutHelper::InstallWebApkInBackgroundWithSkBitmap(
+ content::BrowserContext* browser_context,
const ShortcutInfo& info,
- const std::string& webapp_id,
const SkBitmap& icon_bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
-
- // TODO(pkotwicz): Send request to WebAPK server to generate WebAPK.
-
- JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> java_url =
- base::android::ConvertUTF8ToJavaString(env, info.url.spec());
- ScopedJavaLocalRef<jstring> java_scope_url =
- base::android::ConvertUTF8ToJavaString(env, info.scope.spec());
- ScopedJavaLocalRef<jstring> java_name =
- base::android::ConvertUTF16ToJavaString(env, info.name);
- ScopedJavaLocalRef<jstring> java_short_name =
- base::android::ConvertUTF16ToJavaString(env, info.short_name);
- ScopedJavaLocalRef<jstring> java_icon_url =
- base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec());
- ScopedJavaLocalRef<jobject> java_bitmap;
- if (icon_bitmap.getSize())
- java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
- ScopedJavaLocalRef<jstring> java_manifest_url =
- base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec());
-
- Java_ShortcutHelper_installWebApk(
- env,
- java_url.obj(),
- java_scope_url.obj(),
- java_name.obj(),
- java_short_name.obj(),
- java_icon_url.obj(),
- java_bitmap.obj(),
- info.display,
- info.orientation,
- info.theme_color,
- info.background_color,
- java_manifest_url.obj());
+ // WebApkInstaller destroys itself when it is done.
+ WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap);
+ installer->InstallAsync(browser_context,
+ base::Bind(&ShortcutHelper::OnBuiltWebApk));
}
// static
@@ -194,6 +167,16 @@
java_bitmap.obj(), info.source);
}
+void ShortcutHelper::OnBuiltWebApk(bool success) {
+ if (success) {
+ DVLOG(1) << "Sent request to install WebAPK. Seems to have worked.";
+ } else {
+ LOG(ERROR) << "WebAPK install failed.";
+ }
+ // TODO(pkotwicz): Figure out what to do when installing WebAPK fails.
+ // (crbug.com/626950)
+}
+
int ShortcutHelper::GetIdealHomescreenIconSizeInDp() {
if (kIdealHomescreenIconSize == -1)
GetHomescreenIconAndSplashImageSizes();