| 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 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "content/public/browser/notification_observer.h" | 9 #include "base/scoped_observer.h" |
| 10 #include "content/public/browser/notification_registrar.h" | |
| 11 #include "content/public/browser/web_ui_message_handler.h" | 10 #include "content/public/browser/web_ui_message_handler.h" |
| 11 #include "extensions/browser/extension_registry_observer.h" |
| 12 |
| 13 class Profile; |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 class DictionaryValue; | 16 class DictionaryValue; |
| 15 class ListValue; | 17 class ListValue; |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 class WebUIDataSource; | 21 class WebUIDataSource; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace extensions { | 24 namespace extensions { |
| 23 class Command; | 25 class Command; |
| 24 class CommandService; | 26 class CommandService; |
| 25 } | |
| 26 | |
| 27 class Extension; | 27 class Extension; |
| 28 class Profile; | 28 class ExtensionRegistry; |
| 29 | |
| 30 namespace extensions { | |
| 31 | 29 |
| 32 // The handler page for the Extension Commands UI overlay. | 30 // The handler page for the Extension Commands UI overlay. |
| 33 class CommandHandler : public content::WebUIMessageHandler, | 31 class CommandHandler : public content::WebUIMessageHandler, |
| 34 public content::NotificationObserver { | 32 public ExtensionRegistryObserver { |
| 35 public: | 33 public: |
| 36 explicit CommandHandler(Profile* profile); | 34 explicit CommandHandler(Profile* profile); |
| 37 virtual ~CommandHandler(); | 35 virtual ~CommandHandler(); |
| 38 | 36 |
| 39 // Fetches the localized values for the page and deposits them into |source|. | 37 // Fetches the localized values for the page and deposits them into |source|. |
| 40 void GetLocalizedValues(content::WebUIDataSource* source); | 38 void GetLocalizedValues(content::WebUIDataSource* source); |
| 41 | 39 |
| 42 // WebUIMessageHandler implementation. | 40 // WebUIMessageHandler implementation. |
| 43 virtual void RegisterMessages() OVERRIDE; | 41 virtual void RegisterMessages() OVERRIDE; |
| 44 | 42 |
| 45 // NotificationObserver implementation. | 43 private: |
| 46 virtual void Observe(int type, | 44 // ExtensionRegistryObserver implementation. |
| 47 const content::NotificationSource& source, | 45 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 48 const content::NotificationDetails& details) OVERRIDE; | 46 const Extension* extension) OVERRIDE; |
| 47 virtual void OnExtensionUnloaded( |
| 48 content::BrowserContext* browser_context, |
| 49 const Extension* extension, |
| 50 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 49 | 51 |
| 50 private: | |
| 51 // Update the list of extension commands in the config UI. | 52 // Update the list of extension commands in the config UI. |
| 52 void UpdateCommandDataOnPage(); | 53 void UpdateCommandDataOnPage(); |
| 53 | 54 |
| 54 // Handles requests from javascript to fetch the extensions data, including | 55 // Handles requests from javascript to fetch the extensions data, including |
| 55 // the commands it contains. | 56 // the commands it contains. |
| 56 // Replies back through: ExtensionCommandsOverlay.returnExtensionsData. | 57 // Replies back through: ExtensionCommandsOverlay.returnExtensionsData. |
| 57 void HandleRequestExtensionsData(const base::ListValue* args); | 58 void HandleRequestExtensionsData(const base::ListValue* args); |
| 58 | 59 |
| 59 // Handles requests from javascript to set a particular keyboard shortcut | 60 // Handles requests from javascript to set a particular keyboard shortcut |
| 60 // for a given extension command. | 61 // for a given extension command. |
| 61 void HandleSetExtensionCommandShortcut(const base::ListValue* args); | 62 void HandleSetExtensionCommandShortcut(const base::ListValue* args); |
| 62 | 63 |
| 63 // Handles requests from javascript to change the scope of a particular | 64 // Handles requests from javascript to change the scope of a particular |
| 64 // keyboard shortcut for a given extension command. | 65 // keyboard shortcut for a given extension command. |
| 65 void HandleSetCommandScope(const base::ListValue* args); | 66 void HandleSetCommandScope(const base::ListValue* args); |
| 66 | 67 |
| 67 // Handles requests from javascript to temporarily disable general Chrome | 68 // Handles requests from javascript to temporarily disable general Chrome |
| 68 // shortcut handling while the web page is capturing which shortcut to use. | 69 // shortcut handling while the web page is capturing which shortcut to use. |
| 69 void HandleSetShortcutHandlingSuspended(const base::ListValue* args); | 70 void HandleSetShortcutHandlingSuspended(const base::ListValue* args); |
| 70 | 71 |
| 71 // Fetches all known commands, active and inactive and returns them through | 72 // Fetches all known commands, active and inactive and returns them through |
| 72 // |commands|. | 73 // |commands|. |
| 73 void GetAllCommands(base::DictionaryValue* commands); | 74 void GetAllCommands(base::DictionaryValue* commands); |
| 74 | 75 |
| 75 content::NotificationRegistrar registrar_; | 76 Profile* profile_; |
| 76 | 77 |
| 77 Profile* profile_; | 78 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 79 extension_registry_observer_; |
| 78 | 80 |
| 79 DISALLOW_COPY_AND_ASSIGN(CommandHandler); | 81 DISALLOW_COPY_AND_ASSIGN(CommandHandler); |
| 80 }; | 82 }; |
| 81 | 83 |
| 82 } // namespace extensions | 84 } // namespace extensions |
| 83 | 85 |
| 84 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ | 86 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_COMMAND_HANDLER_H_ |
| OLD | NEW |