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

Unified Diff: chrome/browser/android/shortcut_helper.cc

Issue 2138973002: Initial CL for talking to the WebAPK server to generate WebAPK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_builder_impl22_no_content Created 4 years, 4 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
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/webapk/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/shortcut_helper.cc
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc
index 50c6cadfeba9b208b14e5e8eb0b8d1e4fe822b4a..9afc8153bd7de246235d75b5390318a9dccdd170 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 @@ void GetHomescreenIconAndSplashImageSizes() {
// static
void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap(
+ content::BrowserContext* browser_context,
const ShortcutInfo& info,
const std::string& webapp_id,
const SkBitmap& icon_bitmap,
@@ -74,7 +76,7 @@ void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap(
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 @@ void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap(
// 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 @@ void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
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();
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/webapk/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698