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