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 "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
10 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | |
10 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 16 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
17 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
18 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 20 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
21 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
22 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" |
23 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
24 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
25 #include "extensions/browser/runtime_data.h" | 27 #include "extensions/browser/runtime_data.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 Browser* browser, | 413 Browser* browser, |
412 ToolbarActionsBar* main_bar) | 414 ToolbarActionsBar* main_bar) |
413 : delegate_(delegate), | 415 : delegate_(delegate), |
414 browser_(browser), | 416 browser_(browser), |
415 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), | 417 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), |
416 main_bar_(main_bar), | 418 main_bar_(main_bar), |
417 platform_settings_(main_bar != nullptr), | 419 platform_settings_(main_bar != nullptr), |
418 model_observer_(this), | 420 model_observer_(this), |
419 suppress_layout_(false), | 421 suppress_layout_(false), |
420 suppress_animation_(true), | 422 suppress_animation_(true), |
421 overflowed_action_wants_to_run_(false) { | 423 overflowed_action_wants_to_run_(false), |
424 checked_extension_bubble_(false), | |
425 weak_ptr_factory_(this) { | |
422 if (model_) // |model_| can be null in unittests. | 426 if (model_) // |model_| can be null in unittests. |
423 model_observer_.Add(model_); | 427 model_observer_.Add(model_); |
424 | 428 |
425 if (pop_out_actions_to_run_) { | 429 if (pop_out_actions_to_run_) { |
426 if (in_overflow_mode()) | 430 if (in_overflow_mode()) |
427 main_bar_->tab_order_helper_->notify_overflow_bar(this, true); | 431 main_bar_->tab_order_helper_->notify_overflow_bar(this, true); |
428 else | 432 else |
429 tab_order_helper_.reset(new TabOrderHelper(this, browser_, model_)); | 433 tab_order_helper_.reset(new TabOrderHelper(this, browser_, model_)); |
430 } | 434 } |
431 } | 435 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 | 628 |
625 tracked_objects::ScopedTracker tracking_profile4( | 629 tracked_objects::ScopedTracker tracking_profile4( |
626 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4")); | 630 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4")); |
627 | 631 |
628 for (size_t i = 0; i < toolbar_actions_.size(); ++i) | 632 for (size_t i = 0; i < toolbar_actions_.size(); ++i) |
629 delegate_->AddViewForAction(toolbar_actions_[i], i); | 633 delegate_->AddViewForAction(toolbar_actions_[i], i); |
630 } | 634 } |
631 | 635 |
632 // Once the actions are created, we should animate the changes. | 636 // Once the actions are created, we should animate the changes. |
633 suppress_animation_ = false; | 637 suppress_animation_ = false; |
638 | |
639 // CreateActions() can be called multiple times, so we need to make sure we | |
640 // haven't already shown the bubble. | |
641 if (!checked_extension_bubble_) { | |
642 checked_extension_bubble_ = true; | |
643 // CreateActions() can be called as part of the browser window set up, which | |
Devlin
2015/04/14 16:37:37
This is what was actually causing the crash (funny
Finnur
2015/04/15 14:51:37
Woot.
| |
644 // we need to let finish before showing the actions. | |
645 base::MessageLoop::current()->PostTask( | |
646 FROM_HERE, | |
647 base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, | |
648 weak_ptr_factory_.GetWeakPtr())); | |
649 } | |
634 } | 650 } |
635 | 651 |
636 void ToolbarActionsBar::DeleteActions() { | 652 void ToolbarActionsBar::DeleteActions() { |
637 delegate_->RemoveAllViews(); | 653 delegate_->RemoveAllViews(); |
638 toolbar_actions_.clear(); | 654 toolbar_actions_.clear(); |
639 } | 655 } |
640 | 656 |
641 void ToolbarActionsBar::Update() { | 657 void ToolbarActionsBar::Update() { |
642 if (toolbar_actions_.empty()) | 658 if (toolbar_actions_.empty()) |
643 return; // Nothing to do. | 659 return; // Nothing to do. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 // We only show the bubble if there are any new icons present - otherwise, | 738 // We only show the bubble if there are any new icons present - otherwise, |
723 // the user won't see anything different, so we treat it as acknowledged. | 739 // the user won't see anything different, so we treat it as acknowledged. |
724 OnToolbarActionsBarBubbleClosed( | 740 OnToolbarActionsBarBubbleClosed( |
725 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); | 741 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); |
726 return false; | 742 return false; |
727 } | 743 } |
728 | 744 |
729 return true; | 745 return true; |
730 } | 746 } |
731 | 747 |
748 void ToolbarActionsBar::MaybeShowExtensionBubble() { | |
749 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = | |
750 ExtensionMessageBubbleFactory(browser_->profile()).GetController(); | |
751 if (controller) { | |
752 controller->HighlightExtensionsIfNecessary(); | |
753 delegate_->ShowExtensionMessageBubble(controller.Pass()); | |
754 } | |
755 } | |
756 | |
732 void ToolbarActionsBar::OnToolbarExtensionAdded( | 757 void ToolbarActionsBar::OnToolbarExtensionAdded( |
733 const extensions::Extension* extension, | 758 const extensions::Extension* extension, |
734 int index) { | 759 int index) { |
735 DCHECK(GetActionForId(extension->id()) == nullptr) << | 760 DCHECK(GetActionForId(extension->id()) == nullptr) << |
736 "Asked to add a toolbar action view for an extension that already exists"; | 761 "Asked to add a toolbar action view for an extension that already exists"; |
737 | 762 |
738 toolbar_actions_.insert( | 763 toolbar_actions_.insert( |
739 toolbar_actions_.begin() + index, | 764 toolbar_actions_.begin() + index, |
740 new ExtensionActionViewController( | 765 new ExtensionActionViewController( |
741 extension, | 766 extension, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 for (ToolbarActionViewController* action : toolbar_actions_) { | 1002 for (ToolbarActionViewController* action : toolbar_actions_) { |
978 if (action->GetId() == id) | 1003 if (action->GetId() == id) |
979 return action; | 1004 return action; |
980 } | 1005 } |
981 return nullptr; | 1006 return nullptr; |
982 } | 1007 } |
983 | 1008 |
984 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 1009 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
985 return browser_->tab_strip_model()->GetActiveWebContents(); | 1010 return browser_->tab_strip_model()->GetActiveWebContents(); |
986 } | 1011 } |
OLD | NEW |