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) { |
422 if (model_) // |model_| can be null in unittests. | 425 if (model_) // |model_| can be null in unittests. |
423 model_observer_.Add(model_); | 426 model_observer_.Add(model_); |
424 | 427 |
425 if (pop_out_actions_to_run_) { | 428 if (pop_out_actions_to_run_) { |
426 if (in_overflow_mode()) | 429 if (in_overflow_mode()) |
427 main_bar_->tab_order_helper_->notify_overflow_bar(this, true); | 430 main_bar_->tab_order_helper_->notify_overflow_bar(this, true); |
428 else | 431 else |
429 tab_order_helper_.reset(new TabOrderHelper(this, browser_, model_)); | 432 tab_order_helper_.reset(new TabOrderHelper(this, browser_, model_)); |
430 } | 433 } |
431 } | 434 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 627 |
625 tracked_objects::ScopedTracker tracking_profile4( | 628 tracked_objects::ScopedTracker tracking_profile4( |
626 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4")); | 629 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4")); |
627 | 630 |
628 for (size_t i = 0; i < toolbar_actions_.size(); ++i) | 631 for (size_t i = 0; i < toolbar_actions_.size(); ++i) |
629 delegate_->AddViewForAction(toolbar_actions_[i], i); | 632 delegate_->AddViewForAction(toolbar_actions_[i], i); |
630 } | 633 } |
631 | 634 |
632 // Once the actions are created, we should animate the changes. | 635 // Once the actions are created, we should animate the changes. |
633 suppress_animation_ = false; | 636 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(); |
634 } | 642 } |
635 | 643 |
636 void ToolbarActionsBar::DeleteActions() { | 644 void ToolbarActionsBar::DeleteActions() { |
637 delegate_->RemoveAllViews(); | 645 delegate_->RemoveAllViews(); |
638 toolbar_actions_.clear(); | 646 toolbar_actions_.clear(); |
639 } | 647 } |
640 | 648 |
641 void ToolbarActionsBar::Update() { | 649 void ToolbarActionsBar::Update() { |
642 if (toolbar_actions_.empty()) | 650 if (toolbar_actions_.empty()) |
643 return; // Nothing to do. | 651 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, | 730 // 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. | 731 // the user won't see anything different, so we treat it as acknowledged. |
724 OnToolbarActionsBarBubbleClosed( | 732 OnToolbarActionsBarBubbleClosed( |
725 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); | 733 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); |
726 return false; | 734 return false; |
727 } | 735 } |
728 | 736 |
729 return true; | 737 return true; |
730 } | 738 } |
731 | 739 |
| 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 |
732 void ToolbarActionsBar::OnToolbarExtensionAdded( | 750 void ToolbarActionsBar::OnToolbarExtensionAdded( |
733 const extensions::Extension* extension, | 751 const extensions::Extension* extension, |
734 int index) { | 752 int index) { |
735 DCHECK(GetActionForId(extension->id()) == nullptr) << | 753 DCHECK(GetActionForId(extension->id()) == nullptr) << |
736 "Asked to add a toolbar action view for an extension that already exists"; | 754 "Asked to add a toolbar action view for an extension that already exists"; |
737 | 755 |
738 toolbar_actions_.insert( | 756 toolbar_actions_.insert( |
739 toolbar_actions_.begin() + index, | 757 toolbar_actions_.begin() + index, |
740 new ExtensionActionViewController( | 758 new ExtensionActionViewController( |
741 extension, | 759 extension, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 for (ToolbarActionViewController* action : toolbar_actions_) { | 995 for (ToolbarActionViewController* action : toolbar_actions_) { |
978 if (action->GetId() == id) | 996 if (action->GetId() == id) |
979 return action; | 997 return action; |
980 } | 998 } |
981 return nullptr; | 999 return nullptr; |
982 } | 1000 } |
983 | 1001 |
984 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 1002 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
985 return browser_->tab_strip_model()->GetActiveWebContents(); | 1003 return browser_->tab_strip_model()->GetActiveWebContents(); |
986 } | 1004 } |
OLD | NEW |