| 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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); | 55 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); |
| 56 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); | 56 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // anonymous namespace | 59 } // anonymous namespace |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 62 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
| 63 const ShortcutInfo& info, | 63 const ShortcutInfo& info, |
| 64 const std::string& webapp_id, | 64 const std::string& webapp_id, |
| 65 const GURL& icon_url, |
| 65 const SkBitmap& icon_bitmap, | 66 const SkBitmap& icon_bitmap, |
| 66 const base::Closure& splash_image_callback) { | 67 const base::Closure& splash_image_callback) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 68 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 68 | 69 |
| 69 // Send the data to the Java side to create the shortcut. | 70 // Send the data to the Java side to create the shortcut. |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | 71 JNIEnv* env = base::android::AttachCurrentThread(); |
| 71 ScopedJavaLocalRef<jstring> java_webapp_id = | 72 ScopedJavaLocalRef<jstring> java_webapp_id = |
| 72 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 73 base::android::ConvertUTF8ToJavaString(env, webapp_id); |
| 73 ScopedJavaLocalRef<jstring> java_url = | 74 ScopedJavaLocalRef<jstring> java_url = |
| 74 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 75 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 75 ScopedJavaLocalRef<jstring> java_user_title = | 76 ScopedJavaLocalRef<jstring> java_user_title = |
| 76 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 77 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 77 ScopedJavaLocalRef<jstring> java_name = | 78 ScopedJavaLocalRef<jstring> java_name = |
| 78 base::android::ConvertUTF16ToJavaString(env, info.name); | 79 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 79 ScopedJavaLocalRef<jstring> java_short_name = | 80 ScopedJavaLocalRef<jstring> java_short_name = |
| 80 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 81 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 82 ScopedJavaLocalRef<jstring> java_icon_url = |
| 83 base::android::ConvertUTF8ToJavaString(env, icon_url.spec()); |
| 81 ScopedJavaLocalRef<jobject> java_bitmap; | 84 ScopedJavaLocalRef<jobject> java_bitmap; |
| 82 if (icon_bitmap.getSize()) | 85 if (icon_bitmap.getSize()) |
| 83 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 86 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 87 ScopedJavaLocalRef<jstring> java_manifest_url = |
| 88 base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec()); |
| 84 | 89 |
| 85 uintptr_t callback_pointer = 0; | 90 uintptr_t callback_pointer = 0; |
| 86 if (info.display == blink::WebDisplayModeStandalone || | 91 if (info.display == blink::WebDisplayModeStandalone || |
| 87 info.display == blink::WebDisplayModeFullscreen) { | 92 info.display == blink::WebDisplayModeFullscreen) { |
| 88 // The callback will need to be run after shortcut creation completes in | 93 // The callback will need to be run after shortcut creation completes in |
| 89 // order to download the splash image and save it to the WebappDataStorage. | 94 // order to download the splash image and save it to the WebappDataStorage. |
| 90 // Create a copy of the callback here and send the pointer to Java, which | 95 // Create a copy of the callback here and send the pointer to Java, which |
| 91 // will send it back once the asynchronous shortcut creation process | 96 // will send it back once the asynchronous shortcut creation process |
| 92 // finishes. | 97 // finishes. |
| 93 callback_pointer = | 98 callback_pointer = |
| 94 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); | 99 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); |
| 95 } | 100 } |
| 96 | 101 |
| 97 Java_ShortcutHelper_addShortcut( | 102 Java_ShortcutHelper_addShortcut( |
| 98 env, | 103 env, |
| 99 java_webapp_id.obj(), | 104 java_webapp_id.obj(), |
| 100 java_url.obj(), | 105 java_url.obj(), |
| 101 java_user_title.obj(), | 106 java_user_title.obj(), |
| 102 java_name.obj(), | 107 java_name.obj(), |
| 103 java_short_name.obj(), | 108 java_short_name.obj(), |
| 109 java_icon_url.obj(), |
| 104 java_bitmap.obj(), | 110 java_bitmap.obj(), |
| 105 info.display, | 111 info.display, |
| 106 info.orientation, | 112 info.orientation, |
| 107 info.source, | 113 info.source, |
| 108 info.theme_color, | 114 info.theme_color, |
| 109 info.background_color, | 115 info.background_color, |
| 110 info.is_icon_generated, | 116 java_manifest_url.obj(), |
| 111 callback_pointer); | 117 callback_pointer); |
| 112 } | 118 } |
| 113 | 119 |
| 114 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 120 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
| 115 if (kIdealHomescreenIconSize == -1) | 121 if (kIdealHomescreenIconSize == -1) |
| 116 GetHomescreenIconAndSplashImageSizes(); | 122 GetHomescreenIconAndSplashImageSizes(); |
| 117 return kIdealHomescreenIconSize; | 123 return kIdealHomescreenIconSize; |
| 118 } | 124 } |
| 119 | 125 |
| 120 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 126 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DCHECK(jsplash_image_callback); | 226 DCHECK(jsplash_image_callback); |
| 221 base::Closure* splash_image_callback = | 227 base::Closure* splash_image_callback = |
| 222 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 228 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 223 splash_image_callback->Run(); | 229 splash_image_callback->Run(); |
| 224 delete splash_image_callback; | 230 delete splash_image_callback; |
| 225 } | 231 } |
| 226 | 232 |
| 227 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 233 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 228 return RegisterNativesImpl(env); | 234 return RegisterNativesImpl(env); |
| 229 } | 235 } |
| OLD | NEW |