| 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 <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 // CreateActions() can be called multiple times, so we need to make sure we | 366 // CreateActions() can be called multiple times, so we need to make sure we |
| 367 // haven't already shown the bubble. | 367 // haven't already shown the bubble. |
| 368 // Extension bubbles can also highlight a subset of actions, so don't show the | 368 // Extension bubbles can also highlight a subset of actions, so don't show the |
| 369 // bubble if the toolbar is already highlighting a different set. | 369 // bubble if the toolbar is already highlighting a different set. |
| 370 if (should_check_extension_bubble_ && !is_highlighting()) { | 370 if (should_check_extension_bubble_ && !is_highlighting()) { |
| 371 should_check_extension_bubble_ = false; | 371 should_check_extension_bubble_ = false; |
| 372 // CreateActions() can be called as part of the browser window set up, which | 372 // CreateActions() can be called as part of the browser window set up, which |
| 373 // we need to let finish before showing the actions. | 373 // we need to let finish before showing the actions. |
| 374 base::ThreadTaskRunnerHandle::Get()->PostTask( | 374 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 375 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, | 375 FROM_HERE, base::BindOnce(&ToolbarActionsBar::MaybeShowExtensionBubble, |
| 376 weak_ptr_factory_.GetWeakPtr())); | 376 weak_ptr_factory_.GetWeakPtr())); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 void ToolbarActionsBar::DeleteActions() { | 380 void ToolbarActionsBar::DeleteActions() { |
| 381 HideActivePopup(); | 381 HideActivePopup(); |
| 382 delegate_->RemoveAllViews(); | 382 delegate_->RemoveAllViews(); |
| 383 toolbar_actions_.clear(); | 383 toolbar_actions_.clear(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void ToolbarActionsBar::Update() { | 386 void ToolbarActionsBar::Update() { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 // We check ShouldShow() above since we show the bubble asynchronously, and | 575 // We check ShouldShow() above since we show the bubble asynchronously, and |
| 576 // it might no longer have been valid. | 576 // it might no longer have been valid. |
| 577 is_showing_bubble_ = true; | 577 is_showing_bubble_ = true; |
| 578 delegate_->ShowToolbarActionBubble(std::move(bubble)); | 578 delegate_->ShowToolbarActionBubble(std::move(bubble)); |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 void ToolbarActionsBar::ShowToolbarActionBubbleAsync( | 582 void ToolbarActionsBar::ShowToolbarActionBubbleAsync( |
| 583 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { | 583 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { |
| 584 base::ThreadTaskRunnerHandle::Get()->PostTask( | 584 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 585 FROM_HERE, base::Bind(&ToolbarActionsBar::ShowToolbarActionBubble, | 585 FROM_HERE, base::BindOnce(&ToolbarActionsBar::ShowToolbarActionBubble, |
| 586 weak_ptr_factory_.GetWeakPtr(), | 586 weak_ptr_factory_.GetWeakPtr(), |
| 587 base::Passed(std::move(bubble)))); | 587 base::Passed(std::move(bubble)))); |
| 588 } | 588 } |
| 589 | 589 |
| 590 void ToolbarActionsBar::MaybeShowExtensionBubble() { | 590 void ToolbarActionsBar::MaybeShowExtensionBubble() { |
| 591 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller = | 591 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller = |
| 592 model_->GetExtensionMessageBubbleController(browser_); | 592 model_->GetExtensionMessageBubbleController(browser_); |
| 593 if (!controller) | 593 if (!controller) |
| 594 return; | 594 return; |
| 595 | 595 |
| 596 DCHECK(controller->ShouldShow()); | 596 DCHECK(controller->ShouldShow()); |
| 597 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 597 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 598 | 598 |
| 599 // Not showing the bubble right away (during startup) has a few benefits: | 599 // Not showing the bubble right away (during startup) has a few benefits: |
| 600 // We don't have to worry about focus being lost due to the Omnibox (or to | 600 // We don't have to worry about focus being lost due to the Omnibox (or to |
| 601 // other things that want focus at startup). This allows Esc to work to close | 601 // other things that want focus at startup). This allows Esc to work to close |
| 602 // the bubble and also solves the keyboard accessibility problem that comes | 602 // the bubble and also solves the keyboard accessibility problem that comes |
| 603 // with focus being lost (we don't have a good generic mechanism of injecting | 603 // with focus being lost (we don't have a good generic mechanism of injecting |
| 604 // bubbles into the focus cycle). Another benefit of delaying the show is | 604 // bubbles into the focus cycle). Another benefit of delaying the show is |
| 605 // that fade-in works (the fade-in isn't apparent if the the bubble appears at | 605 // that fade-in works (the fade-in isn't apparent if the the bubble appears at |
| 606 // startup). | 606 // startup). |
| 607 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate( | 607 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate( |
| 608 new ExtensionMessageBubbleBridge(std::move(controller))); | 608 new ExtensionMessageBubbleBridge(std::move(controller))); |
| 609 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 609 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 610 FROM_HERE, base::Bind(&ToolbarActionsBar::ShowToolbarActionBubble, | 610 FROM_HERE, |
| 611 weak_ptr_factory_.GetWeakPtr(), | 611 base::BindOnce(&ToolbarActionsBar::ShowToolbarActionBubble, |
| 612 base::Passed(std::move(delegate))), | 612 weak_ptr_factory_.GetWeakPtr(), |
| 613 base::Passed(std::move(delegate))), |
| 613 base::TimeDelta::FromSeconds( | 614 base::TimeDelta::FromSeconds( |
| 614 g_extension_bubble_appearance_wait_time_in_seconds)); | 615 g_extension_bubble_appearance_wait_time_in_seconds)); |
| 615 } | 616 } |
| 616 | 617 |
| 617 // static | 618 // static |
| 618 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( | 619 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( |
| 619 int time_in_seconds) { | 620 int time_in_seconds) { |
| 620 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; | 621 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; |
| 621 } | 622 } |
| 622 | 623 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 for (const auto& action : toolbar_actions_) { | 817 for (const auto& action : toolbar_actions_) { |
| 817 if (action->GetId() == action_id) | 818 if (action->GetId() == action_id) |
| 818 return action.get(); | 819 return action.get(); |
| 819 } | 820 } |
| 820 return nullptr; | 821 return nullptr; |
| 821 } | 822 } |
| 822 | 823 |
| 823 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 824 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 824 return browser_->tab_strip_model()->GetActiveWebContents(); | 825 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 825 } | 826 } |
| OLD | NEW |