diff options
Diffstat (limited to 'chrome/browser/ui')
15 files changed, 202 insertions, 11 deletions
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm index 3f97173..d6b7bb5 100644 --- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm @@ -167,11 +167,11 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0; // Returns the associated ToolbarController. - (ToolbarController*)toolbarController; -// Creates a message bubble anchored to the given |anchorAction|, or the app -// menu if no |anchorAction| is null. +// Creates a message bubble with the given |delegate| that is anchored to the +// given |anchorView|. - (ToolbarActionsBarBubbleMac*)createMessageBubble: (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate - anchorToSelf:(BOOL)anchorToSelf; + anchorView:(NSView*)anchorView; // Called when the window for the active bubble is closing, and sets the active // bubble to nil. @@ -223,6 +223,8 @@ class ToolbarActionsBarBridge : public ToolbarActionsBarDelegate { void ShowExtensionMessageBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> controller, ToolbarActionViewController* anchor_action) override; + void ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) override; // The owning BrowserActionsController; weak. BrowserActionsController* controller_; @@ -297,6 +299,19 @@ int ToolbarActionsBarBridge::GetChevronWidth() const { void ToolbarActionsBarBridge::ShowExtensionMessageBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> bubble_controller, ToolbarActionViewController* anchor_action) { + NSView* anchorView = nil; + BOOL anchoredToAction = NO; + if (anchor_action) { + BrowserActionButton* actionButton = + [controller_ buttonForId:anchor_action->GetId()]; + if (actionButton && [actionButton superview]) { + anchorView = actionButton; + anchoredToAction = YES; + } + } + if (!anchorView) + anchorView = [[controller_ toolbarController] appMenuButton]; + // This goop is a by-product of needing to wire together abstract classes, // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange // Show() interface. It's ugly, but it's pretty confined, so it's probably @@ -305,14 +320,32 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble( bubble_controller.get(); scoped_ptr<ExtensionMessageBubbleBridge> bridge( new ExtensionMessageBubbleBridge(std::move(bubble_controller), - anchor_action != nullptr)); + anchoredToAction)); ToolbarActionsBarBubbleMac* bubble = [controller_ createMessageBubble:std::move(bridge) - anchorToSelf:anchor_action != nil]; + anchorView:anchorView]; weak_controller->OnShown(); [bubble showWindow:nil]; } +void ToolbarActionsBarBridge::ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) { + NSView* anchorView = nil; + if (!bubble->GetAnchorActionId().empty()) { + BrowserActionButton* button = + [controller_ buttonForId:bubble->GetAnchorActionId()]; + anchorView = button && [button superview] ? button : + [[controller_ toolbarController] appMenuButton]; + } else { + anchorView = [controller_ containerView]; + } + + ToolbarActionsBarBubbleMac* bubbleView = + [controller_ createMessageBubble:std::move(bubble) + anchorView:anchorView]; + [bubbleView showWindow:nil]; +} + } // namespace @implementation BrowserActionsController @@ -826,7 +859,8 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble( scoped_ptr<ToolbarActionsBarBubbleDelegate> delegate( new ExtensionToolbarIconSurfacingBubbleDelegate(browser_->profile())); ToolbarActionsBarBubbleMac* bubble = - [self createMessageBubble:std::move(delegate) anchorToSelf:YES]; + [self createMessageBubble:std::move(delegate) + anchorView:containerView_]; [bubble showWindow:nil]; } [containerView_ setTrackingEnabled:NO]; @@ -1042,10 +1076,9 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble( - (ToolbarActionsBarBubbleMac*)createMessageBubble: (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate - anchorToSelf:(BOOL)anchorToSelf { + anchorView:(NSView*)anchorView { + DCHECK(anchorView); DCHECK_GE([buttons_ count], 0u); - NSView* anchorView = - anchorToSelf ? containerView_ : [[self toolbarController] appMenuButton]; NSPoint anchor = [self popupPointForView:anchorView withBounds:[anchorView bounds]]; diff --git a/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h b/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h index 5a86977..ab925a4 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h +++ b/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h @@ -32,6 +32,7 @@ class ExtensionMessageBubbleBridge : public ToolbarActionsBarBubbleDelegate { base::string16 GetActionButtonText() override; base::string16 GetDismissButtonText() override; base::string16 GetLearnMoreButtonText() override; + std::string GetAnchorActionId() override; void OnBubbleShown() override; void OnBubbleClosed(CloseAction action) override; diff --git a/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.mm b/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.mm index f7cb1f5..ae34ee2 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.mm @@ -44,6 +44,11 @@ base::string16 ExtensionMessageBubbleBridge::GetLearnMoreButtonText() { return controller_->delegate()->GetLearnMoreLabel(); } +std::string ExtensionMessageBubbleBridge::GetAnchorActionId() { + return controller_->GetExtensionIdList().size() == 1u ? + controller_->GetExtensionIdList()[0] : std::string(); +} + void ExtensionMessageBubbleBridge::OnBubbleShown() { } diff --git a/chrome/browser/ui/extensions/blocked_action_bubble_delegate.cc b/chrome/browser/ui/extensions/blocked_action_bubble_delegate.cc new file mode 100644 index 0000000..288ffef --- /dev/null +++ b/chrome/browser/ui/extensions/blocked_action_bubble_delegate.cc @@ -0,0 +1,53 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/extensions/blocked_action_bubble_delegate.h" + +#include "base/callback_helpers.h" +#include "base/strings/string16.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +BlockedActionBubbleDelegate::BlockedActionBubbleDelegate( + const base::Callback<void(CloseAction)>& callback, + const std::string& extension_id) + : callback_(callback), extension_id_(extension_id) {} + +BlockedActionBubbleDelegate::~BlockedActionBubbleDelegate() {} + +base::string16 BlockedActionBubbleDelegate::GetHeadingText() { + return l10n_util::GetStringUTF16(IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_HEADING); +} + +base::string16 BlockedActionBubbleDelegate::GetBodyText() { + return l10n_util::GetStringUTF16(IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CONTENT); +} + +base::string16 BlockedActionBubbleDelegate::GetItemListText() { + return base::string16(); // No item list. +} + +base::string16 BlockedActionBubbleDelegate::GetActionButtonText() { + return l10n_util::GetStringUTF16( + IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_OK_BUTTON); +} + +base::string16 BlockedActionBubbleDelegate::GetDismissButtonText() { + return l10n_util::GetStringUTF16( + IDS_EXTENSION_BLOCKED_ACTION_BUBBLE_CANCEL_BUTTON); +} + +base::string16 BlockedActionBubbleDelegate::GetLearnMoreButtonText() { + return base::string16(); // No learn more link. +} + +std::string BlockedActionBubbleDelegate::GetAnchorActionId() { + return extension_id_; +} + +void BlockedActionBubbleDelegate::OnBubbleShown() {} + +void BlockedActionBubbleDelegate::OnBubbleClosed(CloseAction action) { + base::ResetAndReturn(&callback_).Run(action); +} diff --git a/chrome/browser/ui/extensions/blocked_action_bubble_delegate.h b/chrome/browser/ui/extensions/blocked_action_bubble_delegate.h new file mode 100644 index 0000000..8e2200e --- /dev/null +++ b/chrome/browser/ui/extensions/blocked_action_bubble_delegate.h @@ -0,0 +1,38 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_EXTENSIONS_BLOCKED_ACTION_BUBBLE_DELEGATE_H_ +#define CHROME_BROWSER_UI_EXTENSIONS_BLOCKED_ACTION_BUBBLE_DELEGATE_H_ + +#include "base/callback.h" +#include "base/macros.h" +#include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" + +// The delegate for the bubble to ask the user if they want to refresh the page +// in order to run any blocked actions the extension may have. +class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate { + public: + BlockedActionBubbleDelegate(const base::Callback<void(CloseAction)>& callback, + const std::string& extension_id); + ~BlockedActionBubbleDelegate() override; + + private: + // ToolbarActionsBarBubbleDelegate: + base::string16 GetHeadingText() override; + base::string16 GetBodyText() override; + base::string16 GetItemListText() override; + base::string16 GetActionButtonText() override; + base::string16 GetDismissButtonText() override; + base::string16 GetLearnMoreButtonText() override; + std::string GetAnchorActionId() override; + void OnBubbleShown() override; + void OnBubbleClosed(CloseAction action) override; + + base::Callback<void(CloseAction)> callback_; + std::string extension_id_; + + DISALLOW_COPY_AND_ASSIGN(BlockedActionBubbleDelegate); +}; + +#endif // CHROME_BROWSER_UI_EXTENSIONS_BLOCKED_ACTION_BUBBLE_DELEGATE_H_ diff --git a/chrome/browser/ui/extensions/extension_action_view_controller.cc b/chrome/browser/ui/extensions/extension_action_view_controller.cc index bdbb532..4b9f123 100644 --- a/chrome/browser/ui/extensions/extension_action_view_controller.cc +++ b/chrome/browser/ui/extensions/extension_action_view_controller.cc @@ -216,7 +216,7 @@ bool ExtensionActionViewController::ExecuteAction(PopupShowAction show_action, if (action_runner->RunAction(extension(), grant_tab_permissions) == ExtensionAction::ACTION_SHOW_POPUP) { GURL popup_url = extension_action_->GetPopupUrl( - SessionTabHelper::IdForTab(view_delegate_->GetCurrentWebContents())); + SessionTabHelper::IdForTab(web_contents)); return GetPreferredPopupViewController() ->TriggerPopupWithUrl(show_action, popup_url, grant_tab_permissions); } diff --git a/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.cc b/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.cc index a2c8ffc..1151155 100644 --- a/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.cc +++ b/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.cc @@ -91,6 +91,10 @@ ExtensionToolbarIconSurfacingBubbleDelegate::GetLearnMoreButtonText() { return base::string16(); // No learn more link. } +std::string ExtensionToolbarIconSurfacingBubbleDelegate::GetAnchorActionId() { + return std::string(); // Point to the whole set of actions. +} + void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleShown() { // Record the last time the bubble was shown. profile_->GetPrefs()->SetInt64( diff --git a/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h b/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h index 527201a..85e4caf 100644 --- a/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h +++ b/chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h @@ -29,6 +29,7 @@ class ExtensionToolbarIconSurfacingBubbleDelegate base::string16 GetActionButtonText() override; base::string16 GetDismissButtonText() override; base::string16 GetLearnMoreButtonText() override; + std::string GetAnchorActionId() override; void OnBubbleShown() override; void OnBubbleClosed(CloseAction action) override; diff --git a/chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.cc b/chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.cc index 957ad6f..fa13f07 100644 --- a/chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.cc +++ b/chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.cc @@ -23,6 +23,7 @@ class TestToolbarActionsBarBubbleDelegate::DelegateImpl base::string16 GetLearnMoreButtonText() override { return parent_->learn_more_; } + std::string GetAnchorActionId() override { return std::string(); } void OnBubbleShown() override { CHECK(!parent_->shown_); parent_->shown_ = true; diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar.cc b/chrome/browser/ui/toolbar/toolbar_actions_bar.cc index 546acd4..cb62c0c 100644 --- a/chrome/browser/ui/toolbar/toolbar_actions_bar.cc +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar.cc @@ -493,6 +493,8 @@ void ToolbarActionsBar::OnAnimationEnded() { // message bubble, or to show a popup. if (pending_extension_bubble_controller_) { MaybeShowExtensionBubble(std::move(pending_extension_bubble_controller_)); + } else if (pending_toolbar_bubble_controller_) { + ShowToolbarActionBubble(std::move(pending_toolbar_bubble_controller_)); } else if (!popped_out_closure_.is_null()) { popped_out_closure_.Run(); popped_out_closure_.Reset(); @@ -575,6 +577,16 @@ void ToolbarActionsBar::RemoveObserver(ToolbarActionsBarObserver* observer) { observers_.RemoveObserver(observer); } +void ToolbarActionsBar::ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) { + DCHECK(bubble->GetAnchorActionId().empty() || + GetActionForId(bubble->GetAnchorActionId())); + if (delegate_->IsAnimating()) + pending_toolbar_bubble_controller_ = std::move(bubble); + else + delegate_->ShowToolbarActionBubble(std::move(bubble)); +} + void ToolbarActionsBar::MaybeShowExtensionBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar.h b/chrome/browser/ui/toolbar/toolbar_actions_bar.h index 1c04dae..871db82 100644 --- a/chrome/browser/ui/toolbar/toolbar_actions_bar.h +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar.h @@ -211,6 +211,10 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer { void AddObserver(ToolbarActionsBarObserver* observer); void RemoveObserver(ToolbarActionsBarObserver* observer); + // Displays the given |bubble| once the toolbar is no longer animating. + void ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble); + // Returns the underlying toolbar actions, but does not order them. Primarily // for use in testing. const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() @@ -336,10 +340,17 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer { // it is fully popped out. base::Closure popped_out_closure_; - // The controller of the bubble to show once animation finishes, if any. + // The controller of the extension message bubble to show once animation + // finishes, if any. This has priority over + // |pending_toolbar_bubble_controller_|. scoped_ptr<extensions::ExtensionMessageBubbleController> pending_extension_bubble_controller_; + // The controller for the toolbar action bubble to show once animation + // finishes, if any. + scoped_ptr<ToolbarActionsBarBubbleDelegate> + pending_toolbar_bubble_controller_; + base::ObserverList<ToolbarActionsBarObserver> observers_; base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_; diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h b/chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h index 508371e..d07dc71 100644 --- a/chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_BUBBLE_DELEGATE_H_ #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_BUBBLE_DELEGATE_H_ +#include <string> + #include "base/strings/string16.h" // A delegate for a generic bubble that hangs off the toolbar actions bar. @@ -43,6 +45,10 @@ class ToolbarActionsBarBubbleDelegate { // string, no button will be added. virtual base::string16 GetLearnMoreButtonText() = 0; + // Returns the id of the action to point to, or the empty string if the + // bubble should point to the center of the actions container. + virtual std::string GetAnchorActionId() = 0; + // Called when the bubble is shown. virtual void OnBubbleShown() = 0; diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h b/chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h index 584a4b3..4c31025 100644 --- a/chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h @@ -12,6 +12,7 @@ #include "ui/gfx/geometry/size.h" class ToolbarActionViewController; +class ToolbarActionsBarBubbleDelegate; namespace extensions { class ExtensionMessageBubbleController; @@ -70,6 +71,10 @@ class ToolbarActionsBarDelegate { virtual void ShowExtensionMessageBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> controller, ToolbarActionViewController* anchor_action) = 0; + + // Shows the given |bubble| if no other bubbles are showing. + virtual void ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) = 0; }; #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_DELEGATE_H_ diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc index 5ac758e..2d704d4 100644 --- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc +++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc @@ -319,6 +319,25 @@ int BrowserActionsContainer::GetChevronWidth() const { chevron_->GetPreferredSize().width() + GetChevronSpacing() : 0; } +void BrowserActionsContainer::ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> controller) { + // The container shouldn't be asked to show a bubble if it's animating. + DCHECK(!animating()); + views::View* anchor_view = nullptr; + if (!controller->GetAnchorActionId().empty()) { + ToolbarActionView* action_view = + GetViewForId(controller->GetAnchorActionId()); + anchor_view = + action_view->visible() ? action_view : GetOverflowReferenceView(); + } else { + anchor_view = this; + } + ToolbarActionsBarBubbleViews* bubble = + new ToolbarActionsBarBubbleViews(anchor_view, std::move(controller)); + views::BubbleDelegateView::CreateBubble(bubble); + bubble->Show(); +} + void BrowserActionsContainer::ShowExtensionMessageBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> controller, ToolbarActionViewController* anchor_action) { diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.h b/chrome/browser/ui/views/toolbar/browser_actions_container.h index 14517aa..f77f7cb 100644 --- a/chrome/browser/ui/views/toolbar/browser_actions_container.h +++ b/chrome/browser/ui/views/toolbar/browser_actions_container.h @@ -239,6 +239,8 @@ class BrowserActionsContainer : public views::View, bool IsAnimating() const override; void StopAnimating() override; int GetChevronWidth() const override; + void ShowToolbarActionBubble( + scoped_ptr<ToolbarActionsBarBubbleDelegate> controller) override; void ShowExtensionMessageBubble( scoped_ptr<extensions::ExtensionMessageBubbleController> controller, ToolbarActionViewController* anchor_action) override; |
