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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.cc

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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/profiler/scoped_tracker.h" 9 #include "base/profiler/scoped_tracker.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 available_space -= delegate_->GetChevronWidth(); 220 available_space -= delegate_->GetChevronWidth();
221 221
222 // Now we add an extra between-item padding value so the space can be divided 222 // Now we add an extra between-item padding value so the space can be divided
223 // evenly by (size of icon with padding). 223 // evenly by (size of icon with padding).
224 return static_cast<size_t>(std::max( 224 return static_cast<size_t>(std::max(
225 0, available_space + platform_settings_.item_spacing) / IconWidth(true)); 225 0, available_space + platform_settings_.item_spacing) / IconWidth(true));
226 } 226 }
227 227
228 size_t ToolbarActionsBar::GetIconCount() const { 228 size_t ToolbarActionsBar::GetIconCount() const {
229 if (!model_) 229 if (!model_)
230 return 0u; 230 return 0;
231 231
232 int pop_out_modifier = 0; 232 int pop_out_modifier = 0;
233 // If there is a popped out action, it could affect the number of visible 233 // If there is a popped out action, it could affect the number of visible
234 // icons - but only if it wouldn't otherwise be visible. 234 // icons - but only if it wouldn't otherwise be visible.
235 if (popped_out_action_) { 235 if (popped_out_action_) {
236 size_t popped_out_index = 236 size_t popped_out_index =
237 std::find(toolbar_actions_.begin(), 237 std::find(toolbar_actions_.begin(),
238 toolbar_actions_.end(), 238 toolbar_actions_.end(),
239 popped_out_action_) - toolbar_actions_.begin(); 239 popped_out_action_) - toolbar_actions_.begin();
240 pop_out_modifier = popped_out_index >= model_->visible_icon_count() ? 1 : 0; 240 pop_out_modifier = popped_out_index >= model_->visible_icon_count() ? 1 : 0;
(...skipping 16 matching lines...) Expand all
257 if (!toolbar_actions_.empty() && !suppress_layout_ && 257 if (!toolbar_actions_.empty() && !suppress_layout_ &&
258 model_->actions_initialized()) { 258 model_->actions_initialized()) {
259 DCHECK_LE(visible_icons, toolbar_actions_.size()); 259 DCHECK_LE(visible_icons, toolbar_actions_.size());
260 DCHECK_EQ(model_->toolbar_items().size(), toolbar_actions_.size()); 260 DCHECK_EQ(model_->toolbar_items().size(), toolbar_actions_.size());
261 } 261 }
262 #endif 262 #endif
263 263
264 return visible_icons; 264 return visible_icons;
265 } 265 }
266 266
267 gfx::Rect ToolbarActionsBar::GetFrameForIndex(size_t index) const { 267 size_t ToolbarActionsBar::GetStartIndexInBounds() const {
268 size_t start_index = in_overflow_mode() ? 268 return in_overflow_mode() ? main_bar_->GetEndIndexInBounds() : 0;
269 toolbar_actions_.size() - GetIconCount() : 0u; 269 }
270
271 size_t ToolbarActionsBar::GetEndIndexInBounds() const {
272 return in_overflow_mode() ?
273 toolbar_actions_.size() : WidthToIconCount(delegate_->GetWidth());
274 }
275
276 bool ToolbarActionsBar::NeedsOverflow() const {
277 DCHECK(!in_overflow_mode());
278 return GetEndIndexInBounds() != toolbar_actions_.size();
279 }
280
281 gfx::Rect ToolbarActionsBar::GetFrameForIndex(
282 size_t index) const {
283 size_t start_index = GetStartIndexInBounds();
270 284
271 // If the index is for an action that is before range we show (i.e., is for 285 // If the index is for an action that is before range we show (i.e., is for
272 // a button that's on the main bar, and this is the overflow), send back an 286 // a button that's on the main bar, and this is the overflow), send back an
273 // empty rect. 287 // empty rect.
274 if (index < start_index) 288 if (index < start_index)
275 return gfx::Rect(); 289 return gfx::Rect();
276 290
277 size_t relative_index = index - start_index; 291 size_t relative_index = index - start_index;
278 int icons_per_overflow_row = platform_settings().icons_per_overflow_menu_row; 292 int icons_per_overflow_row = platform_settings().icons_per_overflow_menu_row;
279 size_t row_index = in_overflow_mode() ? 293 size_t row_index = in_overflow_mode() ?
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 for (ToolbarActionViewController* action : toolbar_actions_) { 721 for (ToolbarActionViewController* action : toolbar_actions_) {
708 if (action->GetId() == action_id) 722 if (action->GetId() == action_id)
709 return action; 723 return action;
710 } 724 }
711 return nullptr; 725 return nullptr;
712 } 726 }
713 727
714 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 728 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
715 return browser_->tab_strip_model()->GetActiveWebContents(); 729 return browser_->tab_strip_model()->GetActiveWebContents();
716 } 730 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_bar.h ('k') | chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698