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

Side by Side Diff: chrome/browser/ui/webui/ntp/android/bookmarks_handler.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/ntp/android/bookmarks_handler.h" 5 #include "chrome/browser/ui/webui/ntp/android/bookmarks_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/android/tab_android.h" 11 #include "chrome/browser/android/tab_android.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
14 #include "chrome/browser/favicon/favicon_service_factory.h" 14 #include "chrome/browser/favicon/favicon_service_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
18 #include "chrome/browser/ui/webui/favicon_source.h" 18 #include "chrome/browser/ui/webui/favicon_source.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/codec/png_codec.h" 22 #include "ui/gfx/codec/png_codec.h"
23 #include "ui/gfx/color_analysis.h" 23 #include "ui/gfx/color_analysis.h"
24 #include "ui/gfx/favicon_size.h"
24 25
25 using base::Int64ToString; 26 using base::Int64ToString;
26 using content::BrowserThread; 27 using content::BrowserThread;
27 28
28 namespace { 29 namespace {
29 30
30 static const char* kParentIdParam = "parent_id"; 31 static const char* kParentIdParam = "parent_id";
31 static const char* kNodeIdParam = "node_id"; 32 static const char* kNodeIdParam = "node_id";
32 33
33 // Parses a bookmark ID passed back from the NTP. The IDs differ from the 34 // Parses a bookmark ID passed back from the NTP. The IDs differ from the
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 bool is_partner; 347 bool is_partner;
347 if (args && !args->empty() && ParseNtpBookmarkId(args, &id, &is_partner)) { 348 if (args && !args->empty() && ParseNtpBookmarkId(args, &id, &is_partner)) {
348 DCHECK(partner_bookmarks_shim_ != NULL); 349 DCHECK(partner_bookmarks_shim_ != NULL);
349 const BookmarkNode* node = 350 const BookmarkNode* node =
350 partner_bookmarks_shim_->GetNodeByID(id, is_partner); 351 partner_bookmarks_shim_->GetNodeByID(id, is_partner);
351 if (!node) 352 if (!node)
352 return; 353 return;
353 354
354 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 355 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
355 profile, Profile::EXPLICIT_ACCESS); 356 profile, Profile::EXPLICIT_ACCESS);
356 FaviconService::Handle handle = favicon_service->GetFaviconForURL( 357 FaviconService::Handle handle = favicon_service->GetRawFaviconForURL(
357 profile, 358 profile,
358 node->url(), 359 node->url(),
359 history::FAVICON | history::TOUCH_ICON, 360 history::FAVICON | history::TOUCH_ICON,
361 gfx::kFaviconSize,
362 ui::SCALE_FACTOR_100P,
360 &cancelable_consumer_, 363 &cancelable_consumer_,
361 base::Bind(&BookmarksHandler::OnShortcutFaviconDataAvailable, 364 base::Bind(&BookmarksHandler::OnShortcutFaviconDataAvailable,
362 base::Unretained(this))); 365 base::Unretained(this)));
363 cancelable_consumer_.SetClientData(favicon_service, handle, node); 366 cancelable_consumer_.SetClientData(favicon_service, handle, node);
364 } 367 }
365 } 368 }
366 369
367 void BookmarksHandler::OnShortcutFaviconDataAvailable( 370 void BookmarksHandler::OnShortcutFaviconDataAvailable(
368 FaviconService::Handle handle, 371 FaviconService::Handle handle,
369 history::FaviconData favicon) { 372 const history::FaviconBitmapResult& bitmap_result) {
370 SkColor color = SK_ColorWHITE; 373 SkColor color = SK_ColorWHITE;
371 SkBitmap favicon_bitmap; 374 SkBitmap favicon_bitmap;
372 if (favicon.is_valid()) { 375 if (bitmap_result.is_valid()) {
373 color = GetDominantColorForFavicon(favicon.image_data); 376 color = GetDominantColorForFavicon(bitmap_result.bitmap_data);
374 gfx::PNGCodec::Decode(favicon.image_data->front(), 377 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
375 favicon.image_data->size(), 378 bitmap_result.bitmap_data->size(),
376 &favicon_bitmap); 379 &favicon_bitmap);
377 } 380 }
378 381
379 Profile* profile = Profile::FromBrowserContext( 382 Profile* profile = Profile::FromBrowserContext(
380 web_ui()->GetWebContents()->GetBrowserContext()); 383 web_ui()->GetWebContents()->GetBrowserContext());
381 const BookmarkNode* node = cancelable_consumer_.GetClientData( 384 const BookmarkNode* node = cancelable_consumer_.GetClientData(
382 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS), 385 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS),
383 handle); 386 handle);
384 387
385 TabAndroid* tab = TabAndroid::FromWebContents( 388 TabAndroid* tab = TabAndroid::FromWebContents(
386 web_ui()->GetWebContents()); 389 web_ui()->GetWebContents());
387 if (tab) { 390 if (tab) {
388 tab->AddShortcutToBookmark(node->url(), node->GetTitle(), 391 tab->AddShortcutToBookmark(node->url(), node->GetTitle(),
389 favicon_bitmap, SkColorGetR(color), 392 favicon_bitmap, SkColorGetR(color),
390 SkColorGetG(color), SkColorGetB(color)); 393 SkColorGetG(color), SkColorGetB(color));
391 } 394 }
392 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698