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 // Since we're going to do Cocoa-y things, make sure this is the main thread. | 466 // Since we're going to do Cocoa-y things, make sure this is the main thread. |
467 DCHECK([NSThread isMainThread]); | 467 DCHECK([NSThread isMainThread]); |
468 | 468 |
469 HistoryItem* item = | 469 HistoryItem* item = |
470 favicon_consumer_.GetClientData( | 470 favicon_consumer_.GetClientData( |
471 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); | 471 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); |
472 DCHECK(item); | 472 DCHECK(item); |
473 item->icon_requested = false; | 473 item->icon_requested = false; |
474 item->icon_handle = NULL; | 474 item->icon_handle = NULL; |
475 | 475 |
476 // Convert the raw data to Skia and then to a NSImage. | 476 // Convert the raw data to Skia and then to a NSImage. |
477 // TODO(rsesek): Is there an easier way to do this? | 477 // TODO(rsesek): Is there an easier way to do this? |
478 SkBitmap icon; | 478 SkBitmap icon; |
479 if (favicon.is_valid() && | 479 if (favicon_data.is_valid()) { |
480 gfx::PNGCodec::Decode(favicon.image_data->front(), | 480 const history::FaviconDataElement& element = favicon_data.elements[0]; |
481 favicon.image_data->size(), &icon)) { | 481 if (gfx::PNGCodec::Decode(element.bitmap_data->front(), |
482 NSImage* image = gfx::SkBitmapToNSImage(icon); | 482 element.bitmap_data->size(), &icon)) { |
483 if (image) { | 483 NSImage* image = gfx::SkBitmapToNSImage(icon); |
484 // The conversion was successful. | 484 if (image) { |
485 item->icon.reset([image retain]); | 485 // The conversion was successful. |
486 [item->menu_item setImage:item->icon.get()]; | 486 item->icon.reset([image retain]); |
| 487 [item->menu_item setImage:item->icon.get()]; |
| 488 } |
487 } | 489 } |
488 } | 490 } |
489 } | 491 } |
490 | 492 |
491 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 493 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
492 DCHECK(item); | 494 DCHECK(item); |
493 if (item->icon_requested) { | 495 if (item->icon_requested) { |
494 FaviconService* service = | 496 FaviconService* service = |
495 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 497 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
496 service->CancelRequest(item->icon_handle); | 498 service->CancelRequest(item->icon_handle); |
497 item->icon_requested = false; | 499 item->icon_requested = false; |
498 item->icon_handle = NULL; | 500 item->icon_handle = NULL; |
499 } | 501 } |
500 } | 502 } |
OLD | NEW |