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" | |
13 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/banners/app_banner_settings_helper.h" | 14 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/manifest.h" | |
19 #include "jni/ShortcutHelper_jni.h" | 17 #include "jni/ShortcutHelper_jni.h" |
20 #include "ui/gfx/android/java_bitmap.h" | 18 #include "ui/gfx/android/java_bitmap.h" |
21 #include "ui/gfx/color_analysis.h" | |
22 #include "url/gurl.h" | 19 #include "url/gurl.h" |
23 | 20 |
24 using content::Manifest; | 21 using content::Manifest; |
25 | 22 |
26 // static | 23 // static |
27 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 24 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
28 const ShortcutInfo& info, | 25 const ShortcutInfo& info, |
26 const std::string& webapp_id, | |
29 const SkBitmap& icon_bitmap) { | 27 const SkBitmap& icon_bitmap) { |
30 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
31 | 29 |
32 // Send the data to the Java side to create the shortcut. | 30 // Send the data to the Java side to create the shortcut. |
33 JNIEnv* env = base::android::AttachCurrentThread(); | 31 JNIEnv* env = base::android::AttachCurrentThread(); |
32 ScopedJavaLocalRef<jstring> java_webapp_id = | |
33 base::android::ConvertUTF8ToJavaString(env, webapp_id); | |
34 ScopedJavaLocalRef<jstring> java_url = | 34 ScopedJavaLocalRef<jstring> java_url = |
35 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 35 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
36 ScopedJavaLocalRef<jstring> java_user_title = | 36 ScopedJavaLocalRef<jstring> java_user_title = |
37 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 37 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
38 ScopedJavaLocalRef<jstring> java_name = | 38 ScopedJavaLocalRef<jstring> java_name = |
39 base::android::ConvertUTF16ToJavaString(env, info.name); | 39 base::android::ConvertUTF16ToJavaString(env, info.name); |
40 ScopedJavaLocalRef<jstring> java_short_name = | 40 ScopedJavaLocalRef<jstring> java_short_name = |
41 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 41 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
42 ScopedJavaLocalRef<jobject> java_bitmap; | 42 ScopedJavaLocalRef<jobject> java_bitmap; |
43 if (icon_bitmap.getSize()) | 43 if (icon_bitmap.getSize()) |
44 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 44 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
45 | 45 |
46 Java_ShortcutHelper_addShortcut( | 46 Java_ShortcutHelper_addShortcut( |
47 env, | 47 env, |
48 base::android::GetApplicationContext(), | 48 base::android::GetApplicationContext(), |
49 java_webapp_id.obj(), | |
49 java_url.obj(), | 50 java_url.obj(), |
50 java_user_title.obj(), | 51 java_user_title.obj(), |
51 java_name.obj(), | 52 java_name.obj(), |
52 java_short_name.obj(), | 53 java_short_name.obj(), |
53 java_bitmap.obj(), | 54 java_bitmap.obj(), |
54 info.display == blink::WebDisplayModeStandalone, | 55 info.display == blink::WebDisplayModeStandalone, |
55 info.orientation, | 56 info.orientation, |
56 info.source, | 57 info.source, |
57 info.theme_color, | 58 info.theme_color, |
58 info.background_color); | 59 info.background_color); |
59 } | 60 } |
60 | 61 |
62 void ShortcutHelper::FetchSplashScreenImage( | |
mlamouri (slow - plz ping)
2015/09/03 22:58:40
nit: add "// static" above.
Lalit Maganti
2015/09/04 11:13:24
Done. And below as well.
| |
63 content::WebContents* web_contents, | |
64 const GURL& image_url, | |
65 const int ideal_splash_image_size_in_dp, | |
66 const std::string& webapp_id) { | |
67 // This is a fire and forget task. It is not vital for the splash screen image | |
68 // to be downloaded so if the downloader returns false there is no fallback. | |
69 ManifestIconDownloader::Download( | |
70 web_contents, | |
71 image_url, | |
72 ideal_splash_image_size_in_dp, | |
73 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id)); | |
74 } | |
75 | |
76 void ShortcutHelper::StoreWebappData( | |
77 const std::string& webapp_id, | |
78 const SkBitmap& splash_image) { | |
79 if (splash_image.drawsNothing()) | |
80 return; | |
81 | |
82 JNIEnv* env = base::android::AttachCurrentThread(); | |
83 ScopedJavaLocalRef<jstring> java_webapp_id = | |
84 base::android::ConvertUTF8ToJavaString(env, webapp_id); | |
85 ScopedJavaLocalRef<jobject> java_splash_image = | |
86 gfx::ConvertToJavaBitmap(&splash_image); | |
87 | |
88 Java_ShortcutHelper_storeWebappData( | |
89 env, | |
90 base::android::GetApplicationContext(), | |
91 java_webapp_id.obj(), | |
92 java_splash_image.obj()); | |
93 } | |
94 | |
61 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 95 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
62 return RegisterNativesImpl(env); | 96 return RegisterNativesImpl(env); |
63 } | 97 } |
OLD | NEW |