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