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" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU | 12 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU |
13 #import "chrome/browser/app_controller_mac.h" | 13 #import "chrome/browser/app_controller_mac.h" |
14 #include "chrome/browser/history/page_usage_data.h" | 14 #include "chrome/browser/history/page_usage_data.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sessions/session_types.h" | 16 #include "chrome/browser/sessions/session_types.h" |
17 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
18 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" | 18 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
20 #include "content/common/notification_registrar.h" | 21 #include "content/common/notification_registrar.h" |
21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
24 #include "grit/theme_resources_standard.h" | 25 #include "grit/theme_resources_standard.h" |
25 #include "grit/ui_resources.h" | 26 #include "grit/ui_resources.h" |
26 #include "skia/ext/skia_utils_mac.h" | 27 #include "skia/ext/skia_utils_mac.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 97 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
97 default_favicon_.reset([gfx::GetCachedImageWithName(@"nav.pdf") retain]); | 98 default_favicon_.reset([gfx::GetCachedImageWithName(@"nav.pdf") retain]); |
98 | 99 |
99 // Set the static icons in the menu. | 100 // Set the static icons in the menu. |
100 NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY]; | 101 NSMenuItem* item = [HistoryMenu() itemWithTag:IDC_SHOW_HISTORY]; |
101 [item setImage:rb.GetNativeImageNamed(IDR_HISTORY_FAVICON)]; | 102 [item setImage:rb.GetNativeImageNamed(IDR_HISTORY_FAVICON)]; |
102 | 103 |
103 // The service is not ready for use yet, so become notified when it does. | 104 // The service is not ready for use yet, so become notified when it does. |
104 if (!history_service_) { | 105 if (!history_service_) { |
105 registrar_.Add( | 106 registrar_.Add( |
106 this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_)); | 107 this, chrome::NOTIFICATION_HISTORY_LOADED, Source<Profile>(profile_)); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 // Note that all requests sent to either the history service or the favicon | 111 // Note that all requests sent to either the history service or the favicon |
111 // service will be automatically cancelled by their respective Consumers, so | 112 // service will be automatically cancelled by their respective Consumers, so |
112 // task cancellation is not done manually here in the dtor. | 113 // task cancellation is not done manually here in the dtor. |
113 HistoryMenuBridge::~HistoryMenuBridge() { | 114 HistoryMenuBridge::~HistoryMenuBridge() { |
114 // Unregister ourselves as observers and notifications. | 115 // Unregister ourselves as observers and notifications. |
115 if (history_service_) { | 116 if (history_service_) { |
116 const NotificationSource& src = NotificationService::AllSources(); | 117 const NotificationSource& src = NotificationService::AllSources(); |
117 registrar_.Remove(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, src); | 118 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, |
118 registrar_.Remove(this, NotificationType::HISTORY_URL_VISITED, src); | 119 src); |
119 registrar_.Remove(this, NotificationType::HISTORY_URLS_DELETED, src); | 120 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, src); |
| 121 registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, src); |
120 } else { | 122 } else { |
121 registrar_.Remove( | 123 registrar_.Remove( |
122 this, NotificationType::HISTORY_LOADED, Source<Profile>(profile_)); | 124 this, chrome::NOTIFICATION_HISTORY_LOADED, Source<Profile>(profile_)); |
123 } | 125 } |
124 | 126 |
125 if (tab_restore_service_) | 127 if (tab_restore_service_) |
126 tab_restore_service_->RemoveObserver(this); | 128 tab_restore_service_->RemoveObserver(this); |
127 | 129 |
128 // Since the map owns the HistoryItems, delete anything that still exists. | 130 // Since the map owns the HistoryItems, delete anything that still exists. |
129 std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.begin(); | 131 std::map<NSMenuItem*, HistoryItem*>::iterator it = menu_item_map_.begin(); |
130 while (it != menu_item_map_.end()) { | 132 while (it != menu_item_map_.end()) { |
131 HistoryItem* item = it->second; | 133 HistoryItem* item = it->second; |
132 menu_item_map_.erase(it++); | 134 menu_item_map_.erase(it++); |
133 delete item; | 135 delete item; |
134 } | 136 } |
135 } | 137 } |
136 | 138 |
137 void HistoryMenuBridge::Observe(NotificationType type, | 139 void HistoryMenuBridge::Observe(int type, |
138 const NotificationSource& source, | 140 const NotificationSource& source, |
139 const NotificationDetails& details) { | 141 const NotificationDetails& details) { |
140 // A history service is now ready. Check to see if it's the one for the main | 142 // A history service is now ready. Check to see if it's the one for the main |
141 // profile. If so, perform final initialization. | 143 // profile. If so, perform final initialization. |
142 if (type == NotificationType::HISTORY_LOADED) { | 144 if (type == chrome::NOTIFICATION_HISTORY_LOADED) { |
143 HistoryService* hs = | 145 HistoryService* hs = |
144 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 146 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
145 if (hs != NULL && hs->BackendLoaded()) { | 147 if (hs != NULL && hs->BackendLoaded()) { |
146 history_service_ = hs; | 148 history_service_ = hs; |
147 Init(); | 149 Init(); |
148 | 150 |
149 // Found our HistoryService, so stop listening for this notification. | 151 // Found our HistoryService, so stop listening for this notification. |
150 registrar_.Remove(this, | 152 registrar_.Remove(this, |
151 NotificationType::HISTORY_LOADED, | 153 chrome::NOTIFICATION_HISTORY_LOADED, |
152 Source<Profile>(profile_)); | 154 Source<Profile>(profile_)); |
153 } | 155 } |
154 } | 156 } |
155 | 157 |
156 // All other notification types that we observe indicate that the history has | 158 // All other notification types that we observe indicate that the history has |
157 // changed and we need to rebuild. | 159 // changed and we need to rebuild. |
158 need_recreate_ = true; | 160 need_recreate_ = true; |
159 CreateMenu(); | 161 CreateMenu(); |
160 } | 162 } |
161 | 163 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 [item->menu_item setToolTip:tooltip]; | 358 [item->menu_item setToolTip:tooltip]; |
357 | 359 |
358 [menu insertItem:item->menu_item.get() atIndex:index]; | 360 [menu insertItem:item->menu_item.get() atIndex:index]; |
359 menu_item_map_.insert(std::make_pair(item->menu_item.get(), item)); | 361 menu_item_map_.insert(std::make_pair(item->menu_item.get(), item)); |
360 | 362 |
361 return item->menu_item.get(); | 363 return item->menu_item.get(); |
362 } | 364 } |
363 | 365 |
364 void HistoryMenuBridge::Init() { | 366 void HistoryMenuBridge::Init() { |
365 const NotificationSource& source = NotificationService::AllSources(); | 367 const NotificationSource& source = NotificationService::AllSources(); |
366 registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source); | 368 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, |
367 registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source); | 369 source); |
368 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source); | 370 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source); |
| 371 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
369 } | 372 } |
370 | 373 |
371 void HistoryMenuBridge::CreateMenu() { | 374 void HistoryMenuBridge::CreateMenu() { |
372 // If we're currently running CreateMenu(), wait until it finishes. | 375 // If we're currently running CreateMenu(), wait until it finishes. |
373 if (create_in_progress_) | 376 if (create_in_progress_) |
374 return; | 377 return; |
375 create_in_progress_ = true; | 378 create_in_progress_ = true; |
376 need_recreate_ = false; | 379 need_recreate_ = false; |
377 | 380 |
378 DCHECK(history_service_); | 381 DCHECK(history_service_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 479 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
477 DCHECK(item); | 480 DCHECK(item); |
478 if (item->icon_requested) { | 481 if (item->icon_requested) { |
479 FaviconService* service = | 482 FaviconService* service = |
480 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 483 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
481 service->CancelRequest(item->icon_handle); | 484 service->CancelRequest(item->icon_handle); |
482 item->icon_requested = false; | 485 item->icon_requested = false; |
483 item->icon_handle = NULL; | 486 item->icon_handle = NULL; |
484 } | 487 } |
485 } | 488 } |
OLD | NEW |