Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model.h

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final nits Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 10 matching lines...) Expand all
21 class PrefService; 21 class PrefService;
22 class Profile; 22 class Profile;
23 class ToolbarActionsBar; 23 class ToolbarActionsBar;
24 class ToolbarActionViewController; 24 class ToolbarActionViewController;
25 25
26 namespace extensions { 26 namespace extensions {
27 class ExtensionRegistry; 27 class ExtensionRegistry;
28 class ExtensionSet; 28 class ExtensionSet;
29 } 29 }
30 30
31 // Model for the browser actions toolbar. 31 // Model for the browser actions toolbar. This is a per-profile instance, and
32 // manages the user's global preferences.
33 // Each browser window will attempt to show browser actions as specified by this
34 // model, but if the window is too narrow, actions may end up pushed into the
35 // overflow menu on a per-window basis. Callers interested in the arrangement of
36 // actions in a particular window should check that window's instance of
37 // ToolbarActionsBar, which is responsible for the per-window layout.
32 class ToolbarActionsModel : public extensions::ExtensionActionAPI::Observer, 38 class ToolbarActionsModel : public extensions::ExtensionActionAPI::Observer,
33 public extensions::ExtensionRegistryObserver, 39 public extensions::ExtensionRegistryObserver,
34 public KeyedService { 40 public KeyedService {
35 public: 41 public:
36 // The different options for highlighting. 42 // The different options for highlighting.
37 enum HighlightType { 43 enum HighlightType {
38 HIGHLIGHT_NONE, 44 HIGHLIGHT_NONE,
39 HIGHLIGHT_INFO, 45 HIGHLIGHT_INFO,
40 HIGHLIGHT_WARNING, 46 HIGHLIGHT_WARNING,
41 }; 47 };
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void RemoveObserver(Observer* observer); 122 void RemoveObserver(Observer* observer);
117 123
118 // Moves the given action with |id|'s icon to the given |index|. 124 // Moves the given action with |id|'s icon to the given |index|.
119 void MoveActionIcon(const std::string& id, size_t index); 125 void MoveActionIcon(const std::string& id, size_t index);
120 126
121 // Sets the number of action icons that should be visible. 127 // Sets the number of action icons that should be visible.
122 // If count == size(), this will set the visible icon count to -1, meaning 128 // If count == size(), this will set the visible icon count to -1, meaning
123 // "show all actions". 129 // "show all actions".
124 void SetVisibleIconCount(size_t count); 130 void SetVisibleIconCount(size_t count);
125 131
132 // Note that this (and all_icons_visible()) are the global default, but are
133 // inappropriate for determining a specific window's state - for that, use
134 // the ToolbarActionsBar.
126 size_t visible_icon_count() const { 135 size_t visible_icon_count() const {
127 // We have guards around this because |visible_icon_count_| can be set by 136 // We have guards around this because |visible_icon_count_| can be set by
128 // prefs/sync, and we want to ensure that the icon count returned is within 137 // prefs/sync, and we want to ensure that the icon count returned is within
129 // bounds. 138 // bounds.
130 return visible_icon_count_ == -1 139 return visible_icon_count_ == -1
131 ? toolbar_items().size() 140 ? toolbar_items().size()
132 : std::min(static_cast<size_t>(visible_icon_count_), 141 : std::min(static_cast<size_t>(visible_icon_count_),
133 toolbar_items().size()); 142 toolbar_items().size());
134 } 143 }
135
136 bool all_icons_visible() const { 144 bool all_icons_visible() const {
137 return visible_icon_count() == toolbar_items().size(); 145 return visible_icon_count() == toolbar_items().size();
138 } 146 }
139 147
140 bool actions_initialized() const { return actions_initialized_; } 148 bool actions_initialized() const { return actions_initialized_; }
141 149
142 ScopedVector<ToolbarActionViewController> CreateActions( 150 ScopedVector<ToolbarActionViewController> CreateActions(
143 Browser* browser, 151 Browser* browser,
144 ToolbarActionsBar* bar); 152 ToolbarActionsBar* bar);
145 153
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // For observing change of toolbar order preference by external entity (sync). 287 // For observing change of toolbar order preference by external entity (sync).
280 PrefChangeRegistrar pref_change_registrar_; 288 PrefChangeRegistrar pref_change_registrar_;
281 base::Closure pref_change_callback_; 289 base::Closure pref_change_callback_;
282 290
283 base::WeakPtrFactory<ToolbarActionsModel> weak_ptr_factory_; 291 base::WeakPtrFactory<ToolbarActionsModel> weak_ptr_factory_;
284 292
285 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsModel); 293 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsModel);
286 }; 294 };
287 295
288 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ 296 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc ('k') | chrome/browser/ui/toolbar/wrench_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698