| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ScopedJavaLocalRef<jstring> java_webapp_id = | 71 ScopedJavaLocalRef<jstring> java_webapp_id = |
| 72 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 72 base::android::ConvertUTF8ToJavaString(env, webapp_id); |
| 73 ScopedJavaLocalRef<jstring> java_url = | 73 ScopedJavaLocalRef<jstring> java_url = |
| 74 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 74 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 75 ScopedJavaLocalRef<jstring> java_user_title = | 75 ScopedJavaLocalRef<jstring> java_user_title = |
| 76 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 76 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 77 ScopedJavaLocalRef<jstring> java_name = | 77 ScopedJavaLocalRef<jstring> java_name = |
| 78 base::android::ConvertUTF16ToJavaString(env, info.name); | 78 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 79 ScopedJavaLocalRef<jstring> java_short_name = | 79 ScopedJavaLocalRef<jstring> java_short_name = |
| 80 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 80 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 81 ScopedJavaLocalRef<jstring> java_icon_url = |
| 82 base::android::ConvertUTF8ToJavaString(env, info.icon_url.spec()); |
| 81 ScopedJavaLocalRef<jobject> java_bitmap; | 83 ScopedJavaLocalRef<jobject> java_bitmap; |
| 82 if (icon_bitmap.getSize()) | 84 if (icon_bitmap.getSize()) |
| 83 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 85 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 86 ScopedJavaLocalRef<jstring> java_manifest_url = |
| 87 base::android::ConvertUTF8ToJavaString(env, info.manifest_url.spec()); |
| 84 | 88 |
| 85 uintptr_t callback_pointer = 0; | 89 uintptr_t callback_pointer = 0; |
| 86 if (info.display == blink::WebDisplayModeStandalone || | 90 if (info.display == blink::WebDisplayModeStandalone || |
| 87 info.display == blink::WebDisplayModeFullscreen) { | 91 info.display == blink::WebDisplayModeFullscreen) { |
| 88 // The callback will need to be run after shortcut creation completes in | 92 // 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. | 93 // 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 | 94 // 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 | 95 // will send it back once the asynchronous shortcut creation process |
| 92 // finishes. | 96 // finishes. |
| 93 callback_pointer = | 97 callback_pointer = |
| 94 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); | 98 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); |
| 95 } | 99 } |
| 96 | 100 |
| 97 Java_ShortcutHelper_addShortcut( | 101 Java_ShortcutHelper_addShortcut( |
| 98 env, | 102 env, |
| 99 java_webapp_id.obj(), | 103 java_webapp_id.obj(), |
| 100 java_url.obj(), | 104 java_url.obj(), |
| 101 java_user_title.obj(), | 105 java_user_title.obj(), |
| 102 java_name.obj(), | 106 java_name.obj(), |
| 103 java_short_name.obj(), | 107 java_short_name.obj(), |
| 108 java_icon_url.obj(), |
| 104 java_bitmap.obj(), | 109 java_bitmap.obj(), |
| 105 info.display, | 110 info.display, |
| 106 info.orientation, | 111 info.orientation, |
| 107 info.source, | 112 info.source, |
| 108 info.theme_color, | 113 info.theme_color, |
| 109 info.background_color, | 114 info.background_color, |
| 110 info.is_icon_generated, | 115 java_manifest_url.obj(), |
| 111 callback_pointer); | 116 callback_pointer); |
| 112 } | 117 } |
| 113 | 118 |
| 114 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 119 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
| 115 if (kIdealHomescreenIconSize == -1) | 120 if (kIdealHomescreenIconSize == -1) |
| 116 GetHomescreenIconAndSplashImageSizes(); | 121 GetHomescreenIconAndSplashImageSizes(); |
| 117 return kIdealHomescreenIconSize; | 122 return kIdealHomescreenIconSize; |
| 118 } | 123 } |
| 119 | 124 |
| 120 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 125 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DCHECK(jsplash_image_callback); | 225 DCHECK(jsplash_image_callback); |
| 221 base::Closure* splash_image_callback = | 226 base::Closure* splash_image_callback = |
| 222 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 227 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 223 splash_image_callback->Run(); | 228 splash_image_callback->Run(); |
| 224 delete splash_image_callback; | 229 delete splash_image_callback; |
| 225 } | 230 } |
| 226 | 231 |
| 227 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 232 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 228 return RegisterNativesImpl(env); | 233 return RegisterNativesImpl(env); |
| 229 } | 234 } |
| OLD | NEW |