Chromium Code Reviews| 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/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 17 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 18 #include "chrome/common/chrome_switches.h" | |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 19 #include "jni/ShortcutHelper_jni.h" | 21 #include "jni/ShortcutHelper_jni.h" |
| 20 #include "ui/gfx/android/java_bitmap.h" | 22 #include "ui/gfx/android/java_bitmap.h" |
| 21 #include "ui/gfx/color_analysis.h" | 23 #include "ui/gfx/color_analysis.h" |
| 22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 23 | 25 |
| 24 using content::Manifest; | 26 using content::Manifest; |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, |
| 66 const base::Closure& splash_image_callback) { | 68 const base::Closure& splash_image_callback) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 68 | 70 |
| 71 if (info.display == blink::WebDisplayModeStandalone || | |
| 72 info.display == blink::WebDisplayModeFullscreen) { | |
| 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 74 switches::kEnableWebApk) && | |
| 75 AddWebApkInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap)) { | |
|
Xi Han
2016/07/08 19:10:38
If AddWebApkInBackgroundWithSkBitmap returns false
pkotwicz
2016/07/10 19:25:00
I have removed the fallback for now and have filed
Xi Han
2016/07/11 19:07:01
Thanks for firing the bug!
| |
| 76 return; | |
| 77 } | |
| 78 AddWebappInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap, | |
| 79 splash_image_callback); | |
| 80 return; | |
| 81 } | |
| 82 AddBookmarkShortcutInBackgroundWithSkBitmap(info, icon_bitmap); | |
| 83 } | |
| 84 | |
| 85 // static | |
| 86 bool ShortcutHelper::AddWebApkInBackgroundWithSkBitmap( | |
| 87 const ShortcutInfo& info, | |
| 88 const std::string& webapp_id, | |
| 89 const SkBitmap& icon_bitmap) { | |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 91 | |
| 92 // TODO(pkotwicz): Send request to WebAPK server to generate WebAPK. | |
| 93 | |
| 94 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 95 ScopedJavaLocalRef<jstring> java_url = | |
| 96 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | |
| 97 ScopedJavaLocalRef<jstring> java_name = | |
| 98 base::android::ConvertUTF16ToJavaString(env, info.name); | |
| 99 ScopedJavaLocalRef<jstring> java_short_name = | |
| 100 base::android::ConvertUTF16ToJavaString(env, info.short_name); | |
| 101 ScopedJavaLocalRef<jstring> java_icon_url = | |
| 102 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); | |
| 103 ScopedJavaLocalRef<jobject> java_bitmap; | |
| 104 if (icon_bitmap.getSize()) | |
| 105 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | |
| 106 ScopedJavaLocalRef<jstring> java_manifest_url = | |
| 107 base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec()); | |
| 108 | |
| 109 return Java_ShortcutHelper_installWebApk( | |
| 110 env, | |
| 111 java_url.obj(), | |
| 112 java_name.obj(), | |
| 113 java_short_name.obj(), | |
| 114 java_icon_url.obj(), | |
| 115 java_bitmap.obj(), | |
| 116 info.display, | |
| 117 info.orientation, | |
| 118 info.theme_color, | |
| 119 info.background_color, | |
| 120 java_manifest_url.obj()); | |
| 121 } | |
| 122 | |
| 123 // static | |
| 124 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap( | |
| 125 const ShortcutInfo& info, | |
| 126 const std::string& webapp_id, | |
| 127 const SkBitmap& icon_bitmap, | |
| 128 const base::Closure& splash_image_callback) { | |
| 129 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 130 | |
| 69 // Send the data to the Java side to create the shortcut. | 131 // Send the data to the Java side to create the shortcut. |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | 132 JNIEnv* env = base::android::AttachCurrentThread(); |
| 71 ScopedJavaLocalRef<jstring> java_webapp_id = | 133 ScopedJavaLocalRef<jstring> java_webapp_id = |
| 72 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 134 base::android::ConvertUTF8ToJavaString(env, webapp_id); |
| 73 ScopedJavaLocalRef<jstring> java_url = | 135 ScopedJavaLocalRef<jstring> java_url = |
| 74 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 136 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 75 ScopedJavaLocalRef<jstring> java_user_title = | 137 ScopedJavaLocalRef<jstring> java_user_title = |
| 76 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 138 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 77 ScopedJavaLocalRef<jstring> java_name = | 139 ScopedJavaLocalRef<jstring> java_name = |
| 78 base::android::ConvertUTF16ToJavaString(env, info.name); | 140 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 79 ScopedJavaLocalRef<jstring> java_short_name = | 141 ScopedJavaLocalRef<jstring> java_short_name = |
| 80 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 142 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 81 ScopedJavaLocalRef<jstring> java_icon_url = | 143 ScopedJavaLocalRef<jstring> java_icon_url = |
| 82 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); | 144 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); |
| 83 ScopedJavaLocalRef<jobject> java_bitmap; | 145 ScopedJavaLocalRef<jobject> java_bitmap; |
| 84 if (icon_bitmap.getSize()) | 146 if (icon_bitmap.getSize()) |
| 85 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 147 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 86 ScopedJavaLocalRef<jstring> java_manifest_url = | |
| 87 base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec()); | |
| 88 | 148 |
| 89 uintptr_t callback_pointer = 0; | 149 // The callback will need to be run after shortcut creation completes in order |
| 90 if (info.display == blink::WebDisplayModeStandalone || | 150 // to download the splash image and save it to the WebappDataStorage. Create a |
| 91 info.display == blink::WebDisplayModeFullscreen) { | 151 // copy of the callback here and send the pointer to Java, which will send it |
| 92 // The callback will need to be run after shortcut creation completes in | 152 // back once the asynchronous shortcut creation process finishes. |
| 93 // order to download the splash image and save it to the WebappDataStorage. | 153 uintptr_t callback_pointer = |
| 94 // Create a copy of the callback here and send the pointer to Java, which | 154 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); |
| 95 // will send it back once the asynchronous shortcut creation process | |
| 96 // finishes. | |
| 97 callback_pointer = | |
| 98 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); | |
| 99 } | |
| 100 | 155 |
| 101 Java_ShortcutHelper_addShortcut( | 156 Java_ShortcutHelper_addWebappShortcut( |
| 102 env, | 157 env, |
| 103 java_webapp_id.obj(), | 158 java_webapp_id.obj(), |
| 104 java_url.obj(), | 159 java_url.obj(), |
| 105 java_user_title.obj(), | 160 java_user_title.obj(), |
| 106 java_name.obj(), | 161 java_name.obj(), |
| 107 java_short_name.obj(), | 162 java_short_name.obj(), |
| 108 java_icon_url.obj(), | 163 java_icon_url.obj(), |
| 109 java_bitmap.obj(), | 164 java_bitmap.obj(), |
| 110 info.display, | 165 info.display, |
| 111 info.orientation, | 166 info.orientation, |
| 112 info.source, | 167 info.source, |
| 113 info.theme_color, | 168 info.theme_color, |
| 114 info.background_color, | 169 info.background_color, |
| 115 java_manifest_url.obj(), | |
| 116 callback_pointer); | 170 callback_pointer); |
| 117 } | 171 } |
| 118 | 172 |
| 173 void ShortcutHelper::AddBookmarkShortcutInBackgroundWithSkBitmap( | |
| 174 const ShortcutInfo& info, | |
| 175 const SkBitmap& icon_bitmap) { | |
| 176 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 177 ScopedJavaLocalRef<jstring> java_url = | |
| 178 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | |
| 179 ScopedJavaLocalRef<jstring> java_user_title = | |
| 180 base::android::ConvertUTF16ToJavaString(env, info.user_title); | |
| 181 ScopedJavaLocalRef<jobject> java_bitmap; | |
| 182 if (icon_bitmap.getSize()) | |
| 183 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | |
| 184 | |
| 185 Java_ShortcutHelper_addBookmarkShortcut(env, java_url.obj(), | |
| 186 java_user_title.obj(), | |
| 187 java_bitmap.obj(), info.source); | |
| 188 } | |
| 189 | |
| 119 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 190 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
| 120 if (kIdealHomescreenIconSize == -1) | 191 if (kIdealHomescreenIconSize == -1) |
| 121 GetHomescreenIconAndSplashImageSizes(); | 192 GetHomescreenIconAndSplashImageSizes(); |
| 122 return kIdealHomescreenIconSize; | 193 return kIdealHomescreenIconSize; |
| 123 } | 194 } |
| 124 | 195 |
| 125 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 196 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { |
| 126 if (kMinimumHomescreenIconSize == -1) | 197 if (kMinimumHomescreenIconSize == -1) |
| 127 GetHomescreenIconAndSplashImageSizes(); | 198 GetHomescreenIconAndSplashImageSizes(); |
| 128 return kMinimumHomescreenIconSize; | 199 return kMinimumHomescreenIconSize; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 DCHECK(jsplash_image_callback); | 296 DCHECK(jsplash_image_callback); |
| 226 base::Closure* splash_image_callback = | 297 base::Closure* splash_image_callback = |
| 227 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 298 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 228 splash_image_callback->Run(); | 299 splash_image_callback->Run(); |
| 229 delete splash_image_callback; | 300 delete splash_image_callback; |
| 230 } | 301 } |
| 231 | 302 |
| 232 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 303 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 233 return RegisterNativesImpl(env); | 304 return RegisterNativesImpl(env); |
| 234 } | 305 } |
| OLD | NEW |