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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_action_platform_delegate_cocoa.mm

Issue 703443002: Move more extension action cocoa logic into the platform delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_toolbar_abstract_extension_action
Patch Set: Created 6 years, 1 month 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 #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>
8 #include <utility>
9
10 #include "base/logging.h"
11 #include "chrome/browser/extensions/extension_action.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu_contro ller.h"
7 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 15 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
8 #import "chrome/browser/ui/cocoa/toolbar/toolbar_action_view_delegate_cocoa.h" 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_action_view_delegate_cocoa.h"
17 #include "chrome/common/extensions/api/extension_action/action_info.h"
18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h"
20 #include "extensions/browser/notification_types.h"
9 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
10 22
23 namespace {
24
25 // Returns the notification to listen to for activation for a particular
26 // |extension_action|.
27 int GetNotificationTypeForAction(const ExtensionAction& extension_action) {
28 if (extension_action.action_type() == extensions::ActionInfo::TYPE_BROWSER)
29 return extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC;
30
31 // We should only have page and browser action types.
32 DCHECK_EQ(extensions::ActionInfo::TYPE_PAGE, extension_action.action_type());
33 return extensions::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC;
34 }
35
36 } // namespace
37
11 // static 38 // static
12 scoped_ptr<ExtensionActionPlatformDelegate> 39 scoped_ptr<ExtensionActionPlatformDelegate>
13 ExtensionActionPlatformDelegate::Create( 40 ExtensionActionPlatformDelegate::Create(
14 ExtensionActionViewController* controller) { 41 ExtensionActionViewController* controller) {
15 return make_scoped_ptr(new ExtensionActionPlatformDelegateCocoa(controller)); 42 return make_scoped_ptr(new ExtensionActionPlatformDelegateCocoa(controller));
16 } 43 }
17 44
18 ExtensionActionPlatformDelegateCocoa::ExtensionActionPlatformDelegateCocoa( 45 ExtensionActionPlatformDelegateCocoa::ExtensionActionPlatformDelegateCocoa(
19 ExtensionActionViewController* controller) 46 ExtensionActionViewController* controller)
20 : controller_(controller) { 47 : controller_(controller) {
(...skipping 10 matching lines...) Expand all
31 bool ExtensionActionPlatformDelegateCocoa::IsMenuRunning() const { 58 bool ExtensionActionPlatformDelegateCocoa::IsMenuRunning() const {
32 // TODO(devlin): Also account for context menus. 59 // TODO(devlin): Also account for context menus.
33 return GetPopup() != nil; 60 return GetPopup() != nil;
34 } 61 }
35 62
36 void ExtensionActionPlatformDelegateCocoa::RegisterCommand() { 63 void ExtensionActionPlatformDelegateCocoa::RegisterCommand() {
37 // Commands are handled elsewhere for cocoa. 64 // Commands are handled elsewhere for cocoa.
38 } 65 }
39 66
40 void ExtensionActionPlatformDelegateCocoa::OnDelegateSet() { 67 void ExtensionActionPlatformDelegateCocoa::OnDelegateSet() {
68 if (controller_->extension()->ShowConfigureContextMenus()) {
69 menuController_.reset([[ExtensionActionContextMenuController alloc]
70 initWithExtension:controller_->extension()
71 browser:controller_->browser()
72 extensionAction:controller_->extension_action()]);
73 GetDelegateCocoa()->SetContextMenuController(menuController_.get());
74 }
75
76 registrar_.Add(
77 this,
78 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
79 content::Source<Profile>(controller_->browser()->profile()));
80 registrar_.Add(
81 this,
82 GetNotificationTypeForAction(*controller_->extension_action()),
83 content::Source<Profile>(controller_->browser()->profile()));
41 } 84 }
42 85
43 bool ExtensionActionPlatformDelegateCocoa::IsShowingPopup() const { 86 bool ExtensionActionPlatformDelegateCocoa::IsShowingPopup() const {
44 return GetPopup() != nil; 87 return GetPopup() != nil;
45 } 88 }
46 89
47 void ExtensionActionPlatformDelegateCocoa::CloseActivePopup() { 90 void ExtensionActionPlatformDelegateCocoa::CloseActivePopup() {
48 ExtensionPopupController* popup = [ExtensionPopupController popup]; 91 ExtensionPopupController* popup = [ExtensionPopupController popup];
49 if (popup) 92 if (popup && ![popup isClosing])
50 [popup close]; 93 [popup close];
51 } 94 }
52 95
53 void ExtensionActionPlatformDelegateCocoa::CloseOwnPopup() { 96 void ExtensionActionPlatformDelegateCocoa::CloseOwnPopup() {
54 ExtensionPopupController* popup = GetPopup(); 97 ExtensionPopupController* popup = GetPopup();
55 DCHECK(popup); 98 DCHECK(popup);
56 [popup close]; 99 if (popup && ![popup isClosing])
100 [popup close];
57 } 101 }
58 102
59 bool ExtensionActionPlatformDelegateCocoa::ShowPopupWithUrl( 103 bool ExtensionActionPlatformDelegateCocoa::ShowPopupWithUrl(
60 ExtensionActionViewController::PopupShowAction show_action, 104 ExtensionActionViewController::PopupShowAction show_action,
61 const GURL& popup_url, 105 const GURL& popup_url,
62 bool grant_tab_permissions) { 106 bool grant_tab_permissions) {
63 NSPoint arrowPoint = GetDelegateCocoa()->GetPopupPoint(); 107 NSPoint arrowPoint = GetDelegateCocoa()->GetPopupPoint();
64 [ExtensionPopupController showURL:popup_url 108 [ExtensionPopupController showURL:popup_url
65 inBrowser:controller_->browser() 109 inBrowser:controller_->browser()
66 anchoredAt:arrowPoint 110 anchoredAt:arrowPoint
67 arrowLocation:info_bubble::kTopRight 111 arrowLocation:info_bubble::kTopRight
68 devMode:NO]; 112 devMode:NO];
69 return true; 113 return true;
70 } 114 }
71 115
72 ToolbarActionViewDelegateCocoa* 116 ToolbarActionViewDelegateCocoa*
73 ExtensionActionPlatformDelegateCocoa::GetDelegateCocoa() { 117 ExtensionActionPlatformDelegateCocoa::GetDelegateCocoa() {
74 return static_cast<ToolbarActionViewDelegateCocoa*>( 118 return static_cast<ToolbarActionViewDelegateCocoa*>(
75 controller_->view_delegate()); 119 controller_->view_delegate());
76 } 120 }
77 121
78 ExtensionPopupController* ExtensionActionPlatformDelegateCocoa::GetPopup() 122 ExtensionPopupController* ExtensionActionPlatformDelegateCocoa::GetPopup()
79 const { 123 const {
80 ExtensionPopupController* popup = [ExtensionPopupController popup]; 124 ExtensionPopupController* popup = [ExtensionPopupController popup];
81 return popup && [popup extensionId] == controller_->extension()->id() ? 125 return popup && [popup extensionId] == controller_->extension()->id() ?
82 popup : nil; 126 popup : nil;
83 } 127 }
128
129 void ExtensionActionPlatformDelegateCocoa::Observe(
130 int type,
131 const content::NotificationSource& source,
132 const content::NotificationDetails& details) {
133 switch (type) {
134 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
135 CloseActivePopup();
136 break;
137 case extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC:
138 case extensions::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC: {
Avi (use Gerrit) 2014/11/03 22:04:00 Not for this CL, but why don't we collapse these?
Devlin 2014/11/03 22:07:28 I can't think of a reason to not (since extensions
139 DCHECK_EQ(type,
140 GetNotificationTypeForAction(*controller_->extension_action()));
141 std::pair<const std::string, gfx::NativeWindow>* payload =
142 content::Details<std::pair<const std::string, gfx::NativeWindow> >(
143 details).ptr();
144 const std::string& extension_id = payload->first;
145 gfx::NativeWindow window = payload->second;
146 if (window == controller_->browser()->window()->GetNativeWindow() &&
147 extension_id == controller_->extension()->id() &&
148 controller_->IsEnabled(
149 controller_->view_delegate()->GetCurrentWebContents())) {
150 controller_->ExecuteAction(true);
151 }
152 break;
153 }
154 default:
155 NOTREACHED() << L"Unexpected notification";
156 }
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698