| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU | 13 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU |
| 14 #import "chrome/browser/app_controller_mac.h" | 14 #import "chrome/browser/app_controller_mac.h" |
| 15 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/history/page_usage_data.h" | 17 #include "chrome/browser/history/page_usage_data.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/session_types.h" | 19 #include "chrome/browser/sessions/session_types.h" |
| 19 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 20 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 20 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" | 21 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 item->session_id = entry.id; | 446 item->session_id = entry.id; |
| 446 | 447 |
| 447 // Tab navigations don't come with icons, so we always have to request them. | 448 // Tab navigations don't come with icons, so we always have to request them. |
| 448 GetFaviconForHistoryItem(item); | 449 GetFaviconForHistoryItem(item); |
| 449 | 450 |
| 450 return item; | 451 return item; |
| 451 } | 452 } |
| 452 | 453 |
| 453 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { | 454 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { |
| 454 FaviconService* service = | 455 FaviconService* service = |
| 455 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 456 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 456 FaviconService::Handle handle = service->GetFaviconForURL( | 457 FaviconService::Handle handle = service->GetFaviconForURL( |
| 457 item->url, history::FAVICON, &favicon_consumer_, | 458 profile_, item->url, history::FAVICON, &favicon_consumer_, |
| 458 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); | 459 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); |
| 459 favicon_consumer_.SetClientData(service, handle, item); | 460 favicon_consumer_.SetClientData(service, handle, item); |
| 460 item->icon_handle = handle; | 461 item->icon_handle = handle; |
| 461 item->icon_requested = true; | 462 item->icon_requested = true; |
| 462 } | 463 } |
| 463 | 464 |
| 464 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, | 465 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, |
| 465 history::FaviconData favicon) { | 466 history::FaviconData favicon) { |
| 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 FaviconServiceFactory::GetForProfile( |
| 473 profile_, Profile::EXPLICIT_ACCESS), handle); |
| 472 DCHECK(item); | 474 DCHECK(item); |
| 473 item->icon_requested = false; | 475 item->icon_requested = false; |
| 474 item->icon_handle = 0; | 476 item->icon_handle = 0; |
| 475 | 477 |
| 476 // Convert the raw data to Skia and then to a NSImage. | 478 // Convert the raw data to Skia and then to a NSImage. |
| 477 // TODO(rsesek): Is there an easier way to do this? | 479 // TODO(rsesek): Is there an easier way to do this? |
| 478 SkBitmap icon; | 480 SkBitmap icon; |
| 479 if (favicon.is_valid() && | 481 if (favicon.is_valid() && |
| 480 gfx::PNGCodec::Decode(favicon.image_data->front(), | 482 gfx::PNGCodec::Decode(favicon.image_data->front(), |
| 481 favicon.image_data->size(), &icon)) { | 483 favicon.image_data->size(), &icon)) { |
| 482 NSImage* image = gfx::SkBitmapToNSImage(icon); | 484 NSImage* image = gfx::SkBitmapToNSImage(icon); |
| 483 if (image) { | 485 if (image) { |
| 484 // The conversion was successful. | 486 // The conversion was successful. |
| 485 item->icon.reset([image retain]); | 487 item->icon.reset([image retain]); |
| 486 [item->menu_item setImage:item->icon.get()]; | 488 [item->menu_item setImage:item->icon.get()]; |
| 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 = FaviconServiceFactory::GetForProfile( |
| 495 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 497 profile_, 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 = 0; | 500 item->icon_handle = 0; |
| 499 } | 501 } |
| 500 } | 502 } |
| OLD | NEW |