Index: chrome/browser/android/shortcut_helper.cc |
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc |
index e52f96ec34b5178272419523e5df9895b9093365..1f1849b3c50b8fa9debad4ad9714adcb83349ef2 100644 |
--- a/chrome/browser/android/shortcut_helper.cc |
+++ b/chrome/browser/android/shortcut_helper.cc |
@@ -10,6 +10,8 @@ |
#include "base/android/jni_android.h" |
#include "base/android/jni_array.h" |
#include "base/android/jni_string.h" |
+#include "base/bind.h" |
+#include "base/callback.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/manifest/manifest_icon_downloader.h" |
@@ -62,7 +64,8 @@ void GetHomescreenIconAndSplashImageSizes() { |
void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
const ShortcutInfo& info, |
const std::string& webapp_id, |
- const SkBitmap& icon_bitmap) { |
+ const SkBitmap& icon_bitmap, |
+ const base::Closure& splash_image_callback) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
// Send the data to the Java side to create the shortcut. |
@@ -81,6 +84,9 @@ void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
if (icon_bitmap.getSize()) |
java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
+ uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
gone
2016/04/01 23:44:48
Don't we know whether the callback will be used at
dominickn
2016/04/04 07:26:24
That's a good point. This cleans up the mess here
|
+ new base::Closure(splash_image_callback)); |
+ |
Java_ShortcutHelper_addShortcut( |
env, |
base::android::GetApplicationContext(), |
@@ -95,7 +101,8 @@ void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
info.source, |
info.theme_color, |
info.background_color, |
- info.is_icon_generated); |
+ info.is_icon_generated, |
+ callback_pointer); |
} |
int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
@@ -128,20 +135,18 @@ void ShortcutHelper::FetchSplashScreenImage( |
const GURL& image_url, |
const int ideal_splash_image_size_in_dp, |
const int minimum_splash_image_size_in_dp, |
- const std::string& webapp_id, |
- const std::string& webapp_scope) { |
+ const std::string& webapp_id) { |
// This is a fire and forget task. It is not vital for the splash screen image |
// to be downloaded so if the downloader returns false there is no fallback. |
ManifestIconDownloader::Download( |
web_contents, image_url, ideal_splash_image_size_in_dp, |
minimum_splash_image_size_in_dp, |
- base::Bind(&ShortcutHelper::StoreWebappData, webapp_id, webapp_scope)); |
+ base::Bind(&ShortcutHelper::StoreWebappSplashImage, webapp_id)); |
} |
// static |
-void ShortcutHelper::StoreWebappData( |
+void ShortcutHelper::StoreWebappSplashImage( |
const std::string& webapp_id, |
- const std::string& webapp_url, |
const SkBitmap& splash_image) { |
if (splash_image.drawsNothing()) |
return; |
@@ -149,16 +154,13 @@ void ShortcutHelper::StoreWebappData( |
JNIEnv* env = base::android::AttachCurrentThread(); |
ScopedJavaLocalRef<jstring> java_webapp_id = |
base::android::ConvertUTF8ToJavaString(env, webapp_id); |
- ScopedJavaLocalRef<jstring> java_webapp_url = |
- base::android::ConvertUTF8ToJavaString(env, webapp_url); |
ScopedJavaLocalRef<jobject> java_splash_image = |
gfx::ConvertToJavaBitmap(&splash_image); |
- Java_ShortcutHelper_storeWebappData( |
+ Java_ShortcutHelper_storeWebappSplashImage( |
env, |
base::android::GetApplicationContext(), |
java_webapp_id.obj(), |
- java_webapp_url.obj(), |
java_splash_image.obj()); |
} |
@@ -202,6 +204,20 @@ SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, |
return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); |
} |
+// Callback used by Java when the shortcut has been created. If the shortcut |
+// was for a webapp capable site, run the splashscreen_callback. |
+void OnWebappDataStored(JNIEnv* env, |
+ const JavaParamRef<jclass>& clazz, |
+ jlong jsplash_image_callback, |
+ jboolean jwebapp_capable) { |
+ base::Closure* splash_image_callback = |
+ reinterpret_cast<base::Closure*>(jsplash_image_callback); |
+ if (jwebapp_capable) |
+ splash_image_callback->Run(); |
+ |
+ delete splash_image_callback; |
+} |
+ |
bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |