OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/toolbar/browser_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 called_registered_extension_command_(false), | 113 called_registered_extension_command_(false), |
114 icon_observer_(NULL) { | 114 icon_observer_(NULL) { |
115 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 115 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
116 set_context_menu_controller(this); | 116 set_context_menu_controller(this); |
117 | 117 |
118 // No UpdateState() here because View hierarchy not setup yet. Our parent | 118 // No UpdateState() here because View hierarchy not setup yet. Our parent |
119 // should call UpdateState() after creation. | 119 // should call UpdateState() after creation. |
120 | 120 |
121 content::NotificationSource notification_source = | 121 content::NotificationSource notification_source = |
122 content::Source<Profile>(browser_->profile()->GetOriginalProfile()); | 122 content::Source<Profile>(browser_->profile()->GetOriginalProfile()); |
123 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 123 registrar_.Add(this, |
| 124 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
124 content::Source<ExtensionAction>(browser_action_)); | 125 content::Source<ExtensionAction>(browser_action_)); |
125 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 126 registrar_.Add(this, |
| 127 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
126 notification_source); | 128 notification_source); |
127 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 129 registrar_.Add(this, |
| 130 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
128 notification_source); | 131 notification_source); |
129 | 132 |
130 // We also listen for browser theme changes on linux because a switch from or | 133 // We also listen for browser theme changes on linux because a switch from or |
131 // to GTK requires that we regrab our browser action images. | 134 // to GTK requires that we regrab our browser action images. |
132 registrar_.Add( | 135 registrar_.Add( |
133 this, | 136 this, |
134 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 137 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
135 content::Source<ThemeService>( | 138 content::Source<ThemeService>( |
136 ThemeServiceFactory::GetForProfile(browser->profile()))); | 139 ThemeServiceFactory::GetForProfile(browser->profile()))); |
137 } | 140 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 271 |
269 GURL BrowserActionButton::GetPopupUrl() { | 272 GURL BrowserActionButton::GetPopupUrl() { |
270 int tab_id = delegate_->GetCurrentTabId(); | 273 int tab_id = delegate_->GetCurrentTabId(); |
271 return (tab_id < 0) ? GURL() : browser_action_->GetPopupUrl(tab_id); | 274 return (tab_id < 0) ? GURL() : browser_action_->GetPopupUrl(tab_id); |
272 } | 275 } |
273 | 276 |
274 void BrowserActionButton::Observe(int type, | 277 void BrowserActionButton::Observe(int type, |
275 const content::NotificationSource& source, | 278 const content::NotificationSource& source, |
276 const content::NotificationDetails& details) { | 279 const content::NotificationDetails& details) { |
277 switch (type) { | 280 switch (type) { |
278 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED: | 281 case extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED: |
279 UpdateState(); | 282 UpdateState(); |
280 // The browser action may have become visible/hidden so we need to make | 283 // The browser action may have become visible/hidden so we need to make |
281 // sure the state gets updated. | 284 // sure the state gets updated. |
282 delegate_->OnBrowserActionVisibilityChanged(); | 285 delegate_->OnBrowserActionVisibilityChanged(); |
283 break; | 286 break; |
284 case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: | 287 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED: |
285 case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { | 288 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { |
286 std::pair<const std::string, const std::string>* payload = | 289 std::pair<const std::string, const std::string>* payload = |
287 content::Details<std::pair<const std::string, const std::string> >( | 290 content::Details<std::pair<const std::string, const std::string> >( |
288 details).ptr(); | 291 details).ptr(); |
289 if (extension_->id() == payload->first && | 292 if (extension_->id() == payload->first && |
290 payload->second == | 293 payload->second == |
291 extensions::manifest_values::kBrowserActionCommandEvent) { | 294 extensions::manifest_values::kBrowserActionCommandEvent) { |
292 if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) | 295 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED) |
293 MaybeRegisterExtensionCommand(); | 296 MaybeRegisterExtensionCommand(); |
294 else | 297 else |
295 MaybeUnregisterExtensionCommand(true); | 298 MaybeUnregisterExtensionCommand(true); |
296 } | 299 } |
297 break; | 300 break; |
298 } | 301 } |
299 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | 302 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
300 UpdateState(); | 303 UpdateState(); |
301 break; | 304 break; |
302 default: | 305 default: |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 extensions::Command browser_action_command; | 452 extensions::Command browser_action_command; |
450 if (!only_if_active || !command_service->GetBrowserActionCommand( | 453 if (!only_if_active || !command_service->GetBrowserActionCommand( |
451 extension_->id(), | 454 extension_->id(), |
452 extensions::CommandService::ACTIVE_ONLY, | 455 extensions::CommandService::ACTIVE_ONLY, |
453 &browser_action_command, | 456 &browser_action_command, |
454 NULL)) { | 457 NULL)) { |
455 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 458 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
456 keybinding_.reset(NULL); | 459 keybinding_.reset(NULL); |
457 } | 460 } |
458 } | 461 } |
OLD | NEW |