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 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 break; | 205 break; |
206 } | 206 } |
207 case chrome::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC: { | 207 case chrome::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC: { |
208 std::pair<const std::string, gfx::NativeWindow>* payload = | 208 std::pair<const std::string, gfx::NativeWindow>* payload = |
209 content::Details<std::pair<const std::string, gfx::NativeWindow> >( | 209 content::Details<std::pair<const std::string, gfx::NativeWindow> >( |
210 details).ptr(); | 210 details).ptr(); |
211 std::string extension_id = payload->first; | 211 std::string extension_id = payload->first; |
212 gfx::NativeWindow window = payload->second; | 212 gfx::NativeWindow window = payload->second; |
213 if (window != browser_->window()->GetNativeWindow()) | 213 if (window != browser_->window()->GetNativeWindow()) |
214 break; | 214 break; |
215 ExtensionService* service = browser_->profile()->GetExtensionService(); | 215 [owner_ activateBrowserAction:extension_id]; |
216 if (!service) | |
217 break; | |
218 const Extension* extension = service->GetExtensionById(extension_id, | |
219 false); | |
220 if (!extension) | |
221 break; | |
222 BrowserActionButton* button = [owner_ buttonForExtension:extension]; | |
223 // |button| can be nil when the browser action has its button hidden. | |
224 if (button) | |
225 [owner_ browserActionClicked:button]; | |
226 break; | 216 break; |
227 } | 217 } |
228 default: | 218 default: |
229 NOTREACHED() << L"Unexpected notification"; | 219 NOTREACHED() << L"Unexpected notification"; |
230 } | 220 } |
231 } | 221 } |
232 | 222 |
233 // ExtensionToolbarModel::Observer implementation. | 223 // ExtensionToolbarModel::Observer implementation. |
234 virtual void BrowserActionAdded( | 224 virtual void BrowserActionAdded( |
235 const Extension* extension, | 225 const Extension* extension, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (effect == NSViewAnimationFadeInEffect) { | 435 if (effect == NSViewAnimationFadeInEffect) { |
446 return NO; | 436 return NO; |
447 } else if (effect == NSViewAnimationFadeOutEffect) { | 437 } else if (effect == NSViewAnimationFadeOutEffect) { |
448 return YES; | 438 return YES; |
449 } | 439 } |
450 | 440 |
451 NOTREACHED(); | 441 NOTREACHED(); |
452 return YES; | 442 return YES; |
453 } | 443 } |
454 | 444 |
| 445 - (void)activateBrowserAction:(const std::string&)extension_id { |
| 446 ExtensionService* service = browser_->profile()->GetExtensionService(); |
| 447 if (!service) |
| 448 return; |
| 449 |
| 450 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 451 if (!extension) |
| 452 return; |
| 453 |
| 454 BrowserActionButton* button = [self buttonForExtension:extension]; |
| 455 // |button| can be nil when the browser action has its button hidden. |
| 456 if (button) |
| 457 [self browserActionClicked:button]; |
| 458 } |
| 459 |
455 #pragma mark - | 460 #pragma mark - |
456 #pragma mark NSMenuDelegate | 461 #pragma mark NSMenuDelegate |
457 | 462 |
458 - (void)menuNeedsUpdate:(NSMenu*)menu { | 463 - (void)menuNeedsUpdate:(NSMenu*)menu { |
459 [menu removeAllItems]; | 464 [menu removeAllItems]; |
460 | 465 |
461 // See menu_button.h for documentation on why this is needed. | 466 // See menu_button.h for documentation on why this is needed. |
462 [menu addItemWithTitle:@"" action:nil keyEquivalent:@""]; | 467 [menu addItemWithTitle:@"" action:nil keyEquivalent:@""]; |
463 | 468 |
464 for (BrowserActionButton* button in hiddenButtons_.get()) { | 469 for (BrowserActionButton* button in hiddenButtons_.get()) { |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 const extensions::ExtensionList& toolbar_items = | 887 const extensions::ExtensionList& toolbar_items = |
883 toolbarModel_->toolbar_items(); | 888 toolbarModel_->toolbar_items(); |
884 if (index < toolbar_items.size()) { | 889 if (index < toolbar_items.size()) { |
885 const Extension* extension = toolbar_items[index].get(); | 890 const Extension* extension = toolbar_items[index].get(); |
886 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 891 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
887 } | 892 } |
888 return nil; | 893 return nil; |
889 } | 894 } |
890 | 895 |
891 @end | 896 @end |
OLD | NEW |