| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_GTK_GLOBAL_HISTORY_MENU_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_GLOBAL_HISTORY_MENU_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "content/browser/cancelable_request.h" |
| 11 #include "chrome/browser/favicon_service.h" |
| 12 #include "chrome/browser/sessions/tab_restore_service.h" |
| 13 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 14 #include "content/common/notification_observer.h" |
| 15 #include "content/common/notification_registrar.h" |
| 16 #include "ui/base/gtk/gtk_signal.h" |
| 17 |
| 18 class Browser; |
| 19 class HistoryService; |
| 20 class PageUsageData; |
| 21 typedef struct _GdkPixbuf GdkPixbuf; |
| 22 |
| 23 // Controls the History menu. |
| 24 class GlobalHistoryMenu : public NotificationObserver, |
| 25 public TabRestoreServiceObserver { |
| 26 public: |
| 27 explicit GlobalHistoryMenu(Browser* browser); |
| 28 virtual ~GlobalHistoryMenu(); |
| 29 |
| 30 // Takes the history menu we need to modify based on the tab restore/most |
| 31 // visited state. |
| 32 void Init(GtkWidget* history_menu); |
| 33 |
| 34 private: |
| 35 class HistoryItem; |
| 36 struct ClearMenuClosure; |
| 37 struct GetIndexClosure; |
| 38 |
| 39 typedef std::map<GtkWidget*, HistoryItem*> MenuItemToHistoryMap; |
| 40 |
| 41 // Called to start observing history related events. |
| 42 void InitHistoryService(); |
| 43 |
| 44 // Called to (re)create the most visited section. |
| 45 void CreateMostVisited(); |
| 46 |
| 47 // Callback from CreateMostVisited(). |
| 48 void OnVisitedHistoryResults(CancelableRequestProvider::Handle handle, |
| 49 std::vector<PageUsageData*>* results); |
| 50 |
| 51 // Returns the currently existing HistoryItem associated with |
| 52 // |menu_item|. Can return NULL. |
| 53 HistoryItem* HistoryItemForMenuItem(GtkWidget* menu_item); |
| 54 |
| 55 // Returns whether there's a valid HistoryItem representation of |entry|. |
| 56 bool HasValidHistoryItemForTab(const TabRestoreService::Tab& entry); |
| 57 |
| 58 // Creates a HistoryItem from the data in |entry|. |
| 59 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); |
| 60 |
| 61 // Creates a menu item form |item| and inserts it in |menu| at |index|. |
| 62 GtkWidget* AddHistoryItemToMenu(HistoryItem* item, |
| 63 GtkWidget* menu, |
| 64 int tag, |
| 65 int index); |
| 66 |
| 67 // Requests a FavIcon; we'll receive the data in the future through the |
| 68 // GotFaviconData() callback. |
| 69 void GetFaviconForHistoryItem(HistoryItem* item); |
| 70 |
| 71 // Callback for GetFaviconForHistoryItem(). |
| 72 void GotFaviconData(FaviconService::Handle handle, |
| 73 history::FaviconData favicon); |
| 74 |
| 75 // Cancels an outstanding favicon request. |
| 76 void CancelFaviconRequest(HistoryItem* item); |
| 77 |
| 78 // Find the first index of the item in |menu| with the tag |tag_id|. |
| 79 int GetIndexOfMenuItemWithTag(GtkWidget* menu, int tag_id); |
| 80 |
| 81 // This will remove all menu items in |menu| with |tag| as their tag. This |
| 82 // clears state about HistoryItems* that we keep to prevent that data from |
| 83 // going stale. That's why this method recurses into its child menus. |
| 84 void ClearMenuSection(GtkWidget* menu, int tag); |
| 85 |
| 86 // Implementation detail of GetIndexOfMenuItemWithTag. |
| 87 static void GetIndexCallback(GtkWidget* widget, GetIndexClosure* closure); |
| 88 |
| 89 // Implementation detail of ClearMenuSection. |
| 90 static void ClearMenuCallback(GtkWidget* widget, ClearMenuClosure* closure); |
| 91 |
| 92 // NotificationObserver: |
| 93 virtual void Observe(NotificationType type, |
| 94 const NotificationSource& source, |
| 95 const NotificationDetails& details); |
| 96 |
| 97 // For TabRestoreServiceObserver |
| 98 virtual void TabRestoreServiceChanged(TabRestoreService* service); |
| 99 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); |
| 100 |
| 101 CHROMEGTK_CALLBACK_0(GlobalHistoryMenu, void, OnRecentlyClosedItemActivated); |
| 102 |
| 103 Browser* browser_; |
| 104 Profile* profile_; |
| 105 |
| 106 NotificationRegistrar registrar_; |
| 107 CancelableRequestConsumer cancelable_request_consumer_; |
| 108 |
| 109 GdkPixbuf* default_favicon_; |
| 110 |
| 111 // The history menu. We keep this since we need to rewrite parts of it |
| 112 // periodically. |
| 113 GtkWidget* history_menu_; |
| 114 |
| 115 TabRestoreService* tab_restore_service_; // weak |
| 116 |
| 117 // A mapping from GtkMenuItems to HistoryItems that maintain data. |
| 118 MenuItemToHistoryMap menu_item_history_map_; |
| 119 |
| 120 // Maps HistoryItems to favicon request Handles. |
| 121 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; |
| 122 |
| 123 HistoryService* history_service_; // weak |
| 124 |
| 125 // Requests to re-create the "Most Visited" section of the menu are |
| 126 // coalesced. |create_in_progress_| is true when either waiting for the |
| 127 // history service to return query results, or when the menu is |
| 128 // rebuilding. |need_recreate_| is true whenever a rebuild has been scheduled |
| 129 // but is waiting for the current one to finish. |
| 130 bool create_in_progress_; |
| 131 bool need_recreate_; |
| 132 }; |
| 133 |
| 134 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_HISTORY_MENU_H_ |
| OLD | NEW |