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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 : add_shortcut_pending_(false), | 36 : add_shortcut_pending_(false), |
37 data_fetcher_(new ShortcutDataFetcher(web_contents, this)) { | 37 data_fetcher_(new ShortcutDataFetcher(web_contents, this)) { |
38 java_ref_.Reset(env, obj); | 38 java_ref_.Reset(env, obj); |
39 } | 39 } |
40 | 40 |
41 ShortcutHelper::~ShortcutHelper() { | 41 ShortcutHelper::~ShortcutHelper() { |
42 data_fetcher_->set_weak_observer(nullptr); | 42 data_fetcher_->set_weak_observer(nullptr); |
43 data_fetcher_ = nullptr; | 43 data_fetcher_ = nullptr; |
44 } | 44 } |
45 | 45 |
46 void ShortcutHelper::OnTitleAvailable(const base::string16& title) { | 46 void ShortcutHelper::OnUserTitleAvailable(const base::string16& user_title) { |
47 JNIEnv* env = base::android::AttachCurrentThread(); | 47 JNIEnv* env = base::android::AttachCurrentThread(); |
48 ScopedJavaLocalRef<jstring> j_title = | 48 ScopedJavaLocalRef<jstring> j_user_title = |
49 base::android::ConvertUTF16ToJavaString(env, title); | 49 base::android::ConvertUTF16ToJavaString(env, user_title); |
50 Java_ShortcutHelper_onTitleAvailable(env, | 50 Java_ShortcutHelper_onUserTitleAvailable(env, |
51 java_ref_.obj(), | 51 java_ref_.obj(), |
52 j_title.obj()); | 52 j_user_title.obj()); |
53 } | 53 } |
54 | 54 |
55 void ShortcutHelper::OnDataAvailable(const ShortcutInfo& info, | 55 void ShortcutHelper::OnDataAvailable(const ShortcutInfo& info, |
56 const SkBitmap& icon) { | 56 const SkBitmap& icon) { |
57 JNIEnv* env = base::android::AttachCurrentThread(); | 57 JNIEnv* env = base::android::AttachCurrentThread(); |
58 ScopedJavaLocalRef<jobject> java_bitmap; | 58 ScopedJavaLocalRef<jobject> java_bitmap; |
59 if (icon.getSize()) | 59 if (icon.getSize()) |
60 java_bitmap = gfx::ConvertToJavaBitmap(&icon); | 60 java_bitmap = gfx::ConvertToJavaBitmap(&icon); |
61 | 61 |
62 Java_ShortcutHelper_onIconAvailable(env, | 62 Java_ShortcutHelper_onIconAvailable(env, |
(...skipping 30 matching lines...) Expand all Loading... |
93 base::android::ScopedJavaLocalRef<jobject> ref = | 93 base::android::ScopedJavaLocalRef<jobject> ref = |
94 Java_ShortcutHelper_finalizeLauncherIcon(env, | 94 Java_ShortcutHelper_finalizeLauncherIcon(env, |
95 java_url.obj(), | 95 java_url.obj(), |
96 java_bitmap.obj(), | 96 java_bitmap.obj(), |
97 dominant_red, | 97 dominant_red, |
98 dominant_green, | 98 dominant_green, |
99 dominant_blue); | 99 dominant_blue); |
100 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj())); | 100 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj())); |
101 } | 101 } |
102 | 102 |
103 void ShortcutHelper::AddShortcut(JNIEnv* env, jobject obj, jstring jtitle) { | 103 void ShortcutHelper::AddShortcut(JNIEnv* env, |
| 104 jobject obj, |
| 105 jstring j_user_title) { |
104 add_shortcut_pending_ = true; | 106 add_shortcut_pending_ = true; |
105 | 107 |
106 base::string16 title = base::android::ConvertJavaStringToUTF16(env, jtitle); | 108 base::string16 user_title = |
107 if (!title.empty()) | 109 base::android::ConvertJavaStringToUTF16(env, j_user_title); |
108 data_fetcher_->shortcut_info().title = title; | 110 if (!user_title.empty()) |
| 111 data_fetcher_->shortcut_info().user_title = user_title; |
109 | 112 |
110 if (data_fetcher_->is_ready()) { | 113 if (data_fetcher_->is_ready()) { |
111 // If the fetcher isn't ready yet, the shortcut will be added when it is | 114 // If the fetcher isn't ready yet, the shortcut will be added when it is |
112 // via OnDataAvailable(); | 115 // via OnDataAvailable(); |
113 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); | 116 AddShortcut(data_fetcher_->shortcut_info(), data_fetcher_->shortcut_icon()); |
114 } | 117 } |
115 } | 118 } |
116 | 119 |
117 void ShortcutHelper::AddShortcut(const ShortcutInfo& info, | 120 void ShortcutHelper::AddShortcut(const ShortcutInfo& info, |
118 const SkBitmap& icon) { | 121 const SkBitmap& icon) { |
(...skipping 19 matching lines...) Expand all Loading... |
138 // static | 141 // static |
139 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 142 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( |
140 const ShortcutInfo& info, | 143 const ShortcutInfo& info, |
141 const SkBitmap& icon_bitmap) { | 144 const SkBitmap& icon_bitmap) { |
142 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
143 | 146 |
144 // Send the data to the Java side to create the shortcut. | 147 // Send the data to the Java side to create the shortcut. |
145 JNIEnv* env = base::android::AttachCurrentThread(); | 148 JNIEnv* env = base::android::AttachCurrentThread(); |
146 ScopedJavaLocalRef<jstring> java_url = | 149 ScopedJavaLocalRef<jstring> java_url = |
147 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 150 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
148 ScopedJavaLocalRef<jstring> java_title = | 151 ScopedJavaLocalRef<jstring> java_user_title = |
149 base::android::ConvertUTF16ToJavaString(env, info.title); | 152 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 153 ScopedJavaLocalRef<jstring> java_name = |
| 154 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 155 ScopedJavaLocalRef<jstring> java_short_name = |
| 156 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
150 ScopedJavaLocalRef<jobject> java_bitmap; | 157 ScopedJavaLocalRef<jobject> java_bitmap; |
151 if (icon_bitmap.getSize()) | 158 if (icon_bitmap.getSize()) |
152 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 159 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
153 | 160 |
154 Java_ShortcutHelper_addShortcut( | 161 Java_ShortcutHelper_addShortcut( |
155 env, | 162 env, |
156 base::android::GetApplicationContext(), | 163 base::android::GetApplicationContext(), |
157 java_url.obj(), | 164 java_url.obj(), |
158 java_title.obj(), | 165 java_user_title.obj(), |
| 166 java_name.obj(), |
| 167 java_short_name.obj(), |
159 java_bitmap.obj(), | 168 java_bitmap.obj(), |
160 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, | 169 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, |
161 info.orientation, | 170 info.orientation, |
162 info.source); | 171 info.source); |
163 } | 172 } |
164 | 173 |
165 void ShortcutHelper::RecordAddToHomescreen() { | 174 void ShortcutHelper::RecordAddToHomescreen() { |
166 // Record that the shortcut has been added, so no banners will be shown | 175 // Record that the shortcut has been added, so no banners will be shown |
167 // for this app. | 176 // for this app. |
168 content::WebContents* web_contents = data_fetcher_->web_contents(); | 177 content::WebContents* web_contents = data_fetcher_->web_contents(); |
169 if (!web_contents) | 178 if (!web_contents) |
170 return; | 179 return; |
171 | 180 |
172 AppBannerSettingsHelper::RecordBannerEvent( | 181 AppBannerSettingsHelper::RecordBannerEvent( |
173 web_contents, web_contents->GetURL(), | 182 web_contents, web_contents->GetURL(), |
174 data_fetcher_->shortcut_info().url.spec(), | 183 data_fetcher_->shortcut_info().url.spec(), |
175 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 184 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
176 base::Time::Now()); | 185 base::Time::Now()); |
177 } | 186 } |
OLD | NEW |