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