OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/command_observer.h" | 14 #include "chrome/browser/command_observer.h" |
| 15 #include "chrome/browser/profiles/avatar_menu.h" |
| 16 #include "chrome/browser/profiles/avatar_menu_observer.h" |
15 #include "chrome/browser/sessions/tab_restore_service.h" | 17 #include "chrome/browser/sessions/tab_restore_service.h" |
16 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 18 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 19 #include "chrome/browser/ui/browser_list_observer.h" |
17 #include "components/history/core/browser/history_types.h" | 20 #include "components/history/core/browser/history_types.h" |
18 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/base/glib/glib_signal.h" | 23 #include "ui/base/glib/glib_signal.h" |
21 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" | 24 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" |
22 | 25 |
23 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; | 26 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; |
24 typedef struct _DbusmenuServer DbusmenuServer; | 27 typedef struct _DbusmenuServer DbusmenuServer; |
25 | 28 |
26 namespace history { | 29 namespace history { |
(...skipping 12 matching lines...) Expand all Loading... |
39 struct GlobalMenuBarCommand; | 42 struct GlobalMenuBarCommand; |
40 | 43 |
41 // Controls the Mac style menu bar on Unity. | 44 // Controls the Mac style menu bar on Unity. |
42 // | 45 // |
43 // Unity has an Apple-like menu bar at the top of the screen that changes | 46 // Unity has an Apple-like menu bar at the top of the screen that changes |
44 // depending on the active window. In the GTK port, we had a hidden GtkMenuBar | 47 // depending on the active window. In the GTK port, we had a hidden GtkMenuBar |
45 // object in each GtkWindow which existed only to be scrapped by the | 48 // object in each GtkWindow which existed only to be scrapped by the |
46 // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to | 49 // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to |
47 // interface directly with the lower level libdbusmenu-glib, which we | 50 // interface directly with the lower level libdbusmenu-glib, which we |
48 // opportunistically dlopen() since not everyone is running Ubuntu. | 51 // opportunistically dlopen() since not everyone is running Ubuntu. |
49 class GlobalMenuBarX11 : public CommandObserver, | 52 class GlobalMenuBarX11 : public AvatarMenuObserver, |
| 53 public chrome::BrowserListObserver, |
| 54 public CommandObserver, |
50 public content::NotificationObserver, | 55 public content::NotificationObserver, |
51 public TabRestoreServiceObserver, | 56 public TabRestoreServiceObserver, |
52 public views::DesktopWindowTreeHostObserverX11 { | 57 public views::DesktopWindowTreeHostObserverX11 { |
53 public: | 58 public: |
54 GlobalMenuBarX11(BrowserView* browser_view, | 59 GlobalMenuBarX11(BrowserView* browser_view, |
55 BrowserDesktopWindowTreeHostX11* host); | 60 BrowserDesktopWindowTreeHostX11* host); |
56 virtual ~GlobalMenuBarX11(); | 61 virtual ~GlobalMenuBarX11(); |
57 | 62 |
58 // Creates the object path for DbusemenuServer which is attached to |xid|. | 63 // Creates the object path for DbusemenuServer which is attached to |xid|. |
59 static std::string GetPathForWindow(unsigned long xid); | 64 static std::string GetPathForWindow(unsigned long xid); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 101 |
97 // Sends a message off to History for data. | 102 // Sends a message off to History for data. |
98 void GetTopSitesData(); | 103 void GetTopSitesData(); |
99 | 104 |
100 // Callback to receive data requested from GetTopSitesData(). | 105 // Callback to receive data requested from GetTopSitesData(). |
101 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); | 106 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); |
102 | 107 |
103 // Updates the visibility of the bookmark bar on pref changes. | 108 // Updates the visibility of the bookmark bar on pref changes. |
104 void OnBookmarkBarVisibilityChanged(); | 109 void OnBookmarkBarVisibilityChanged(); |
105 | 110 |
| 111 void RebuildProfilesMenu(); |
| 112 |
106 // Find the first index of the item in |menu| with the tag |tag_id|. | 113 // Find the first index of the item in |menu| with the tag |tag_id|. |
107 int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id); | 114 int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id); |
108 | 115 |
109 // This will remove all menu items in |menu| with |tag| as their tag. This | 116 // This will remove all menu items in |menu| with |tag| as their tag. This |
110 // clears state about HistoryItems* that we keep to prevent that data from | 117 // clears state about HistoryItems* that we keep to prevent that data from |
111 // going stale. That's why this method recurses into its child menus. | 118 // going stale. That's why this method recurses into its child menus. |
112 void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id); | 119 void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id); |
113 | 120 |
114 // Deleter function for HistoryItem implementation detail. | 121 // Deleter function for HistoryItem implementation detail. |
115 static void DeleteHistoryItem(void* void_item); | 122 static void DeleteHistoryItem(void* void_item); |
116 | 123 |
| 124 // Overridden from AvatarMenuObserver: |
| 125 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE; |
| 126 |
| 127 // Overridden from chrome::BrowserListObserver: |
| 128 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; |
| 129 |
117 // Overridden from CommandObserver: | 130 // Overridden from CommandObserver: |
118 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; | 131 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; |
119 | 132 |
120 // Overridden from content::NotificationObserver: | 133 // Overridden from content::NotificationObserver: |
121 virtual void Observe(int type, | 134 virtual void Observe(int type, |
122 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
123 const content::NotificationDetails& details) OVERRIDE; | 136 const content::NotificationDetails& details) OVERRIDE; |
124 | 137 |
125 // Overridden from TabRestoreServiceObserver: | 138 // Overridden from TabRestoreServiceObserver: |
126 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; | 139 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; |
127 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; | 140 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; |
128 | 141 |
129 // Overridden from views::DesktopWindowTreeHostObserverX11: | 142 // Overridden from views::DesktopWindowTreeHostObserverX11: |
130 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; | 143 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; |
131 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; | 144 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; |
132 | 145 |
133 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, | 146 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, |
134 unsigned int); | 147 unsigned int); |
135 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated, | 148 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated, |
136 DbusmenuMenuitem*, unsigned int); | 149 DbusmenuMenuitem*, unsigned int); |
137 CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow, | 150 CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow, |
138 DbusmenuMenuitem*); | 151 DbusmenuMenuitem*); |
| 152 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnProfileItemActivated, |
| 153 DbusmenuMenuitem*, unsigned int); |
| 154 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnEditProfileItemActivated, |
| 155 DbusmenuMenuitem*, unsigned int); |
| 156 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnCreateProfileItemActivated, |
| 157 DbusmenuMenuitem*, unsigned int); |
139 | 158 |
140 Browser* browser_; | 159 Browser* browser_; |
141 Profile* profile_; | 160 Profile* profile_; |
142 BrowserView* browser_view_; | 161 BrowserView* browser_view_; |
143 BrowserDesktopWindowTreeHostX11* host_; | 162 BrowserDesktopWindowTreeHostX11* host_; |
144 | 163 |
145 // Maps command ids to DbusmenuMenuitems so we can modify their | 164 // Maps command ids to DbusmenuMenuitems so we can modify their |
146 // enabled/checked state in response to state change notifications. | 165 // enabled/checked state in response to state change notifications. |
147 CommandIDMenuItemMap id_to_menu_item_; | 166 CommandIDMenuItemMap id_to_menu_item_; |
148 | 167 |
149 DbusmenuServer* server_; | 168 DbusmenuServer* server_; |
150 DbusmenuMenuitem* root_item_; | 169 DbusmenuMenuitem* root_item_; |
151 DbusmenuMenuitem* history_menu_; | 170 DbusmenuMenuitem* history_menu_; |
| 171 DbusmenuMenuitem* profiles_menu_; |
152 | 172 |
153 // Tracks value of the kShowBookmarkBar preference. | 173 // Tracks value of the kShowBookmarkBar preference. |
154 PrefChangeRegistrar pref_change_registrar_; | 174 PrefChangeRegistrar pref_change_registrar_; |
155 | 175 |
156 history::TopSites* top_sites_; | 176 history::TopSites* top_sites_; |
157 | 177 |
158 TabRestoreService* tab_restore_service_; // weak | 178 TabRestoreService* tab_restore_service_; // weak |
159 | 179 |
| 180 scoped_ptr<AvatarMenu> avatar_menu_; |
| 181 |
160 content::NotificationRegistrar registrar_; | 182 content::NotificationRegistrar registrar_; |
161 | 183 |
162 // For callbacks may be run after destruction. | 184 // For callbacks may be run after destruction. |
163 base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_; | 185 base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_; |
164 | 186 |
165 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); | 187 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); |
166 }; | 188 }; |
167 | 189 |
168 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 190 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
OLD | NEW |