| 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> |
| 8 |
| 7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 14 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 13 #include "chrome/browser/extensions/extension_util.h" | 15 #include "chrome/browser/extensions/extension_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" | 17 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (!checked_extension_bubble_ && !is_highlighting()) { | 386 if (!checked_extension_bubble_ && !is_highlighting()) { |
| 385 checked_extension_bubble_ = true; | 387 checked_extension_bubble_ = true; |
| 386 // CreateActions() can be called as part of the browser window set up, which | 388 // CreateActions() can be called as part of the browser window set up, which |
| 387 // we need to let finish before showing the actions. | 389 // we need to let finish before showing the actions. |
| 388 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = | 390 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = |
| 389 ExtensionMessageBubbleFactory(browser_).GetController(); | 391 ExtensionMessageBubbleFactory(browser_).GetController(); |
| 390 if (controller) { | 392 if (controller) { |
| 391 base::ThreadTaskRunnerHandle::Get()->PostTask( | 393 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 392 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, | 394 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, |
| 393 weak_ptr_factory_.GetWeakPtr(), | 395 weak_ptr_factory_.GetWeakPtr(), |
| 394 base::Passed(controller.Pass()))); | 396 base::Passed(std::move(controller)))); |
| 395 } | 397 } |
| 396 } | 398 } |
| 397 } | 399 } |
| 398 | 400 |
| 399 void ToolbarActionsBar::DeleteActions() { | 401 void ToolbarActionsBar::DeleteActions() { |
| 400 HideActivePopup(); | 402 HideActivePopup(); |
| 401 delegate_->RemoveAllViews(); | 403 delegate_->RemoveAllViews(); |
| 402 toolbar_actions_.clear(); | 404 toolbar_actions_.clear(); |
| 403 } | 405 } |
| 404 | 406 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(), | 481 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 480 dropped_index); | 482 dropped_index); |
| 481 if (delta) | 483 if (delta) |
| 482 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 484 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 483 } | 485 } |
| 484 | 486 |
| 485 void ToolbarActionsBar::OnAnimationEnded() { | 487 void ToolbarActionsBar::OnAnimationEnded() { |
| 486 // Check if we were waiting for animation to complete to either show a | 488 // Check if we were waiting for animation to complete to either show a |
| 487 // message bubble, or to show a popup. | 489 // message bubble, or to show a popup. |
| 488 if (pending_extension_bubble_controller_) { | 490 if (pending_extension_bubble_controller_) { |
| 489 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); | 491 MaybeShowExtensionBubble(std::move(pending_extension_bubble_controller_)); |
| 490 } else if (!popped_out_closure_.is_null()) { | 492 } else if (!popped_out_closure_.is_null()) { |
| 491 popped_out_closure_.Run(); | 493 popped_out_closure_.Run(); |
| 492 popped_out_closure_.Reset(); | 494 popped_out_closure_.Reset(); |
| 493 } | 495 } |
| 494 } | 496 } |
| 495 | 497 |
| 496 bool ToolbarActionsBar::IsActionVisibleOnMainBar( | 498 bool ToolbarActionsBar::IsActionVisibleOnMainBar( |
| 497 const ToolbarActionViewController* action) const { | 499 const ToolbarActionViewController* action) const { |
| 498 if (in_overflow_mode()) | 500 if (in_overflow_mode()) |
| 499 return main_bar_->IsActionVisibleOnMainBar(action); | 501 return main_bar_->IsActionVisibleOnMainBar(action); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { | 567 void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { |
| 566 observers_.RemoveObserver(observer); | 568 observers_.RemoveObserver(observer); |
| 567 } | 569 } |
| 568 | 570 |
| 569 void ToolbarActionsBar::MaybeShowExtensionBubble( | 571 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 570 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 572 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 571 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 573 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 572 if (delegate_->IsAnimating()) { | 574 if (delegate_->IsAnimating()) { |
| 573 // If the toolbar is animating, we can't effectively anchor the bubble, | 575 // If the toolbar is animating, we can't effectively anchor the bubble, |
| 574 // so wait until animation stops. | 576 // so wait until animation stops. |
| 575 pending_extension_bubble_controller_ = controller.Pass(); | 577 pending_extension_bubble_controller_ = std::move(controller); |
| 576 } else if (controller->ShouldShow()) { | 578 } else if (controller->ShouldShow()) { |
| 577 // We check ShouldShow() above because the affected extensions may have been | 579 // We check ShouldShow() above because the affected extensions may have been |
| 578 // removed since the controller was initialized. | 580 // removed since the controller was initialized. |
| 579 const std::vector<std::string>& affected_extensions = | 581 const std::vector<std::string>& affected_extensions = |
| 580 controller->GetExtensionIdList(); | 582 controller->GetExtensionIdList(); |
| 581 ToolbarActionViewController* anchor_action = nullptr; | 583 ToolbarActionViewController* anchor_action = nullptr; |
| 582 for (const std::string& id : affected_extensions) { | 584 for (const std::string& id : affected_extensions) { |
| 583 anchor_action = GetActionForId(id); | 585 anchor_action = GetActionForId(id); |
| 584 if (anchor_action) | 586 if (anchor_action) |
| 585 break; | 587 break; |
| 586 } | 588 } |
| 587 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); | 589 delegate_->ShowExtensionMessageBubble(std::move(controller), anchor_action); |
| 588 } | 590 } |
| 589 } | 591 } |
| 590 | 592 |
| 591 void ToolbarActionsBar::OnToolbarActionAdded( | 593 void ToolbarActionsBar::OnToolbarActionAdded( |
| 592 const ToolbarActionsModel::ToolbarItem& item, | 594 const ToolbarActionsModel::ToolbarItem& item, |
| 593 int index) { | 595 int index) { |
| 594 DCHECK(GetActionForId(item.id) == nullptr) | 596 DCHECK(GetActionForId(item.id) == nullptr) |
| 595 << "Asked to add a toolbar action view for an action that already " | 597 << "Asked to add a toolbar action view for an action that already " |
| 596 "exists"; | 598 "exists"; |
| 597 | 599 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 for (ToolbarActionViewController* action : toolbar_actions_) { | 776 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 775 if (action->GetId() == action_id) | 777 if (action->GetId() == action_id) |
| 776 return action; | 778 return action; |
| 777 } | 779 } |
| 778 return nullptr; | 780 return nullptr; |
| 779 } | 781 } |
| 780 | 782 |
| 781 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 783 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 782 return browser_->tab_strip_model()->GetActiveWebContents(); | 784 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 783 } | 785 } |
| OLD | NEW |