OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
8 | 8 |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/extensions/location_bar_controller.h" | 12 #include "chrome/browser/extensions/location_bar_controller.h" |
13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sessions/session_id.h" | 15 #include "chrome/browser/sessions/session_id.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" |
17 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" | 18 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" |
18 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 19 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
19 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 20 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 21 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
22 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/extensions/extension_action.h" | 25 #include "chrome/common/extensions/extension_action.h" |
25 #include "chrome/common/extensions/extension_resource.h" | 26 #include "chrome/common/extensions/extension_resource.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 69 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
69 iter != icon_paths.end(); ++iter) { | 70 iter != icon_paths.end(); ++iter) { |
70 tracker_.LoadImage(extension, extension->GetResource(*iter), | 71 tracker_.LoadImage(extension, extension->GetResource(*iter), |
71 gfx::Size(Extension::kPageActionIconMaxSize, | 72 gfx::Size(Extension::kPageActionIconMaxSize, |
72 Extension::kPageActionIconMaxSize), | 73 Extension::kPageActionIconMaxSize), |
73 ImageLoadingTracker::DONT_CACHE); | 74 ImageLoadingTracker::DONT_CACHE); |
74 } | 75 } |
75 | 76 |
76 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 77 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
77 content::Source<Profile>(browser_->profile())); | 78 content::Source<Profile>(browser_->profile())); |
| 79 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC, |
| 80 content::Source<Profile>(browser_->profile())); |
| 81 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_SCRIPT_BADGE_MAC, |
| 82 content::Source<Profile>(browser_->profile())); |
78 | 83 |
79 // We set the owner last of all so that we can determine whether we are in | 84 // We set the owner last of all so that we can determine whether we are in |
80 // the process of initializing this class or not. | 85 // the process of initializing this class or not. |
81 owner_ = owner; | 86 owner_ = owner; |
82 } | 87 } |
83 | 88 |
84 PageActionDecoration::~PageActionDecoration() {} | 89 PageActionDecoration::~PageActionDecoration() {} |
85 | 90 |
86 // Always |kPageActionIconMaxSize| wide. |ImageDecoration| draws the | 91 // Always |kPageActionIconMaxSize| wide. |ImageDecoration| draws the |
87 // image centered. | 92 // image centered. |
88 CGFloat PageActionDecoration::GetWidthForSpace(CGFloat width) { | 93 CGFloat PageActionDecoration::GetWidthForSpace(CGFloat width) { |
89 return Extension::kPageActionIconMaxSize; | 94 return Extension::kPageActionIconMaxSize; |
90 } | 95 } |
91 | 96 |
92 bool PageActionDecoration::AcceptsMousePress() { | 97 bool PageActionDecoration::AcceptsMousePress() { |
93 return true; | 98 return true; |
94 } | 99 } |
95 | 100 |
96 // Either notify listeners or show a popup depending on the Page | 101 // Either notify listeners or show a popup depending on the Page |
97 // Action. | 102 // Action. |
98 bool PageActionDecoration::OnMousePressed(NSRect frame) { | 103 bool PageActionDecoration::OnMousePressed(NSRect frame) { |
| 104 return ActivatePageAction(frame); |
| 105 } |
| 106 |
| 107 bool PageActionDecoration::ActivatePageAction(NSRect frame) { |
99 TabContents* tab_contents = owner_->GetTabContents(); | 108 TabContents* tab_contents = owner_->GetTabContents(); |
100 if (!tab_contents) { | 109 if (!tab_contents) { |
101 // We don't want other code to try and handle this click. Returning true | 110 // We don't want other code to try and handle this click. Returning true |
102 // prevents this by indicating that we handled it. | 111 // prevents this by indicating that we handled it. |
103 return true; | 112 return true; |
104 } | 113 } |
105 | 114 |
106 LocationBarController* controller = | 115 LocationBarController* controller = |
107 tab_contents->extension_tab_helper()->location_bar_controller(); | 116 tab_contents->extension_tab_helper()->location_bar_controller(); |
108 | 117 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 const content::NotificationSource& source, | 267 const content::NotificationSource& source, |
259 const content::NotificationDetails& details) { | 268 const content::NotificationDetails& details) { |
260 switch (type) { | 269 switch (type) { |
261 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 270 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
262 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 271 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
263 if (popup && ![popup isClosing]) | 272 if (popup && ![popup isClosing]) |
264 [popup close]; | 273 [popup close]; |
265 | 274 |
266 break; | 275 break; |
267 } | 276 } |
| 277 case chrome::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC: |
| 278 case chrome::NOTIFICATION_EXTENSION_COMMAND_SCRIPT_BADGE_MAC: { |
| 279 std::pair<const std::string, gfx::NativeWindow>* payload = |
| 280 content::Details<std::pair<const std::string, gfx::NativeWindow> >( |
| 281 details).ptr(); |
| 282 std::string extension_id = payload->first; |
| 283 gfx::NativeWindow window = payload->second; |
| 284 if (window != browser_->window()->GetNativeWindow()) |
| 285 break; |
| 286 if (extension_id != page_action_->extension_id()) |
| 287 break; |
| 288 NSRect frame = owner_->GetPageActionFrame(page_action_); |
| 289 ActivatePageAction(frame); |
| 290 break; |
| 291 } |
| 292 |
268 default: | 293 default: |
269 NOTREACHED() << "Unexpected notification"; | 294 NOTREACHED() << "Unexpected notification"; |
270 break; | 295 break; |
271 } | 296 } |
272 } | 297 } |
OLD | NEW |