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/cocoa/history_menu_bridge.h" | 5 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 455 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
456 FaviconService::Handle handle = service->GetFaviconForURL( | 456 FaviconService::Handle handle = service->GetFaviconForURL( |
457 item->url, history::FAVICON, &favicon_consumer_, | 457 item->url, history::FAVICON, &favicon_consumer_, |
458 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); | 458 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); |
459 favicon_consumer_.SetClientData(service, handle, item); | 459 favicon_consumer_.SetClientData(service, handle, item); |
460 item->icon_handle = handle; | 460 item->icon_handle = handle; |
461 item->icon_requested = true; | 461 item->icon_requested = true; |
462 } | 462 } |
463 | 463 |
464 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, | 464 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, |
465 history::FaviconData favicon) { | 465 history::FaviconData favicon_data, |
466 std::vector<GURL> icon_urls_in_db) { | |
466 // Since we're going to do Cocoa-y things, make sure this is the main thread. | 467 // Since we're going to do Cocoa-y things, make sure this is the main thread. |
467 DCHECK([NSThread isMainThread]); | 468 DCHECK([NSThread isMainThread]); |
468 | 469 |
469 HistoryItem* item = | 470 HistoryItem* item = |
470 favicon_consumer_.GetClientData( | 471 favicon_consumer_.GetClientData( |
471 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); | 472 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); |
472 DCHECK(item); | 473 DCHECK(item); |
473 item->icon_requested = false; | 474 item->icon_requested = false; |
474 item->icon_handle = 0; | 475 item->icon_handle = 0; |
475 | 476 |
476 // Convert the raw data to Skia and then to a NSImage. | 477 // Convert the raw data to Skia and then to a NSImage. |
477 // TODO(rsesek): Is there an easier way to do this? | 478 // TODO(rsesek): Is there an easier way to do this? |
478 SkBitmap icon; | 479 SkBitmap icon; |
479 if (favicon.is_valid() && | 480 if (favicon_data.has_valid_bitmaps()) { |
480 gfx::PNGCodec::Decode(favicon.image_data->front(), | 481 scoped_refptr<base::RefCountedMemory> bitmap_data = |
481 favicon.image_data->size(), &icon)) { | 482 favicon_data.first_bitmap(); |
482 NSImage* image = gfx::SkBitmapToNSImage(icon); | 483 if (gfx::PNGCodec::Decode(bitmap_data->front(), |
sky
2012/08/23 15:50:38
Would be nice if there was a method on favicondata
| |
483 if (image) { | 484 bitmap_data->size(), &icon)) { |
484 // The conversion was successful. | 485 NSImage* image = gfx::SkBitmapToNSImage(icon); |
485 item->icon.reset([image retain]); | 486 if (image) { |
486 [item->menu_item setImage:item->icon.get()]; | 487 // The conversion was successful. |
488 item->icon.reset([image retain]); | |
489 [item->menu_item setImage:item->icon.get()]; | |
490 } | |
487 } | 491 } |
488 } | 492 } |
489 } | 493 } |
490 | 494 |
491 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 495 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
492 DCHECK(item); | 496 DCHECK(item); |
493 if (item->icon_requested) { | 497 if (item->icon_requested) { |
494 FaviconService* service = | 498 FaviconService* service = |
495 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 499 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
496 service->CancelRequest(item->icon_handle); | 500 service->CancelRequest(item->icon_handle); |
497 item->icon_requested = false; | 501 item->icon_requested = false; |
498 item->icon_handle = 0; | 502 item->icon_handle = 0; |
499 } | 503 } |
500 } | 504 } |
OLD | NEW |