| 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_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/banners/app_banner_settings_helper.h" | 15 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/manifest.h" | 18 #include "content/public/common/manifest.h" |
| 19 #include "jni/ShortcutHelper_jni.h" | 19 #include "jni/ShortcutHelper_jni.h" |
| 20 #include "ui/gfx/android/java_bitmap.h" | 20 #include "ui/gfx/android/java_bitmap.h" |
| 21 #include "ui/gfx/color_analysis.h" | 21 #include "ui/gfx/color_analysis.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 using content::Manifest; | 24 using content::Manifest; |
| 25 | 25 |
| 26 // static | 26 // static |
| 27 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 27 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
| 28 const ShortcutInfo& info, | 28 const ShortcutInfo& info, |
| 29 const std::string& id, |
| 29 const SkBitmap& icon_bitmap) { | 30 const SkBitmap& icon_bitmap) { |
| 30 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 31 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 31 | 32 |
| 32 // Send the data to the Java side to create the shortcut. | 33 // Send the data to the Java side to create the shortcut. |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 34 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 ScopedJavaLocalRef<jstring> java_id = |
| 36 base::android::ConvertUTF8ToJavaString(env, id); |
| 34 ScopedJavaLocalRef<jstring> java_url = | 37 ScopedJavaLocalRef<jstring> java_url = |
| 35 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 38 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 36 ScopedJavaLocalRef<jstring> java_user_title = | 39 ScopedJavaLocalRef<jstring> java_user_title = |
| 37 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 40 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 38 ScopedJavaLocalRef<jstring> java_name = | 41 ScopedJavaLocalRef<jstring> java_name = |
| 39 base::android::ConvertUTF16ToJavaString(env, info.name); | 42 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 40 ScopedJavaLocalRef<jstring> java_short_name = | 43 ScopedJavaLocalRef<jstring> java_short_name = |
| 41 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 44 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 42 ScopedJavaLocalRef<jobject> java_bitmap; | 45 ScopedJavaLocalRef<jobject> java_bitmap; |
| 43 if (icon_bitmap.getSize()) | 46 if (icon_bitmap.getSize()) |
| 44 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 47 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 45 | 48 |
| 46 Java_ShortcutHelper_addShortcut( | 49 Java_ShortcutHelper_addShortcut( |
| 47 env, | 50 env, |
| 48 base::android::GetApplicationContext(), | 51 base::android::GetApplicationContext(), |
| 52 java_id.obj(), |
| 49 java_url.obj(), | 53 java_url.obj(), |
| 50 java_user_title.obj(), | 54 java_user_title.obj(), |
| 51 java_name.obj(), | 55 java_name.obj(), |
| 52 java_short_name.obj(), | 56 java_short_name.obj(), |
| 53 java_bitmap.obj(), | 57 java_bitmap.obj(), |
| 54 info.display == blink::WebDisplayModeStandalone, | 58 info.display == blink::WebDisplayModeStandalone, |
| 55 info.orientation, | 59 info.orientation, |
| 56 info.source, | 60 info.source, |
| 57 info.theme_color, | 61 info.theme_color, |
| 58 info.background_color); | 62 info.background_color); |
| 59 } | 63 } |
| 60 | 64 |
| 65 void ShortcutHelper::AddSplashscreenIconToWebappData( |
| 66 const std::string& id, |
| 67 const SkBitmap& splash_icon) { |
| 68 // Send the data to the Java side to create the shortcut. |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); |
| 70 ScopedJavaLocalRef<jstring> java_id = |
| 71 base::android::ConvertUTF8ToJavaString(env, id); |
| 72 ScopedJavaLocalRef<jobject> java_splash_icon; |
| 73 if (!splash_icon.drawsNothing()) |
| 74 java_splash_icon = gfx::ConvertToJavaBitmap(&splash_icon); |
| 75 |
| 76 Java_ShortcutHelper_addSplashscreenIconToWebappData( |
| 77 env, |
| 78 base::android::GetApplicationContext(), |
| 79 java_id.obj(), |
| 80 java_splash_icon.obj()); |
| 81 } |
| 82 |
| 61 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 83 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 62 return RegisterNativesImpl(env); | 84 return RegisterNativesImpl(env); |
| 63 } | 85 } |
| OLD | NEW |