Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.cc

Issue 2105393002: [Extensions UI] Handle multiple warning bubbles racing to show (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/extensions/extension_message_bubble_controller.h" 15 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
16 #include "chrome/browser/extensions/extension_util.h" 16 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sessions/session_tab_helper.h" 18 #include "chrome/browser/sessions/session_tab_helper.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" 21 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
22 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" 22 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h"
23 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h"
24 #include "chrome/browser/ui/extensions/settings_api_bubble_helpers.h" 23 #include "chrome/browser/ui/extensions/settings_api_bubble_helpers.h"
25 #include "chrome/browser/ui/layout_constants.h" 24 #include "chrome/browser/ui/layout_constants.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 26 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
28 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 27 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" 28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h"
30 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h" 29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h"
31 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
32 #include "components/crx_file/id_util.h" 31 #include "components/crx_file/id_util.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 32 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 suppress_animation_ = false; 398 suppress_animation_ = false;
400 399
401 // CreateActions() can be called multiple times, so we need to make sure we 400 // CreateActions() can be called multiple times, so we need to make sure we
402 // haven't already shown the bubble. 401 // haven't already shown the bubble.
403 // Extension bubbles can also highlight a subset of actions, so don't show the 402 // Extension bubbles can also highlight a subset of actions, so don't show the
404 // bubble if the toolbar is already highlighting a different set. 403 // bubble if the toolbar is already highlighting a different set.
405 if (should_check_extension_bubble_ && !is_highlighting()) { 404 if (should_check_extension_bubble_ && !is_highlighting()) {
406 should_check_extension_bubble_ = false; 405 should_check_extension_bubble_ = false;
407 // CreateActions() can be called as part of the browser window set up, which 406 // CreateActions() can be called as part of the browser window set up, which
408 // we need to let finish before showing the actions. 407 // we need to let finish before showing the actions.
409 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller = 408 base::ThreadTaskRunnerHandle::Get()->PostTask(
410 ExtensionMessageBubbleFactory(browser_).GetController(); 409 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble,
411 if (controller) { 410 weak_ptr_factory_.GetWeakPtr()));
412 base::ThreadTaskRunnerHandle::Get()->PostTask(
413 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble,
414 weak_ptr_factory_.GetWeakPtr(),
415 base::Passed(std::move(controller))));
416 }
417 } 411 }
418 } 412 }
419 413
420 void ToolbarActionsBar::DeleteActions() { 414 void ToolbarActionsBar::DeleteActions() {
421 HideActivePopup(); 415 HideActivePopup();
422 delegate_->RemoveAllViews(); 416 delegate_->RemoveAllViews();
423 toolbar_actions_.clear(); 417 toolbar_actions_.clear();
424 } 418 }
425 419
426 void ToolbarActionsBar::Update() { 420 void ToolbarActionsBar::Update() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 609 }
616 610
617 void ToolbarActionsBar::ShowToolbarActionBubbleAsync( 611 void ToolbarActionsBar::ShowToolbarActionBubbleAsync(
618 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { 612 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) {
619 base::ThreadTaskRunnerHandle::Get()->PostTask( 613 base::ThreadTaskRunnerHandle::Get()->PostTask(
620 FROM_HERE, base::Bind(&ToolbarActionsBar::ShowToolbarActionBubble, 614 FROM_HERE, base::Bind(&ToolbarActionsBar::ShowToolbarActionBubble,
621 weak_ptr_factory_.GetWeakPtr(), 615 weak_ptr_factory_.GetWeakPtr(),
622 base::Passed(std::move(bubble)))); 616 base::Passed(std::move(bubble))));
623 } 617 }
624 618
625 void ToolbarActionsBar::MaybeShowExtensionBubble( 619 void ToolbarActionsBar::MaybeShowExtensionBubble() {
626 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) { 620 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller =
627 if (!controller->ShouldShow()) 621 model_->GetExtensionMessageBubbleController(browser_);
622 if (!controller)
628 return; 623 return;
629 624
625 DCHECK(controller->ShouldShow());
630 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. 626 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times.
631 627
632 // Not showing the bubble right away (during startup) has a few benefits: 628 // Not showing the bubble right away (during startup) has a few benefits:
633 // We don't have to worry about focus being lost due to the Omnibox (or to 629 // We don't have to worry about focus being lost due to the Omnibox (or to
634 // other things that want focus at startup). This allows Esc to work to close 630 // other things that want focus at startup). This allows Esc to work to close
635 // the bubble and also solves the keyboard accessibility problem that comes 631 // the bubble and also solves the keyboard accessibility problem that comes
636 // with focus being lost (we don't have a good generic mechanism of injecting 632 // with focus being lost (we don't have a good generic mechanism of injecting
637 // bubbles into the focus cycle). Another benefit of delaying the show is 633 // bubbles into the focus cycle). Another benefit of delaying the show is
638 // that fade-in works (the fade-in isn't apparent if the the bubble appears at 634 // that fade-in works (the fade-in isn't apparent if the the bubble appears at
639 // startup). 635 // startup).
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 for (ToolbarActionViewController* action : toolbar_actions_) { 844 for (ToolbarActionViewController* action : toolbar_actions_) {
849 if (action->GetId() == action_id) 845 if (action->GetId() == action_id)
850 return action; 846 return action;
851 } 847 }
852 return nullptr; 848 return nullptr;
853 } 849 }
854 850
855 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 851 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
856 return browser_->tab_strip_model()->GetActiveWebContents(); 852 return browser_->tab_strip_model()->GetActiveWebContents();
857 } 853 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_bar.h ('k') | chrome/browser/ui/toolbar/toolbar_actions_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698