| 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/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 registrar_.Add( | 187 registrar_.Add( |
| 188 this, | 188 this, |
| 189 extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC, | 189 extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC, |
| 190 content::Source<Profile>(browser->profile())); | 190 content::Source<Profile>(browser->profile())); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Overridden from content::NotificationObserver. | 193 // Overridden from content::NotificationObserver. |
| 194 virtual void Observe( | 194 virtual void Observe( |
| 195 int type, | 195 int type, |
| 196 const content::NotificationSource& source, | 196 const content::NotificationSource& source, |
| 197 const content::NotificationDetails& details) OVERRIDE { | 197 const content::NotificationDetails& details) override { |
| 198 switch (type) { | 198 switch (type) { |
| 199 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 199 case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
| 200 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 200 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
| 201 if (popup && ![popup isClosing]) | 201 if (popup && ![popup isClosing]) |
| 202 [popup close]; | 202 [popup close]; |
| 203 | 203 |
| 204 break; | 204 break; |
| 205 } | 205 } |
| 206 case extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC: { | 206 case extensions::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC: { |
| 207 std::pair<const std::string, gfx::NativeWindow>* payload = | 207 std::pair<const std::string, gfx::NativeWindow>* payload = |
| 208 content::Details<std::pair<const std::string, gfx::NativeWindow> >( | 208 content::Details<std::pair<const std::string, gfx::NativeWindow> >( |
| 209 details).ptr(); | 209 details).ptr(); |
| 210 std::string extension_id = payload->first; | 210 std::string extension_id = payload->first; |
| 211 gfx::NativeWindow window = payload->second; | 211 gfx::NativeWindow window = payload->second; |
| 212 if (window != browser_->window()->GetNativeWindow()) | 212 if (window != browser_->window()->GetNativeWindow()) |
| 213 break; | 213 break; |
| 214 [owner_ activateBrowserAction:extension_id]; | 214 [owner_ activateBrowserAction:extension_id]; |
| 215 break; | 215 break; |
| 216 } | 216 } |
| 217 default: | 217 default: |
| 218 NOTREACHED() << L"Unexpected notification"; | 218 NOTREACHED() << L"Unexpected notification"; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 // extensions::ExtensionToolbarModel::Observer implementation. | 222 // extensions::ExtensionToolbarModel::Observer implementation. |
| 223 virtual void ToolbarExtensionAdded( | 223 virtual void ToolbarExtensionAdded( |
| 224 const Extension* extension, | 224 const Extension* extension, |
| 225 int index) OVERRIDE { | 225 int index) override { |
| 226 [owner_ createActionButtonForExtension:extension withIndex:index]; | 226 [owner_ createActionButtonForExtension:extension withIndex:index]; |
| 227 [owner_ resizeContainerAndAnimate:NO]; | 227 [owner_ resizeContainerAndAnimate:NO]; |
| 228 } | 228 } |
| 229 | 229 |
| 230 virtual void ToolbarExtensionRemoved(const Extension* extension) OVERRIDE { | 230 virtual void ToolbarExtensionRemoved(const Extension* extension) override { |
| 231 [owner_ removeActionButtonForExtension:extension]; | 231 [owner_ removeActionButtonForExtension:extension]; |
| 232 [owner_ resizeContainerAndAnimate:NO]; | 232 [owner_ resizeContainerAndAnimate:NO]; |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual void ToolbarExtensionMoved(const Extension* extension, | 235 virtual void ToolbarExtensionMoved(const Extension* extension, |
| 236 int index) OVERRIDE { | 236 int index) override { |
| 237 } | 237 } |
| 238 | 238 |
| 239 virtual void ToolbarExtensionUpdated(const Extension* extension) OVERRIDE { | 239 virtual void ToolbarExtensionUpdated(const Extension* extension) override { |
| 240 BrowserActionButton* button = [owner_ buttonForExtension:extension]; | 240 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
| 241 if (button) | 241 if (button) |
| 242 [button updateState]; | 242 [button updateState]; |
| 243 } | 243 } |
| 244 | 244 |
| 245 virtual bool ShowExtensionActionPopup(const Extension* extension, | 245 virtual bool ShowExtensionActionPopup(const Extension* extension, |
| 246 bool grant_active_tab) OVERRIDE { | 246 bool grant_active_tab) override { |
| 247 // Do not override other popups and only show in active window. | 247 // Do not override other popups and only show in active window. |
| 248 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 248 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
| 249 if (popup || !browser_->window()->IsActive()) | 249 if (popup || !browser_->window()->IsActive()) |
| 250 return false; | 250 return false; |
| 251 | 251 |
| 252 BrowserActionButton* button = [owner_ buttonForExtension:extension]; | 252 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
| 253 return button && [owner_ browserActionClicked:button | 253 return button && [owner_ browserActionClicked:button |
| 254 shouldGrant:grant_active_tab]; | 254 shouldGrant:grant_active_tab]; |
| 255 } | 255 } |
| 256 | 256 |
| 257 virtual void ToolbarVisibleCountChanged() OVERRIDE { | 257 virtual void ToolbarVisibleCountChanged() override { |
| 258 } | 258 } |
| 259 | 259 |
| 260 virtual void ToolbarHighlightModeChanged(bool is_highlighting) OVERRIDE { | 260 virtual void ToolbarHighlightModeChanged(bool is_highlighting) override { |
| 261 } | 261 } |
| 262 | 262 |
| 263 virtual Browser* GetBrowser() OVERRIDE { | 263 virtual Browser* GetBrowser() override { |
| 264 return browser_; | 264 return browser_; |
| 265 } | 265 } |
| 266 | 266 |
| 267 private: | 267 private: |
| 268 // The object we need to inform when we get a notification. Weak. Owns us. | 268 // The object we need to inform when we get a notification. Weak. Owns us. |
| 269 BrowserActionsController* owner_; | 269 BrowserActionsController* owner_; |
| 270 | 270 |
| 271 // The browser we listen for events from. Weak. | 271 // The browser we listen for events from. Weak. |
| 272 Browser* browser_; | 272 Browser* browser_; |
| 273 | 273 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 const extensions::ExtensionList& toolbar_items = | 892 const extensions::ExtensionList& toolbar_items = |
| 893 toolbarModel_->toolbar_items(); | 893 toolbarModel_->toolbar_items(); |
| 894 if (index < toolbar_items.size()) { | 894 if (index < toolbar_items.size()) { |
| 895 const Extension* extension = toolbar_items[index].get(); | 895 const Extension* extension = toolbar_items[index].get(); |
| 896 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 896 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 897 } | 897 } |
| 898 return nil; | 898 return nil; |
| 899 } | 899 } |
| 900 | 900 |
| 901 @end | 901 @end |
| OLD | NEW |