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

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

Issue 934183002: Make the ShortcutHelper toast instead of send the user home for web app banners (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix existing null access, change for comments Created 5 years, 10 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
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <limits> 8 #include <limits>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 case MANIFEST_ICON_STATUS_FETCHING: 209 case MANIFEST_ICON_STATUS_FETCHING:
210 // ::OnDidDownloadIcon() will call AddShortcutUsingManifestIcon(). 210 // ::OnDidDownloadIcon() will call AddShortcutUsingManifestIcon().
211 break; 211 break;
212 case MANIFEST_ICON_STATUS_DONE: 212 case MANIFEST_ICON_STATUS_DONE:
213 AddShortcutUsingManifestIcon(); 213 AddShortcutUsingManifestIcon();
214 break; 214 break;
215 } 215 }
216 } 216 }
217 217
218 void ShortcutHelper::AddShortcutUsingManifestIcon() { 218 void ShortcutHelper::AddShortcutUsingManifestIcon() {
219 RecordAddToHomescreen();
220
219 // Stop observing so we don't get destroyed while doing the last steps. 221 // Stop observing so we don't get destroyed while doing the last steps.
220 Observe(NULL); 222 Observe(NULL);
221 223
222 RecordAddToHomescreen();
223
224 base::WorkerPool::PostTask( 224 base::WorkerPool::PostTask(
225 FROM_HERE, 225 FROM_HERE,
226 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, 226 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap,
227 shortcut_info_, 227 shortcut_info_,
228 manifest_icon_), 228 manifest_icon_,
229 true),
229 true); 230 true);
230 231
231 Destroy(); 232 Destroy();
232 } 233 }
233 234
234 void ShortcutHelper::AddShortcutUsingFavicon() { 235 void ShortcutHelper::AddShortcutUsingFavicon() {
235 RecordAddToHomescreen(); 236 RecordAddToHomescreen();
236 237
237 Profile* profile = 238 Profile* profile =
238 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 239 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 300 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
300 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 301 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
301 302
302 SkBitmap icon_bitmap; 303 SkBitmap icon_bitmap;
303 if (bitmap_result.is_valid()) { 304 if (bitmap_result.is_valid()) {
304 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), 305 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
305 bitmap_result.bitmap_data->size(), 306 bitmap_result.bitmap_data->size(),
306 &icon_bitmap); 307 &icon_bitmap);
307 } 308 }
308 309
309 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap); 310 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap, true);
310 } 311 }
311 312
312 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 313 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
313 const ShortcutInfo& info, 314 const ShortcutInfo& info,
314 const SkBitmap& icon_bitmap) { 315 const SkBitmap& icon_bitmap,
316 const bool return_to_homescreen) {
315 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 317 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
316 318
317 SkColor color = color_utils::CalculateKMeanColorOfBitmap(icon_bitmap); 319 SkColor color = color_utils::CalculateKMeanColorOfBitmap(icon_bitmap);
318 int r_value = SkColorGetR(color); 320 int r_value = SkColorGetR(color);
319 int g_value = SkColorGetG(color); 321 int g_value = SkColorGetG(color);
320 int b_value = SkColorGetB(color); 322 int b_value = SkColorGetB(color);
321 323
322 // Send the data to the Java side to create the shortcut. 324 // Send the data to the Java side to create the shortcut.
323 JNIEnv* env = base::android::AttachCurrentThread(); 325 JNIEnv* env = base::android::AttachCurrentThread();
324 ScopedJavaLocalRef<jstring> java_url = 326 ScopedJavaLocalRef<jstring> java_url =
325 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); 327 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
326 ScopedJavaLocalRef<jstring> java_title = 328 ScopedJavaLocalRef<jstring> java_title =
327 base::android::ConvertUTF16ToJavaString(env, info.title); 329 base::android::ConvertUTF16ToJavaString(env, info.title);
328 ScopedJavaLocalRef<jobject> java_bitmap; 330 ScopedJavaLocalRef<jobject> java_bitmap;
329 if (icon_bitmap.getSize()) 331 if (icon_bitmap.getSize())
330 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 332 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
331 333
332 Java_ShortcutHelper_addShortcut( 334 Java_ShortcutHelper_addShortcut(
333 env, 335 env,
334 base::android::GetApplicationContext(), 336 base::android::GetApplicationContext(),
335 java_url.obj(), 337 java_url.obj(),
336 java_title.obj(), 338 java_title.obj(),
337 java_bitmap.obj(), 339 java_bitmap.obj(),
338 r_value, 340 r_value,
339 g_value, 341 g_value,
340 b_value, 342 b_value,
341 info.display == content::Manifest::DISPLAY_MODE_STANDALONE, 343 info.display == content::Manifest::DISPLAY_MODE_STANDALONE,
342 info.orientation); 344 info.orientation,
345 return_to_homescreen);
343 } 346 }
344 347
345 void ShortcutHelper::RecordAddToHomescreen() { 348 void ShortcutHelper::RecordAddToHomescreen() {
346 // Record that the shortcut has been added, so no banners will be shown 349 // Record that the shortcut has been added, so no banners will be shown
347 // for this app. 350 // for this app.
348 AppBannerSettingsHelper::RecordBannerEvent( 351 AppBannerSettingsHelper::RecordBannerEvent(
349 web_contents(), shortcut_info_.url, shortcut_info_.url.spec(), 352 web_contents(), shortcut_info_.url, shortcut_info_.url.spec(),
350 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 353 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
351 base::Time::Now()); 354 base::Time::Now());
352 } 355 }
OLDNEW
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698