| OLD | NEW |
| 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/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 17 #include "chrome/browser/ui/webui/favicon_source.h" | 18 #include "chrome/browser/ui/webui/favicon_source.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" |
| 22 #include "ui/gfx/color_analysis.h" | 23 #include "ui/gfx/color_analysis.h" |
| 23 | 24 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 344 |
| 344 int64 id; | 345 int64 id; |
| 345 bool is_partner; | 346 bool is_partner; |
| 346 if (args && !args->empty() && ParseNtpBookmarkId(args, &id, &is_partner)) { | 347 if (args && !args->empty() && ParseNtpBookmarkId(args, &id, &is_partner)) { |
| 347 DCHECK(partner_bookmarks_shim_ != NULL); | 348 DCHECK(partner_bookmarks_shim_ != NULL); |
| 348 const BookmarkNode* node = | 349 const BookmarkNode* node = |
| 349 partner_bookmarks_shim_->GetNodeByID(id, is_partner); | 350 partner_bookmarks_shim_->GetNodeByID(id, is_partner); |
| 350 if (!node) | 351 if (!node) |
| 351 return; | 352 return; |
| 352 | 353 |
| 353 FaviconService* favicon_service = profile->GetFaviconService( | 354 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 354 Profile::EXPLICIT_ACCESS); | 355 profile, Profile::EXPLICIT_ACCESS); |
| 355 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 356 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 357 profile, |
| 356 node->url(), | 358 node->url(), |
| 357 history::FAVICON | history::TOUCH_ICON, | 359 history::FAVICON | history::TOUCH_ICON, |
| 358 &cancelable_consumer_, | 360 &cancelable_consumer_, |
| 359 base::Bind(&BookmarksHandler::OnShortcutFaviconDataAvailable, | 361 base::Bind(&BookmarksHandler::OnShortcutFaviconDataAvailable, |
| 360 base::Unretained(this))); | 362 base::Unretained(this))); |
| 361 cancelable_consumer_.SetClientData(favicon_service, handle, node); | 363 cancelable_consumer_.SetClientData(favicon_service, handle, node); |
| 362 } | 364 } |
| 363 } | 365 } |
| 364 | 366 |
| 365 void BookmarksHandler::OnShortcutFaviconDataAvailable( | 367 void BookmarksHandler::OnShortcutFaviconDataAvailable( |
| 366 FaviconService::Handle handle, | 368 FaviconService::Handle handle, |
| 367 history::FaviconData favicon) { | 369 history::FaviconData favicon) { |
| 368 SkColor color = SK_ColorWHITE; | 370 SkColor color = SK_ColorWHITE; |
| 369 SkBitmap favicon_bitmap; | 371 SkBitmap favicon_bitmap; |
| 370 if (favicon.is_valid()) { | 372 if (favicon.is_valid()) { |
| 371 color = GetDominantColorForFavicon(favicon.image_data); | 373 color = GetDominantColorForFavicon(favicon.image_data); |
| 372 gfx::PNGCodec::Decode(favicon.image_data->front(), | 374 gfx::PNGCodec::Decode(favicon.image_data->front(), |
| 373 favicon.image_data->size(), | 375 favicon.image_data->size(), |
| 374 &favicon_bitmap); | 376 &favicon_bitmap); |
| 375 } | 377 } |
| 376 | 378 |
| 377 Profile* profile = Profile::FromBrowserContext( | 379 Profile* profile = Profile::FromBrowserContext( |
| 378 web_ui()->GetWebContents()->GetBrowserContext()); | 380 web_ui()->GetWebContents()->GetBrowserContext()); |
| 379 const BookmarkNode* node = cancelable_consumer_.GetClientData( | 381 const BookmarkNode* node = cancelable_consumer_.GetClientData( |
| 380 profile->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); | 382 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS), |
| 383 handle); |
| 381 | 384 |
| 382 TabAndroid* tab = TabAndroid::FromWebContents( | 385 TabAndroid* tab = TabAndroid::FromWebContents( |
| 383 web_ui()->GetWebContents()); | 386 web_ui()->GetWebContents()); |
| 384 if (tab) { | 387 if (tab) { |
| 385 tab->AddShortcutToBookmark(node->url(), node->GetTitle(), | 388 tab->AddShortcutToBookmark(node->url(), node->GetTitle(), |
| 386 favicon_bitmap, SkColorGetR(color), | 389 favicon_bitmap, SkColorGetR(color), |
| 387 SkColorGetG(color), SkColorGetB(color)); | 390 SkColorGetG(color), SkColorGetB(color)); |
| 388 } | 391 } |
| 389 } | 392 } |
| OLD | NEW |