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