OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ |
6 #define CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ | 6 #define CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_nsobject.h" | 13 #include "base/scoped_nsobject.h" |
14 #include "chrome/browser/cancelable_request.h" | 14 #include "chrome/browser/cancelable_request.h" |
15 #import "chrome/browser/favicon_service.h" | 15 #import "chrome/browser/favicon_service.h" |
16 #include "chrome/browser/history/history.h" | 16 #include "chrome/browser/history/history.h" |
17 #include "chrome/browser/sessions/session_id.h" | 17 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/tab_restore_service.h" | 18 #include "chrome/browser/sessions/tab_restore_service.h" |
| 19 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
19 #include "chrome/common/notification_observer.h" | 20 #include "chrome/common/notification_observer.h" |
20 | 21 |
21 class NavigationEntry; | 22 class NavigationEntry; |
22 class NotificationRegistrar; | 23 class NotificationRegistrar; |
23 class PageUsageData; | 24 class PageUsageData; |
24 class Profile; | 25 class Profile; |
25 class TabNavigationEntry; | 26 class TabNavigationEntry; |
| 27 class TabRestoreService; |
26 @class HistoryMenuCocoaController; | 28 @class HistoryMenuCocoaController; |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 class HistoryMenuBridgeTest; | 32 class HistoryMenuBridgeTest; |
31 | 33 |
32 } | 34 } |
33 | 35 |
34 // C++ bridge for the history menu; one per AppController (means there | 36 // C++ bridge for the history menu; one per AppController (means there |
35 // is only one). This class observes various data sources, namely the | 37 // is only one). This class observes various data sources, namely the |
(...skipping 11 matching lines...) Expand all Loading... |
47 // a range of [400,500) and do not go through CommandDispatch for their target- | 49 // a range of [400,500) and do not go through CommandDispatch for their target- |
48 // action mechanism. | 50 // action mechanism. |
49 // | 51 // |
50 // These menu items do not use firstResponder as their target. Rather, they are | 52 // These menu items do not use firstResponder as their target. Rather, they are |
51 // hooked directly up to the HistoryMenuCocoaController that then bridges back | 53 // hooked directly up to the HistoryMenuCocoaController that then bridges back |
52 // to this class. These items are created via the AddItemToMenu() helper. Also, | 54 // to this class. These items are created via the AddItemToMenu() helper. Also, |
53 // unlike the typical ownership model, this bridge owns its controller. The | 55 // unlike the typical ownership model, this bridge owns its controller. The |
54 // controller is very thin and only exists to interact with Cocoa, but this | 56 // controller is very thin and only exists to interact with Cocoa, but this |
55 // class does the bulk of the work. | 57 // class does the bulk of the work. |
56 class HistoryMenuBridge : public NotificationObserver, | 58 class HistoryMenuBridge : public NotificationObserver, |
57 public TabRestoreService::Observer { | 59 public TabRestoreServiceObserver { |
58 public: | 60 public: |
59 // This is a generalization of the data we store in the history menu because | 61 // This is a generalization of the data we store in the history menu because |
60 // we pull things from different sources with different data types. | 62 // we pull things from different sources with different data types. |
61 struct HistoryItem { | 63 struct HistoryItem { |
62 public: | 64 public: |
63 HistoryItem() | 65 HistoryItem(); |
64 : icon_requested(false), | |
65 menu_item(nil), | |
66 session_id(0) {} | |
67 | |
68 // Copy constructor allowed. | 66 // Copy constructor allowed. |
69 HistoryItem(const HistoryItem& copy) | 67 HistoryItem(const HistoryItem& copy); |
70 : title(copy.title), | 68 ~HistoryItem(); |
71 url(copy.url), | |
72 icon_requested(false), | |
73 menu_item(nil), | |
74 session_id(copy.session_id) {} | |
75 | |
76 ~HistoryItem() {} | |
77 | 69 |
78 // The title for the menu item. | 70 // The title for the menu item. |
79 string16 title; | 71 string16 title; |
80 // The URL that will be navigated to if the user selects this item. | 72 // The URL that will be navigated to if the user selects this item. |
81 GURL url; | 73 GURL url; |
82 // Favicon for the URL. | 74 // Favicon for the URL. |
83 scoped_nsobject<NSImage> icon; | 75 scoped_nsobject<NSImage> icon; |
84 | 76 |
85 // If the icon is being requested from the FaviconService, |icon_requested| | 77 // If the icon is being requested from the FaviconService, |icon_requested| |
86 // will be true and |icon_handle| will be non-NULL. If this is false, then | 78 // will be true and |icon_handle| will be non-NULL. If this is false, then |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 }; | 121 }; |
130 | 122 |
131 explicit HistoryMenuBridge(Profile* profile); | 123 explicit HistoryMenuBridge(Profile* profile); |
132 virtual ~HistoryMenuBridge(); | 124 virtual ~HistoryMenuBridge(); |
133 | 125 |
134 // Overriden from NotificationObserver. | 126 // Overriden from NotificationObserver. |
135 virtual void Observe(NotificationType type, | 127 virtual void Observe(NotificationType type, |
136 const NotificationSource& source, | 128 const NotificationSource& source, |
137 const NotificationDetails& details); | 129 const NotificationDetails& details); |
138 | 130 |
139 // For TabRestoreService::Observer | 131 // For TabRestoreServiceObserver |
140 virtual void TabRestoreServiceChanged(TabRestoreService* service); | 132 virtual void TabRestoreServiceChanged(TabRestoreService* service); |
141 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); | 133 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); |
142 | 134 |
143 // Looks up an NSMenuItem in the |menu_item_map_| and returns the | 135 // Looks up an NSMenuItem in the |menu_item_map_| and returns the |
144 // corresponding HistoryItem. | 136 // corresponding HistoryItem. |
145 HistoryItem* HistoryItemForMenuItem(NSMenuItem* item); | 137 HistoryItem* HistoryItemForMenuItem(NSMenuItem* item); |
146 | 138 |
147 // I wish I has a "friend @class" construct. These are used by the HMCC | 139 // I wish I has a "friend @class" construct. These are used by the HMCC |
148 // to access model information when responding to actions. | 140 // to access model information when responding to actions. |
149 HistoryService* service(); | 141 HistoryService* service(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 bool create_in_progress_; | 223 bool create_in_progress_; |
232 bool need_recreate_; | 224 bool need_recreate_; |
233 | 225 |
234 // The default favicon if a HistoryItem does not have one. | 226 // The default favicon if a HistoryItem does not have one. |
235 scoped_nsobject<NSImage> default_favicon_; | 227 scoped_nsobject<NSImage> default_favicon_; |
236 | 228 |
237 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); | 229 DISALLOW_COPY_AND_ASSIGN(HistoryMenuBridge); |
238 }; | 230 }; |
239 | 231 |
240 #endif // CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ | 232 #endif // CHROME_BROWSER_COCOA_HISTORY_MENU_BRIDGE_H_ |
OLD | NEW |