| OLD | NEW |
| 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 "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 #endif | 196 #endif |
| 197 | 197 |
| 198 // The overflow displays any icons not shown by the main bar. | 198 // The overflow displays any icons not shown by the main bar. |
| 199 return in_overflow_mode_ ? | 199 return in_overflow_mode_ ? |
| 200 model_->toolbar_items().size() - model_visible_size : model_visible_size; | 200 model_->toolbar_items().size() - model_visible_size : model_visible_size; |
| 201 } | 201 } |
| 202 | 202 |
| 203 void ToolbarActionsBar::CreateActions() { | 203 void ToolbarActionsBar::CreateActions() { |
| 204 DCHECK(toolbar_actions_.empty()); | 204 DCHECK(toolbar_actions_.empty()); |
| 205 if (!model_) | 205 // We wait for the extension system to be initialized before we add any |
| 206 // actions, as they rely on the extension system to function. |
| 207 if (!model_ || !model_->extensions_initialized()) |
| 206 return; | 208 return; |
| 207 | 209 |
| 208 { | 210 { |
| 209 // We don't redraw the view while creating actions. | 211 // We don't redraw the view while creating actions. |
| 210 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 212 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 211 | 213 |
| 212 // Extension actions come first. | 214 // Extension actions come first. |
| 213 extensions::ExtensionActionManager* action_manager = | 215 extensions::ExtensionActionManager* action_manager = |
| 214 extensions::ExtensionActionManager::Get(browser_->profile()); | 216 extensions::ExtensionActionManager::Get(browser_->profile()); |
| 215 const extensions::ExtensionList& toolbar_items = model_->GetItemOrderForTab( | 217 const extensions::ExtensionList& toolbar_items = model_->GetItemOrderForTab( |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 // appearing, etc), it's not worth the extra complexity to create and insert | 424 // appearing, etc), it's not worth the extra complexity to create and insert |
| 423 // only the new actions. | 425 // only the new actions. |
| 424 DeleteActions(); | 426 DeleteActions(); |
| 425 CreateActions(); | 427 CreateActions(); |
| 426 delegate_->ResizeAndAnimate(gfx::Tween::LINEAR, | 428 delegate_->ResizeAndAnimate(gfx::Tween::LINEAR, |
| 427 GetPreferredSize().width(), | 429 GetPreferredSize().width(), |
| 428 true); // suppress chevron | 430 true); // suppress chevron |
| 429 } | 431 } |
| 430 | 432 |
| 431 void ToolbarActionsBar::OnToolbarModelInitialized() { | 433 void ToolbarActionsBar::OnToolbarModelInitialized() { |
| 432 ToolbarVisibleCountChanged(); // We may not have resized since the start. | 434 // We shouldn't have any actions before the model is initialized. |
| 433 delegate_->Redraw(false); // Order didn't change. | 435 DCHECK(toolbar_actions_.empty()); |
| 434 suppress_animation_ = false; | 436 suppress_animation_ = false; |
| 437 CreateActions(); |
| 438 if (!toolbar_actions_.empty()) { |
| 439 delegate_->Redraw(false); |
| 440 ToolbarVisibleCountChanged(); |
| 441 } |
| 435 } | 442 } |
| 436 | 443 |
| 437 void ToolbarActionsBar::OnToolbarReorderNecessary( | 444 void ToolbarActionsBar::OnToolbarReorderNecessary( |
| 438 content::WebContents* web_contents) { | 445 content::WebContents* web_contents) { |
| 439 if (GetCurrentWebContents() == web_contents) | 446 if (GetCurrentWebContents() == web_contents) |
| 440 ReorderActions(); | 447 ReorderActions(); |
| 441 } | 448 } |
| 442 | 449 |
| 443 Browser* ToolbarActionsBar::GetBrowser() { | 450 Browser* ToolbarActionsBar::GetBrowser() { |
| 444 return browser_; | 451 return browser_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 for (ToolbarActionViewController* action : toolbar_actions_) { | 493 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 487 if (action->GetId() == id) | 494 if (action->GetId() == id) |
| 488 return action; | 495 return action; |
| 489 } | 496 } |
| 490 return nullptr; | 497 return nullptr; |
| 491 } | 498 } |
| 492 | 499 |
| 493 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 500 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 494 return browser_->tab_strip_model()->GetActiveWebContents(); | 501 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 495 } | 502 } |
| OLD | NEW |