| 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 #import "chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_c
ocoa.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_c
ocoa.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 16 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_action_view_delegate_cocoa.h" | 17 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 17 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 18 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" | 19 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 19 #include "chrome/common/extensions/api/extension_action/action_info.h" | 21 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 20 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 22 #include "extensions/browser/notification_types.h" | 24 #include "extensions/browser/notification_types.h" |
| 23 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 // Returns the notification to listen to for activation for a particular | 29 // Returns the notification to listen to for activation for a particular |
| 28 // |extension_action|. | 30 // |extension_action|. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 78 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
| 77 if (popup && ![popup isClosing]) | 79 if (popup && ![popup isClosing]) |
| 78 [popup close]; | 80 [popup close]; |
| 79 } | 81 } |
| 80 | 82 |
| 81 extensions::ExtensionViewHost* | 83 extensions::ExtensionViewHost* |
| 82 ExtensionActionPlatformDelegateCocoa::ShowPopupWithUrl( | 84 ExtensionActionPlatformDelegateCocoa::ShowPopupWithUrl( |
| 83 ExtensionActionViewController::PopupShowAction show_action, | 85 ExtensionActionViewController::PopupShowAction show_action, |
| 84 const GURL& popup_url, | 86 const GURL& popup_url, |
| 85 bool grant_tab_permissions) { | 87 bool grant_tab_permissions) { |
| 86 NSPoint arrowPoint = GetDelegateCocoa()->GetPopupPoint(); | |
| 87 | |
| 88 // If this was triggered by an action overflowed to the wrench menu, then | 88 // If this was triggered by an action overflowed to the wrench menu, then |
| 89 // the wrench menu will be open. Close it before opening the popup. | 89 // the wrench menu will be open. Close it before opening the popup. |
| 90 WrenchMenuController* wrenchMenuController = | 90 WrenchMenuController* wrenchMenuController = |
| 91 [[[BrowserWindowController | 91 [[[BrowserWindowController |
| 92 browserWindowControllerForWindow: | 92 browserWindowControllerForWindow: |
| 93 controller_->browser()->window()->GetNativeWindow()] | 93 controller_->browser()->window()->GetNativeWindow()] |
| 94 toolbarController] wrenchMenuController]; | 94 toolbarController] wrenchMenuController]; |
| 95 if ([wrenchMenuController isMenuOpen]) | 95 if ([wrenchMenuController isMenuOpen]) |
| 96 [wrenchMenuController cancel]; | 96 [wrenchMenuController cancel]; |
| 97 | 97 |
| 98 BOOL devMode = | 98 BOOL devMode = |
| 99 show_action == ExtensionActionViewController::SHOW_POPUP_AND_INSPECT; | 99 show_action == ExtensionActionViewController::SHOW_POPUP_AND_INSPECT; |
| 100 ExtensionPopupController* popupController = | 100 ExtensionPopupController* popupController = |
| 101 [ExtensionPopupController showURL:popup_url | 101 [ExtensionPopupController showURL:popup_url |
| 102 inBrowser:controller_->browser() | 102 inBrowser:controller_->browser() |
| 103 anchoredAt:arrowPoint | 103 anchoredAt:GetPopupPoint() |
| 104 arrowLocation:info_bubble::kTopRight | 104 arrowLocation:info_bubble::kTopRight |
| 105 devMode:devMode]; | 105 devMode:devMode]; |
| 106 return [popupController extensionViewHost]; | 106 return [popupController extensionViewHost]; |
| 107 } | 107 } |
| 108 | 108 |
| 109 ToolbarActionViewDelegateCocoa* | 109 NSPoint ExtensionActionPlatformDelegateCocoa::GetPopupPoint() const { |
| 110 ExtensionActionPlatformDelegateCocoa::GetDelegateCocoa() { | 110 BrowserWindowController* windowController = |
| 111 return static_cast<ToolbarActionViewDelegateCocoa*>( | 111 [BrowserWindowController browserWindowControllerForWindow: |
| 112 controller_->view_delegate()); | 112 controller_->browser()->window()->GetNativeWindow()]; |
| 113 NSPoint popupPoint; |
| 114 if (controller_->extension_action()->action_type() == |
| 115 extensions::ActionInfo::TYPE_PAGE) { |
| 116 popupPoint = [windowController locationBarBridge]->GetPageActionBubblePoint( |
| 117 controller_->extension_action()); |
| 118 } else { |
| 119 DCHECK_EQ(extensions::ActionInfo::TYPE_BROWSER, |
| 120 controller_->extension_action()->action_type()); |
| 121 BrowserActionsController* actionsController = |
| 122 [[windowController toolbarController] browserActionsController]; |
| 123 popupPoint = [actionsController popupPointForId:controller_->GetId()]; |
| 124 } |
| 125 return popupPoint; |
| 113 } | 126 } |
| 114 | 127 |
| 115 void ExtensionActionPlatformDelegateCocoa::Observe( | 128 void ExtensionActionPlatformDelegateCocoa::Observe( |
| 116 int type, | 129 int type, |
| 117 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
| 118 const content::NotificationDetails& details) { | 131 const content::NotificationDetails& details) { |
| 119 switch (type) { | 132 switch (type) { |
| 120 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 133 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 121 CloseActivePopup(); | 134 CloseActivePopup(); |
| 122 break; | 135 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 controller_->IsEnabled( | 147 controller_->IsEnabled( |
| 135 controller_->view_delegate()->GetCurrentWebContents())) { | 148 controller_->view_delegate()->GetCurrentWebContents())) { |
| 136 controller_->ExecuteAction(true); | 149 controller_->ExecuteAction(true); |
| 137 } | 150 } |
| 138 break; | 151 break; |
| 139 } | 152 } |
| 140 default: | 153 default: |
| 141 NOTREACHED() << L"Unexpected notification"; | 154 NOTREACHED() << L"Unexpected notification"; |
| 142 } | 155 } |
| 143 } | 156 } |
| OLD | NEW |