Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
Aaron Boodman
2012/04/30 17:48:12
Can we move all the command-related files into bro
Finnur
2012/05/02 13:50:45
Absolutely. Mind if I do that in a followup change
| |
| 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_EXTENSIONS_EXTENSION_COMMAND_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMAND_SERVICE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 #include "content/public/browser/notification_details.h" | |
| 15 #include "content/public/browser/notification_observer.h" | |
| 16 #include "content/public/browser/notification_registrar.h" | |
| 17 #include "content/public/browser/notification_source.h" | |
| 18 | |
| 19 class PrefService; | |
| 20 class Profile; | |
| 21 | |
| 22 namespace ui { | |
| 23 class Accelerator; | |
| 24 } | |
| 25 | |
| 26 // This service keeps track of preferences related to extension commands | |
| 27 // (assigning initial keybindings on install and removing them on deletion | |
| 28 // and answers questions related to which commands are active. | |
| 29 class ExtensionCommandService : public ProfileKeyedService, | |
| 30 public content::NotificationObserver { | |
| 31 public: | |
| 32 // Register prefs for keybinding. | |
| 33 static void RegisterUserPrefs(PrefService* user_prefs); | |
| 34 | |
| 35 // Constructs an ExtensionCommandService object for the given profile. | |
| 36 explicit ExtensionCommandService(Profile* profile); | |
| 37 virtual ~ExtensionCommandService(); | |
| 38 | |
| 39 // Gets the active keybinding (if any) for the browser action of an extension | |
| 40 // given its |extension_id|. The function consults the master list (in the | |
| 41 // |profile|) to see if the keybinding is active. Returns NULL if the | |
|
Yoyo Zhou
2012/05/01 01:51:30
Nit: change |profile| to either profile or |profil
| |
| 42 // extension has no browser action or no active keybinding for it. | |
| 43 const Extension::ExtensionKeybinding* GetActiveBrowserActionCommand( | |
|
Aaron Boodman
2012/04/30 17:48:12
Nice idea moving this stuff into the PKS.
| |
| 44 const std::string& extension_id); | |
| 45 | |
| 46 // Gets the active keybinding (if any) for the page action of an extension | |
| 47 // given its |extension_id|. The function consults the master list to see if | |
| 48 // the keybinding is active. Returns NULL if the extension has no page action | |
| 49 // or no active keybinding for it. | |
| 50 const Extension::ExtensionKeybinding* GetActivePageActionCommand( | |
| 51 const std::string& extension_id); | |
| 52 | |
| 53 // Gets the active keybinding (if any) for the named commands of an extension | |
| 54 // given its |extension_id|. The function consults the master list to see if | |
| 55 // the keybinding is active. Returns an empty map if the extension has no | |
| 56 // named commands or no active keybinding for the commands. | |
| 57 Extension::CommandMap GetActiveNamedCommands(const std::string& extension_id); | |
| 58 | |
| 59 // Checks to see if a keybinding |accelerator| for a given |command_name| in | |
| 60 // an extension with id |extension_id| is registered as active (by consulting | |
| 61 // the master list in |user_prefs|). | |
| 62 bool IsKeybindingActive(const ui::Accelerator& accelerator, | |
| 63 std::string extension_id, | |
| 64 std::string command_name); | |
| 65 | |
| 66 // Assigns initial keybinding for a given |extension|'s page action, browser | |
| 67 // action and named commands. In each case, if the suggested keybinding is | |
| 68 // free, it will be taken by this extension. If not, that keybinding request | |
| 69 // is ignored. |user_pref| is the PrefService used to record the new | |
| 70 // keybinding assignment. | |
| 71 void AssignInitialKeybindings(const Extension* extension); | |
|
Yoyo Zhou
2012/05/01 01:51:30
Does this function need to be public?
Finnur
2012/05/02 13:50:45
Nope, not any more. Good catch.
On 2012/05/01 01:
| |
| 72 | |
| 73 // Records a keybinding |accelerator| as active for an extension with id | |
| 74 // |extension_id| and command with the name |command_name|. If | |
| 75 // |allow_overrides| is false, the keybinding must be free for the change to | |
| 76 // be recorded (as determined by the master list in |user_prefs|). If | |
| 77 // |allow_overwrites| is true, any previously recorded keybinding for this | |
| 78 // |accelerator| will be overwritten. Returns true if the change was | |
| 79 // successfully recorded. | |
| 80 bool AddKeybindingPref(const ui::Accelerator& accelerator, | |
| 81 std::string extension_id, | |
| 82 std::string command_name, | |
| 83 bool allow_overrides); | |
| 84 | |
| 85 // Overridden from content::NotificationObserver. | |
| 86 void Observe(int type, | |
| 87 const content::NotificationSource& source, | |
| 88 const content::NotificationDetails& details); | |
| 89 | |
| 90 private: | |
| 91 // Removes all keybindings for a given extension by its |extension_id|. | |
| 92 void RemoveKeybindingPrefs(std::string extension_id); | |
| 93 | |
| 94 // The content notification registrar for listening to extension events. | |
| 95 content::NotificationRegistrar registrar_; | |
| 96 | |
| 97 // A weak pointer to the profile we are associated with. Not owned by us. | |
| 98 Profile* profile_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandService); | |
| 101 }; | |
| 102 | |
| 103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMAND_SERVICE_H_ | |
| OLD | NEW |