 Chromium Code Reviews
 Chromium Code Reviews Issue 1845233002:
  Store standalone web app data in WebappDataStorage as well as the homescreen intent.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@notification-deep-linking
    
  
    Issue 1845233002:
  Store standalone web app data in WebappDataStorage as well as the homescreen intent.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@notification-deep-linking| OLD | NEW | 
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/android/shortcut_helper.h" | 5 #include "chrome/browser/android/shortcut_helper.h" | 
| 6 | 6 | 
| 7 #include <jni.h> | 7 #include <jni.h> | 
| 8 | 8 | 
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" | 
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" | 
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" | 
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" | 
| 13 #include "base/bind.h" | |
| 14 #include "base/callback.h" | |
| 13 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" | 
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" | 
| 15 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 17 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 
| 16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" | 
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" | 
| 18 #include "jni/ShortcutHelper_jni.h" | 20 #include "jni/ShortcutHelper_jni.h" | 
| 19 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" | 
| 20 #include "ui/gfx/color_analysis.h" | 22 #include "ui/gfx/color_analysis.h" | 
| 21 #include "url/gurl.h" | 23 #include "url/gurl.h" | 
| 22 | 24 | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); | 57 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); | 
| 56 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); | 58 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); | 
| 57 } | 59 } | 
| 58 | 60 | 
| 59 } // anonymous namespace | 61 } // anonymous namespace | 
| 60 | 62 | 
| 61 // static | 63 // static | 
| 62 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 64 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 
| 63 const ShortcutInfo& info, | 65 const ShortcutInfo& info, | 
| 64 const std::string& webapp_id, | 66 const std::string& webapp_id, | 
| 65 const SkBitmap& icon_bitmap) { | 67 const SkBitmap& icon_bitmap, | 
| 68 const base::Closure& splash_image_callback) { | |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 
| 67 | 70 | 
| 68 // Send the data to the Java side to create the shortcut. | 71 // Send the data to the Java side to create the shortcut. | 
| 69 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); | 
| 70 ScopedJavaLocalRef<jstring> java_webapp_id = | 73 ScopedJavaLocalRef<jstring> java_webapp_id = | 
| 71 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 74 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 
| 72 ScopedJavaLocalRef<jstring> java_url = | 75 ScopedJavaLocalRef<jstring> java_url = | 
| 73 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 76 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 
| 74 ScopedJavaLocalRef<jstring> java_user_title = | 77 ScopedJavaLocalRef<jstring> java_user_title = | 
| 75 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 78 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 
| 76 ScopedJavaLocalRef<jstring> java_name = | 79 ScopedJavaLocalRef<jstring> java_name = | 
| 77 base::android::ConvertUTF16ToJavaString(env, info.name); | 80 base::android::ConvertUTF16ToJavaString(env, info.name); | 
| 78 ScopedJavaLocalRef<jstring> java_short_name = | 81 ScopedJavaLocalRef<jstring> java_short_name = | 
| 79 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 82 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 
| 80 ScopedJavaLocalRef<jobject> java_bitmap; | 83 ScopedJavaLocalRef<jobject> java_bitmap; | 
| 81 if (icon_bitmap.getSize()) | 84 if (icon_bitmap.getSize()) | 
| 82 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 85 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 
| 83 | 86 | 
| 87 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
 | |
| 88 new base::Closure(splash_image_callback)); | |
| 89 | |
| 84 Java_ShortcutHelper_addShortcut( | 90 Java_ShortcutHelper_addShortcut( | 
| 85 env, | 91 env, | 
| 86 base::android::GetApplicationContext(), | 92 base::android::GetApplicationContext(), | 
| 87 java_webapp_id.obj(), | 93 java_webapp_id.obj(), | 
| 88 java_url.obj(), | 94 java_url.obj(), | 
| 89 java_user_title.obj(), | 95 java_user_title.obj(), | 
| 90 java_name.obj(), | 96 java_name.obj(), | 
| 91 java_short_name.obj(), | 97 java_short_name.obj(), | 
| 92 java_bitmap.obj(), | 98 java_bitmap.obj(), | 
| 93 info.display == blink::WebDisplayModeStandalone, | 99 info.display == blink::WebDisplayModeStandalone, | 
| 94 info.orientation, | 100 info.orientation, | 
| 95 info.source, | 101 info.source, | 
| 96 info.theme_color, | 102 info.theme_color, | 
| 97 info.background_color, | 103 info.background_color, | 
| 98 info.is_icon_generated); | 104 info.is_icon_generated, | 
| 105 callback_pointer); | |
| 99 } | 106 } | 
| 100 | 107 | 
| 101 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 108 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 
| 102 if (kIdealHomescreenIconSize == -1) | 109 if (kIdealHomescreenIconSize == -1) | 
| 103 GetHomescreenIconAndSplashImageSizes(); | 110 GetHomescreenIconAndSplashImageSizes(); | 
| 104 return kIdealHomescreenIconSize; | 111 return kIdealHomescreenIconSize; | 
| 105 } | 112 } | 
| 106 | 113 | 
| 107 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 114 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 
| 108 if (kMinimumHomescreenIconSize == -1) | 115 if (kMinimumHomescreenIconSize == -1) | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 121 GetHomescreenIconAndSplashImageSizes(); | 128 GetHomescreenIconAndSplashImageSizes(); | 
| 122 return kMinimumSplashImageSize; | 129 return kMinimumSplashImageSize; | 
| 123 } | 130 } | 
| 124 | 131 | 
| 125 // static | 132 // static | 
| 126 void ShortcutHelper::FetchSplashScreenImage( | 133 void ShortcutHelper::FetchSplashScreenImage( | 
| 127 content::WebContents* web_contents, | 134 content::WebContents* web_contents, | 
| 128 const GURL& image_url, | 135 const GURL& image_url, | 
| 129 const int ideal_splash_image_size_in_dp, | 136 const int ideal_splash_image_size_in_dp, | 
| 130 const int minimum_splash_image_size_in_dp, | 137 const int minimum_splash_image_size_in_dp, | 
| 131 const std::string& webapp_id, | 138 const std::string& webapp_id) { | 
| 132 const std::string& webapp_scope) { | |
| 133 // This is a fire and forget task. It is not vital for the splash screen image | 139 // This is a fire and forget task. It is not vital for the splash screen image | 
| 134 // to be downloaded so if the downloader returns false there is no fallback. | 140 // to be downloaded so if the downloader returns false there is no fallback. | 
| 135 ManifestIconDownloader::Download( | 141 ManifestIconDownloader::Download( | 
| 136 web_contents, image_url, ideal_splash_image_size_in_dp, | 142 web_contents, image_url, ideal_splash_image_size_in_dp, | 
| 137 minimum_splash_image_size_in_dp, | 143 minimum_splash_image_size_in_dp, | 
| 138 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id, webapp_scope)); | 144 base::Bind(&ShortcutHelper::StoreWebappSplashImage, webapp_id)); | 
| 139 } | 145 } | 
| 140 | 146 | 
| 141 // static | 147 // static | 
| 142 void ShortcutHelper::StoreWebappData( | 148 void ShortcutHelper::StoreWebappSplashImage( | 
| 143 const std::string& webapp_id, | 149 const std::string& webapp_id, | 
| 144 const std::string& webapp_url, | |
| 145 const SkBitmap& splash_image) { | 150 const SkBitmap& splash_image) { | 
| 146 if (splash_image.drawsNothing()) | 151 if (splash_image.drawsNothing()) | 
| 147 return; | 152 return; | 
| 148 | 153 | 
| 149 JNIEnv* env = base::android::AttachCurrentThread(); | 154 JNIEnv* env = base::android::AttachCurrentThread(); | 
| 150 ScopedJavaLocalRef<jstring> java_webapp_id = | 155 ScopedJavaLocalRef<jstring> java_webapp_id = | 
| 151 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 156 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 
| 152 ScopedJavaLocalRef<jstring> java_webapp_url = | |
| 153 base::android::ConvertUTF8ToJavaString(env, webapp_url); | |
| 154 ScopedJavaLocalRef<jobject> java_splash_image = | 157 ScopedJavaLocalRef<jobject> java_splash_image = | 
| 155 gfx::ConvertToJavaBitmap(&splash_image); | 158 gfx::ConvertToJavaBitmap(&splash_image); | 
| 156 | 159 | 
| 157 Java_ShortcutHelper_storeWebappData( | 160 Java_ShortcutHelper_storeWebappSplashImage( | 
| 158 env, | 161 env, | 
| 159 base::android::GetApplicationContext(), | 162 base::android::GetApplicationContext(), | 
| 160 java_webapp_id.obj(), | 163 java_webapp_id.obj(), | 
| 161 java_webapp_url.obj(), | |
| 162 java_splash_image.obj()); | 164 java_splash_image.obj()); | 
| 163 } | 165 } | 
| 164 | 166 | 
| 165 // static | 167 // static | 
| 166 SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, | 168 SkBitmap ShortcutHelper::FinalizeLauncherIcon(const SkBitmap& bitmap, | 
| 167 const GURL& url, | 169 const GURL& url, | 
| 168 bool* is_generated) { | 170 bool* is_generated) { | 
| 169 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 171 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 
| 170 | 172 | 
| 171 JNIEnv* env = base::android::AttachCurrentThread(); | 173 JNIEnv* env = base::android::AttachCurrentThread(); | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 195 *is_generated = true; | 197 *is_generated = true; | 
| 196 result = Java_ShortcutHelper_generateHomeScreenIcon( | 198 result = Java_ShortcutHelper_generateHomeScreenIcon( | 
| 197 env, base::android::GetApplicationContext(), java_url.obj(), | 199 env, base::android::GetApplicationContext(), java_url.obj(), | 
| 198 SkColorGetR(mean_color), SkColorGetG(mean_color), | 200 SkColorGetR(mean_color), SkColorGetG(mean_color), | 
| 199 SkColorGetB(mean_color)); | 201 SkColorGetB(mean_color)); | 
| 200 } | 202 } | 
| 201 | 203 | 
| 202 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); | 204 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())); | 
| 203 } | 205 } | 
| 204 | 206 | 
| 207 // Callback used by Java when the shortcut has been created. If the shortcut | |
| 208 // was for a webapp capable site, run the splashscreen_callback. | |
| 209 void OnWebappDataStored(JNIEnv* env, | |
| 210 const JavaParamRef<jclass>& clazz, | |
| 211 jlong jsplash_image_callback, | |
| 212 jboolean jwebapp_capable) { | |
| 213 base::Closure* splash_image_callback = | |
| 214 reinterpret_cast<base::Closure*>(jsplash_image_callback); | |
| 215 if (jwebapp_capable) | |
| 216 splash_image_callback->Run(); | |
| 217 | |
| 218 delete splash_image_callback; | |
| 219 } | |
| 220 | |
| 205 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 221 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 
| 206 return RegisterNativesImpl(env); | 222 return RegisterNativesImpl(env); | 
| 207 } | 223 } | 
| OLD | NEW |