Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 2237943002: Remove now-unnecessary .obj() in Java method calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@switch-context
Patch Set: Rebase *again* :( Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (icon_bitmap.getSize()) 120 if (icon_bitmap.getSize())
121 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 121 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
122 122
123 // The callback will need to be run after shortcut creation completes in order 123 // The callback will need to be run after shortcut creation completes in order
124 // to download the splash image and save it to the WebappDataStorage. Create a 124 // to download the splash image and save it to the WebappDataStorage. Create a
125 // copy of the callback here and send the pointer to Java, which will send it 125 // copy of the callback here and send the pointer to Java, which will send it
126 // back once the asynchronous shortcut creation process finishes. 126 // back once the asynchronous shortcut creation process finishes.
127 uintptr_t callback_pointer = 127 uintptr_t callback_pointer =
128 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); 128 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback));
129 129
130 Java_ShortcutHelper_addWebapp( 130 Java_ShortcutHelper_addWebapp(env, java_webapp_id, java_url, java_scope_url,
131 env, 131 java_user_title, java_name, java_short_name,
132 java_webapp_id.obj(), 132 java_icon_url, java_bitmap, info.display,
133 java_url.obj(), 133 info.orientation, info.source, info.theme_color,
134 java_scope_url.obj(), 134 info.background_color, callback_pointer);
135 java_user_title.obj(),
136 java_name.obj(),
137 java_short_name.obj(),
138 java_icon_url.obj(),
139 java_bitmap.obj(),
140 info.display,
141 info.orientation,
142 info.source,
143 info.theme_color,
144 info.background_color,
145 callback_pointer);
146 } 135 }
147 136
148 void ShortcutHelper::AddShortcutWithSkBitmap( 137 void ShortcutHelper::AddShortcutWithSkBitmap(
149 const ShortcutInfo& info, 138 const ShortcutInfo& info,
150 const SkBitmap& icon_bitmap) { 139 const SkBitmap& icon_bitmap) {
151 JNIEnv* env = base::android::AttachCurrentThread(); 140 JNIEnv* env = base::android::AttachCurrentThread();
152 ScopedJavaLocalRef<jstring> java_url = 141 ScopedJavaLocalRef<jstring> java_url =
153 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); 142 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
154 ScopedJavaLocalRef<jstring> java_user_title = 143 ScopedJavaLocalRef<jstring> java_user_title =
155 base::android::ConvertUTF16ToJavaString(env, info.user_title); 144 base::android::ConvertUTF16ToJavaString(env, info.user_title);
156 ScopedJavaLocalRef<jobject> java_bitmap; 145 ScopedJavaLocalRef<jobject> java_bitmap;
157 if (icon_bitmap.getSize()) 146 if (icon_bitmap.getSize())
158 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 147 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
159 148
160 Java_ShortcutHelper_addShortcut(env, java_url.obj(), java_user_title.obj(), 149 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap,
161 java_bitmap.obj(), info.source); 150 info.source);
162 } 151 }
163 152
164 void ShortcutHelper::OnBuiltWebApk(bool success) { 153 void ShortcutHelper::OnBuiltWebApk(bool success) {
165 if (success) { 154 if (success) {
166 DVLOG(1) << "Sent request to install WebAPK. Seems to have worked."; 155 DVLOG(1) << "Sent request to install WebAPK. Seems to have worked.";
167 } else { 156 } else {
168 LOG(ERROR) << "WebAPK install failed."; 157 LOG(ERROR) << "WebAPK install failed.";
169 } 158 }
170 // TODO(pkotwicz): Figure out what to do when installing WebAPK fails. 159 // TODO(pkotwicz): Figure out what to do when installing WebAPK fails.
171 // (crbug.com/626950) 160 // (crbug.com/626950)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const SkBitmap& splash_image) { 205 const SkBitmap& splash_image) {
217 if (splash_image.drawsNothing()) 206 if (splash_image.drawsNothing())
218 return; 207 return;
219 208
220 JNIEnv* env = base::android::AttachCurrentThread(); 209 JNIEnv* env = base::android::AttachCurrentThread();
221 ScopedJavaLocalRef<jstring> java_webapp_id = 210 ScopedJavaLocalRef<jstring> java_webapp_id =
222 base::android::ConvertUTF8ToJavaString(env, webapp_id); 211 base::android::ConvertUTF8ToJavaString(env, webapp_id);
223 ScopedJavaLocalRef<jobject> java_splash_image = 212 ScopedJavaLocalRef<jobject> java_splash_image =
224 gfx::ConvertToJavaBitmap(&splash_image); 213 gfx::ConvertToJavaBitmap(&splash_image);
225 214
226 Java_ShortcutHelper_storeWebappSplashImage( 215 Java_ShortcutHelper_storeWebappSplashImage(env, java_webapp_id,
227 env, 216 java_splash_image);
228 java_webapp_id.obj(),
229 java_splash_image.obj());
230 } 217 }
231 218
232 // static 219 // static
233 SkBitmap ShortcutHelper::FinalizeLauncherIconInBackground( 220 SkBitmap ShortcutHelper::FinalizeLauncherIconInBackground(
234 const SkBitmap& bitmap, 221 const SkBitmap& bitmap,
235 const GURL& url, 222 const GURL& url,
236 bool* is_generated) { 223 bool* is_generated) {
237 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 224 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
238 225
239 JNIEnv* env = base::android::AttachCurrentThread(); 226 JNIEnv* env = base::android::AttachCurrentThread();
240 ScopedJavaLocalRef<jobject> result; 227 ScopedJavaLocalRef<jobject> result;
241 *is_generated = false; 228 *is_generated = false;
242 229
243 if (!bitmap.isNull()) { 230 if (!bitmap.isNull()) {
244 if (Java_ShortcutHelper_isIconLargeEnoughForLauncher(env, bitmap.width(), 231 if (Java_ShortcutHelper_isIconLargeEnoughForLauncher(env, bitmap.width(),
245 bitmap.height())) { 232 bitmap.height())) {
246 ScopedJavaLocalRef<jobject> java_bitmap = 233 ScopedJavaLocalRef<jobject> java_bitmap =
247 gfx::ConvertToJavaBitmap(&bitmap); 234 gfx::ConvertToJavaBitmap(&bitmap);
248 result = Java_ShortcutHelper_createHomeScreenIconFromWebIcon( 235 result =
249 env, java_bitmap.obj()); 236 Java_ShortcutHelper_createHomeScreenIconFromWebIcon(env, java_bitmap);
250 } 237 }
251 } 238 }
252 239
253 if (result.is_null()) { 240 if (result.is_null()) {
254 ScopedJavaLocalRef<jstring> java_url = 241 ScopedJavaLocalRef<jstring> java_url =
255 base::android::ConvertUTF8ToJavaString(env, url.spec()); 242 base::android::ConvertUTF8ToJavaString(env, url.spec());
256 SkColor mean_color = SkColorSetRGB( 243 SkColor mean_color = SkColorSetRGB(
257 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue); 244 kDefaultRGBIconValue, kDefaultRGBIconValue, kDefaultRGBIconValue);
258 245
259 if (!bitmap.isNull()) 246 if (!bitmap.isNull())
260 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap); 247 mean_color = color_utils::CalculateKMeanColorOfBitmap(bitmap);
261 248
262 *is_generated = true; 249 *is_generated = true;
263 result = Java_ShortcutHelper_generateHomeScreenIcon( 250 result = Java_ShortcutHelper_generateHomeScreenIcon(
264 env, java_url.obj(), SkColorGetR(mean_color), SkColorGetG(mean_color), 251 env, java_url, SkColorGetR(mean_color), SkColorGetG(mean_color),
265 SkColorGetB(mean_color)); 252 SkColorGetB(mean_color));
266 } 253 }
267 254
268 return result.obj() 255 return result.obj()
269 ? gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj())) 256 ? gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(result.obj()))
270 : SkBitmap(); 257 : SkBitmap();
271 } 258 }
272 259
273 // static 260 // static
274 bool ShortcutHelper::IsWebApkInstalled(const GURL& url) { 261 bool ShortcutHelper::IsWebApkInstalled(const GURL& url) {
275 JNIEnv* env = base::android::AttachCurrentThread(); 262 JNIEnv* env = base::android::AttachCurrentThread();
276 ScopedJavaLocalRef<jstring> java_url = 263 ScopedJavaLocalRef<jstring> java_url =
277 base::android::ConvertUTF8ToJavaString(env, url.spec()); 264 base::android::ConvertUTF8ToJavaString(env, url.spec());
278 return Java_ShortcutHelper_isWebApkInstalled(env, java_url.obj()); 265 return Java_ShortcutHelper_isWebApkInstalled(env, java_url);
279 } 266 }
280 267
281 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) { 268 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) {
282 JNIEnv* env = base::android::AttachCurrentThread(); 269 JNIEnv* env = base::android::AttachCurrentThread();
283 ScopedJavaLocalRef<jstring> java_url = 270 ScopedJavaLocalRef<jstring> java_url =
284 base::android::ConvertUTF8ToJavaString(env, url.spec()); 271 base::android::ConvertUTF8ToJavaString(env, url.spec());
285 ScopedJavaLocalRef<jstring> java_scope_url = 272 ScopedJavaLocalRef<jstring> java_scope_url =
286 Java_ShortcutHelper_getScopeFromUrl(env, java_url.obj()); 273 Java_ShortcutHelper_getScopeFromUrl(env, java_url);
287 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); 274 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url));
288 } 275 }
289 276
290 // Callback used by Java when the shortcut has been created. 277 // Callback used by Java when the shortcut has been created.
291 // |splash_image_callback| is a pointer to a base::Closure allocated in 278 // |splash_image_callback| is a pointer to a base::Closure allocated in
292 // AddShortcutWithSkBitmap, so reinterpret_cast it back and run it. 279 // AddShortcutWithSkBitmap, so reinterpret_cast it back and run it.
293 // 280 //
294 // This callback should only ever be called when the shortcut was for a 281 // This callback should only ever be called when the shortcut was for a
295 // webapp-capable site; otherwise, |splash_image_callback| will have never been 282 // webapp-capable site; otherwise, |splash_image_callback| will have never been
296 // allocated and doesn't need to be run or deleted. 283 // allocated and doesn't need to be run or deleted.
297 void OnWebappDataStored(JNIEnv* env, 284 void OnWebappDataStored(JNIEnv* env,
298 const JavaParamRef<jclass>& clazz, 285 const JavaParamRef<jclass>& clazz,
299 jlong jsplash_image_callback) { 286 jlong jsplash_image_callback) {
300 DCHECK(jsplash_image_callback); 287 DCHECK(jsplash_image_callback);
301 base::Closure* splash_image_callback = 288 base::Closure* splash_image_callback =
302 reinterpret_cast<base::Closure*>(jsplash_image_callback); 289 reinterpret_cast<base::Closure*>(jsplash_image_callback);
303 splash_image_callback->Run(); 290 splash_image_callback->Run();
304 delete splash_image_callback; 291 delete splash_image_callback;
305 } 292 }
306 293
307 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 294 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
308 return RegisterNativesImpl(env); 295 return RegisterNativesImpl(env);
309 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/android/service_tab_launcher.cc ('k') | chrome/browser/android/signin/account_management_screen_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698