OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.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" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // Tab navigations don't come with icons, so we always have to request them. | 415 // Tab navigations don't come with icons, so we always have to request them. |
416 GetFaviconForHistoryItem(item); | 416 GetFaviconForHistoryItem(item); |
417 | 417 |
418 return item; | 418 return item; |
419 } | 419 } |
420 | 420 |
421 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { | 421 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { |
422 FaviconService* service = | 422 FaviconService* service = |
423 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 423 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
424 FaviconService::Handle handle = service->GetFaviconForURL(item->url, | 424 FaviconService::Handle handle = service->GetFaviconForURL(item->url, |
425 &favicon_consumer_, | 425 history::FAVICON, &favicon_consumer_, |
426 NewCallback(this, &HistoryMenuBridge::GotFaviconData)); | 426 NewCallback(this, &HistoryMenuBridge::GotFaviconData)); |
427 favicon_consumer_.SetClientData(service, handle, item); | 427 favicon_consumer_.SetClientData(service, handle, item); |
428 item->icon_handle = handle; | 428 item->icon_handle = handle; |
429 item->icon_requested = true; | 429 item->icon_requested = true; |
430 } | 430 } |
431 | 431 |
432 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, | 432 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, |
433 bool know_favicon, | 433 history::FaviconData favicon) { |
434 scoped_refptr<RefCountedMemory> data, | |
435 bool expired, | |
436 GURL url) { | |
437 // Since we're going to do Cocoa-y things, make sure this is the main thread. | 434 // Since we're going to do Cocoa-y things, make sure this is the main thread. |
438 DCHECK([NSThread isMainThread]); | 435 DCHECK([NSThread isMainThread]); |
439 | 436 |
440 HistoryItem* item = | 437 HistoryItem* item = |
441 favicon_consumer_.GetClientData( | 438 favicon_consumer_.GetClientData( |
442 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); | 439 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); |
443 DCHECK(item); | 440 DCHECK(item); |
444 item->icon_requested = false; | 441 item->icon_requested = false; |
445 item->icon_handle = NULL; | 442 item->icon_handle = NULL; |
446 | 443 |
447 // Convert the raw data to Skia and then to a NSImage. | 444 // Convert the raw data to Skia and then to a NSImage. |
448 // TODO(rsesek): Is there an easier way to do this? | 445 // TODO(rsesek): Is there an easier way to do this? |
449 SkBitmap icon; | 446 SkBitmap icon; |
450 if (know_favicon && data.get() && data->size() && | 447 if (favicon.is_valid() && |
451 gfx::PNGCodec::Decode(data->front(), data->size(), &icon)) { | 448 gfx::PNGCodec::Decode(favicon.image_data->front(), |
| 449 favicon.image_data->size(), &icon)) { |
452 NSImage* image = gfx::SkBitmapToNSImage(icon); | 450 NSImage* image = gfx::SkBitmapToNSImage(icon); |
453 if (image) { | 451 if (image) { |
454 // The conversion was successful. | 452 // The conversion was successful. |
455 item->icon.reset([image retain]); | 453 item->icon.reset([image retain]); |
456 [item->menu_item setImage:item->icon.get()]; | 454 [item->menu_item setImage:item->icon.get()]; |
457 } | 455 } |
458 } | 456 } |
459 } | 457 } |
460 | 458 |
461 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 459 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
462 DCHECK(item); | 460 DCHECK(item); |
463 if (item->icon_requested) { | 461 if (item->icon_requested) { |
464 FaviconService* service = | 462 FaviconService* service = |
465 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 463 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
466 service->CancelRequest(item->icon_handle); | 464 service->CancelRequest(item->icon_handle); |
467 item->icon_requested = false; | 465 item->icon_requested = false; |
468 item->icon_handle = NULL; | 466 item->icon_handle = NULL; |
469 } | 467 } |
470 } | 468 } |
OLD | NEW |