app_shell: Add version number in user agent
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / wrench_menu_model.h
blob965baf89a1026a94460dc69cdc9e7b635e036952
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "ui/base/accelerators/accelerator.h"
15 #include "ui/base/models/button_menu_item_model.h"
16 #include "ui/base/models/simple_menu_model.h"
18 class BookmarkSubMenuModel;
19 class Browser;
20 class RecentTabsSubMenuModel;
21 class TabStripModel;
23 namespace {
24 class MockWrenchMenuModel;
25 } // namespace
27 // A menu model that builds the contents of an encoding menu.
28 class EncodingMenuModel : public ui::SimpleMenuModel,
29 public ui::SimpleMenuModel::Delegate {
30 public:
31 explicit EncodingMenuModel(Browser* browser);
32 virtual ~EncodingMenuModel();
34 // Overridden from ui::SimpleMenuModel::Delegate:
35 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
36 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
37 virtual bool GetAcceleratorForCommandId(
38 int command_id,
39 ui::Accelerator* accelerator) OVERRIDE;
40 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
42 private:
43 void Build();
45 Browser* browser_; // weak
47 DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel);
50 // A menu model that builds the contents of the zoom menu.
51 class ZoomMenuModel : public ui::SimpleMenuModel {
52 public:
53 explicit ZoomMenuModel(ui::SimpleMenuModel::Delegate* delegate);
54 virtual ~ZoomMenuModel();
56 private:
57 void Build();
59 DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel);
62 class ToolsMenuModel : public ui::SimpleMenuModel {
63 public:
64 ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser);
65 virtual ~ToolsMenuModel();
67 private:
68 void Build(Browser* browser);
70 scoped_ptr<EncodingMenuModel> encoding_menu_model_;
72 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel);
75 // A menu model that builds the contents of the wrench menu.
76 class WrenchMenuModel : public ui::SimpleMenuModel,
77 public ui::SimpleMenuModel::Delegate,
78 public ui::ButtonMenuItemModel::Delegate,
79 public TabStripModelObserver,
80 public content::NotificationObserver {
81 public:
82 // Range of command ID's to use for the items representing bookmarks in the
83 // bookmark menu, must not overlap with that for recent tabs submenu.
84 static const int kMinBookmarkCommandId = 1;
85 static const int kMaxBookmarkCommandId = 1000;
87 // Range of command ID's to use for the items in the recent tabs submenu, must
88 // not overlap with that for bookmarks.
89 static const int kMinRecentTabsCommandId = 1001;
90 static const int kMaxRecentTabsCommandId = 1200;
92 WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser);
93 virtual ~WrenchMenuModel();
95 // Overridden for ButtonMenuItemModel::Delegate:
96 virtual bool DoesCommandIdDismissMenu(int command_id) const OVERRIDE;
98 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel:
99 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
100 virtual base::string16 GetLabelForCommandId(int command_id) const OVERRIDE;
101 virtual bool GetIconForCommandId(int command_id,
102 gfx::Image* icon) const OVERRIDE;
103 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
104 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
105 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
106 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE;
107 virtual bool GetAcceleratorForCommandId(
108 int command_id,
109 ui::Accelerator* accelerator) OVERRIDE;
111 // Overridden from TabStripModelObserver:
112 virtual void ActiveTabChanged(content::WebContents* old_contents,
113 content::WebContents* new_contents,
114 int index,
115 int reason) OVERRIDE;
116 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
117 content::WebContents* old_contents,
118 content::WebContents* new_contents,
119 int index) OVERRIDE;
120 virtual void TabStripModelDeleted() OVERRIDE;
122 // Overridden from content::NotificationObserver:
123 virtual void Observe(int type,
124 const content::NotificationSource& source,
125 const content::NotificationDetails& details) OVERRIDE;
127 // Getters.
128 Browser* browser() const { return browser_; }
130 BookmarkSubMenuModel* bookmark_sub_menu_model() const {
131 return bookmark_sub_menu_model_.get();
134 // Calculates |zoom_label_| in response to a zoom change.
135 void UpdateZoomControls();
137 private:
138 class HelpMenuModel;
139 // Testing constructor used for mocking.
140 friend class ::MockWrenchMenuModel;
142 WrenchMenuModel();
144 void Build();
146 void AddGlobalErrorMenuItems();
148 // Appends everything needed for the clipboard menu: a menu break, the
149 // clipboard menu content and the finalizing menu break.
150 void CreateCutCopyPasteMenu();
152 // Add a menu item for the extension icons.
153 void CreateExtensionToolbarOverflowMenu();
155 // Appends everything needed for the zoom menu: a menu break, then the zoom
156 // menu content and then another menu break.
157 void CreateZoomMenu();
159 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
161 bool ShouldShowNewIncognitoWindowMenuItem();
163 // Models for the special menu items with buttons.
164 scoped_ptr<ui::ButtonMenuItemModel> edit_menu_item_model_;
165 scoped_ptr<ui::ButtonMenuItemModel> zoom_menu_item_model_;
167 // Label of the zoom label in the zoom menu item.
168 base::string16 zoom_label_;
170 #if defined(GOOGLE_CHROME_BUILD)
171 // Help menu.
172 scoped_ptr<HelpMenuModel> help_menu_model_;
173 #endif
175 // Tools menu.
176 scoped_ptr<ToolsMenuModel> tools_menu_model_;
178 // Bookmark submenu.
179 scoped_ptr<BookmarkSubMenuModel> bookmark_sub_menu_model_;
181 // Recent Tabs submenu.
182 scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_;
184 ui::AcceleratorProvider* provider_; // weak
186 Browser* browser_; // weak
187 TabStripModel* tab_strip_model_; // weak
189 scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_;
190 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_;
191 content::NotificationRegistrar registrar_;
193 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel);
196 #endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_