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; we also have | |
207 // to wait for the delegate to be ready to create any added views. | |
208 if (!model_ || !model_->extensions_initialized() || !delegate_->IsReady()) | |
Peter Kasting
2014/11/14 21:31:58
Hmm. Is there code somewhere that triggers anothe
Devlin
2014/11/14 22:00:37
Yep - the delegate (the view for the browser actio
| |
206 return; | 209 return; |
207 | 210 |
208 { | 211 { |
209 // We don't redraw the view while creating actions. | 212 // We don't redraw the view while creating actions. |
210 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 213 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
211 | 214 |
212 // Extension actions come first. | 215 // Extension actions come first. |
213 extensions::ExtensionActionManager* action_manager = | 216 extensions::ExtensionActionManager* action_manager = |
214 extensions::ExtensionActionManager::Get(browser_->profile()); | 217 extensions::ExtensionActionManager::Get(browser_->profile()); |
215 const extensions::ExtensionList& toolbar_items = model_->GetItemOrderForTab( | 218 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 | 425 // appearing, etc), it's not worth the extra complexity to create and insert |
423 // only the new actions. | 426 // only the new actions. |
424 DeleteActions(); | 427 DeleteActions(); |
425 CreateActions(); | 428 CreateActions(); |
426 delegate_->ResizeAndAnimate(gfx::Tween::LINEAR, | 429 delegate_->ResizeAndAnimate(gfx::Tween::LINEAR, |
427 GetPreferredSize().width(), | 430 GetPreferredSize().width(), |
428 true); // suppress chevron | 431 true); // suppress chevron |
429 } | 432 } |
430 | 433 |
431 void ToolbarActionsBar::OnToolbarModelInitialized() { | 434 void ToolbarActionsBar::OnToolbarModelInitialized() { |
432 ToolbarVisibleCountChanged(); // We may not have resized since the start. | 435 // We shouldn't have any actions before the model is initialized. |
433 delegate_->Redraw(false); // Order didn't change. | 436 DCHECK(toolbar_actions_.empty()); |
434 suppress_animation_ = false; | 437 suppress_animation_ = false; |
438 CreateActions(); | |
439 if (!toolbar_actions_.empty()) { | |
440 delegate_->Redraw(false); | |
441 ToolbarVisibleCountChanged(); | |
442 } | |
435 } | 443 } |
436 | 444 |
437 void ToolbarActionsBar::OnToolbarReorderNecessary( | 445 void ToolbarActionsBar::OnToolbarReorderNecessary( |
438 content::WebContents* web_contents) { | 446 content::WebContents* web_contents) { |
439 if (GetCurrentWebContents() == web_contents) | 447 if (GetCurrentWebContents() == web_contents) |
440 ReorderActions(); | 448 ReorderActions(); |
441 } | 449 } |
442 | 450 |
443 Browser* ToolbarActionsBar::GetBrowser() { | 451 Browser* ToolbarActionsBar::GetBrowser() { |
444 return browser_; | 452 return browser_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 for (ToolbarActionViewController* action : toolbar_actions_) { | 494 for (ToolbarActionViewController* action : toolbar_actions_) { |
487 if (action->GetId() == id) | 495 if (action->GetId() == id) |
488 return action; | 496 return action; |
489 } | 497 } |
490 return nullptr; | 498 return nullptr; |
491 } | 499 } |
492 | 500 |
493 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 501 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
494 return browser_->tab_strip_model()->GetActiveWebContents(); | 502 return browser_->tab_strip_model()->GetActiveWebContents(); |
495 } | 503 } |
OLD | NEW |