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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 suppress_animation_ = false; | 384 suppress_animation_ = false; |
385 | 385 |
386 // CreateActions() can be called multiple times, so we need to make sure we | 386 // CreateActions() can be called multiple times, so we need to make sure we |
387 // haven't already shown the bubble. | 387 // haven't already shown the bubble. |
388 // Extension bubbles can also highlight a subset of actions, so don't show the | 388 // Extension bubbles can also highlight a subset of actions, so don't show the |
389 // bubble if the toolbar is already highlighting a different set. | 389 // bubble if the toolbar is already highlighting a different set. |
390 if (!checked_extension_bubble_ && !is_highlighting()) { | 390 if (!checked_extension_bubble_ && !is_highlighting()) { |
391 checked_extension_bubble_ = true; | 391 checked_extension_bubble_ = true; |
392 // CreateActions() can be called as part of the browser window set up, which | 392 // CreateActions() can be called as part of the browser window set up, which |
393 // we need to let finish before showing the actions. | 393 // we need to let finish before showing the actions. |
394 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = | 394 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller = |
395 ExtensionMessageBubbleFactory(browser_).GetController(); | 395 ExtensionMessageBubbleFactory(browser_).GetController(); |
396 if (controller) { | 396 if (controller) { |
397 base::ThreadTaskRunnerHandle::Get()->PostTask( | 397 base::ThreadTaskRunnerHandle::Get()->PostTask( |
398 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, | 398 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, |
399 weak_ptr_factory_.GetWeakPtr(), | 399 weak_ptr_factory_.GetWeakPtr(), |
400 base::Passed(std::move(controller)))); | 400 base::Passed(std::move(controller)))); |
401 } | 401 } |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 573 |
574 void ToolbarActionsBar::AddObserver(ToolbarActionsBarObserver* observer) { | 574 void ToolbarActionsBar::AddObserver(ToolbarActionsBarObserver* observer) { |
575 observers_.AddObserver(observer); | 575 observers_.AddObserver(observer); |
576 } | 576 } |
577 | 577 |
578 void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { | 578 void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { |
579 observers_.RemoveObserver(observer); | 579 observers_.RemoveObserver(observer); |
580 } | 580 } |
581 | 581 |
582 void ToolbarActionsBar::ShowToolbarActionBubble( | 582 void ToolbarActionsBar::ShowToolbarActionBubble( |
583 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) { | 583 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { |
584 DCHECK(bubble->GetAnchorActionId().empty() || | 584 DCHECK(bubble->GetAnchorActionId().empty() || |
585 GetActionForId(bubble->GetAnchorActionId())); | 585 GetActionForId(bubble->GetAnchorActionId())); |
586 if (delegate_->IsAnimating()) | 586 if (delegate_->IsAnimating()) |
587 pending_toolbar_bubble_controller_ = std::move(bubble); | 587 pending_toolbar_bubble_controller_ = std::move(bubble); |
588 else | 588 else |
589 delegate_->ShowToolbarActionBubble(std::move(bubble)); | 589 delegate_->ShowToolbarActionBubble(std::move(bubble)); |
590 } | 590 } |
591 | 591 |
592 void ToolbarActionsBar::MaybeShowExtensionBubble( | 592 void ToolbarActionsBar::MaybeShowExtensionBubble( |
593 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 593 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) { |
594 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 594 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
595 if (delegate_->IsAnimating()) { | 595 if (delegate_->IsAnimating()) { |
596 // If the toolbar is animating, we can't effectively anchor the bubble, | 596 // If the toolbar is animating, we can't effectively anchor the bubble, |
597 // so wait until animation stops. | 597 // so wait until animation stops. |
598 pending_extension_bubble_controller_ = std::move(controller); | 598 pending_extension_bubble_controller_ = std::move(controller); |
599 } else if (controller->ShouldShow()) { | 599 } else if (controller->ShouldShow()) { |
600 // We check ShouldShow() above because the affected extensions may have been | 600 // We check ShouldShow() above because the affected extensions may have been |
601 // removed since the controller was initialized. | 601 // removed since the controller was initialized. |
602 const std::vector<std::string>& affected_extensions = | 602 const std::vector<std::string>& affected_extensions = |
603 controller->GetExtensionIdList(); | 603 controller->GetExtensionIdList(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 ToolbarActions::iterator iter = toolbar_actions_.begin(); | 641 ToolbarActions::iterator iter = toolbar_actions_.begin(); |
642 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id) | 642 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id) |
643 ++iter; | 643 ++iter; |
644 | 644 |
645 if (iter == toolbar_actions_.end()) | 645 if (iter == toolbar_actions_.end()) |
646 return; | 646 return; |
647 | 647 |
648 // The action should outlive the UI element (which is owned by the delegate), | 648 // The action should outlive the UI element (which is owned by the delegate), |
649 // so we can't delete it just yet. But we should remove it from the list of | 649 // so we can't delete it just yet. But we should remove it from the list of |
650 // actions so that any width calculations are correct. | 650 // actions so that any width calculations are correct. |
651 scoped_ptr<ToolbarActionViewController> removed_action(*iter); | 651 std::unique_ptr<ToolbarActionViewController> removed_action(*iter); |
652 toolbar_actions_.weak_erase(iter); | 652 toolbar_actions_.weak_erase(iter); |
653 delegate_->RemoveViewForAction(removed_action.get()); | 653 delegate_->RemoveViewForAction(removed_action.get()); |
654 removed_action.reset(); | 654 removed_action.reset(); |
655 | 655 |
656 // If the extension is being upgraded we don't want the bar to shrink | 656 // If the extension is being upgraded we don't want the bar to shrink |
657 // because the icon is just going to get re-added to the same location. | 657 // because the icon is just going to get re-added to the same location. |
658 // There is an exception if this is an off-the-record profile, and the | 658 // There is an exception if this is an off-the-record profile, and the |
659 // extension is no longer incognito-enabled. | 659 // extension is no longer incognito-enabled. |
660 if (!extensions::ExtensionSystem::Get(browser_->profile()) | 660 if (!extensions::ExtensionSystem::Get(browser_->profile()) |
661 ->runtime_data() | 661 ->runtime_data() |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 for (ToolbarActionViewController* action : toolbar_actions_) { | 797 for (ToolbarActionViewController* action : toolbar_actions_) { |
798 if (action->GetId() == action_id) | 798 if (action->GetId() == action_id) |
799 return action; | 799 return action; |
800 } | 800 } |
801 return nullptr; | 801 return nullptr; |
802 } | 802 } |
803 | 803 |
804 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 804 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
805 return browser_->tab_strip_model()->GetActiveWebContents(); | 805 return browser_->tab_strip_model()->GetActiveWebContents(); |
806 } | 806 } |
OLD | NEW |