Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: chrome/browser/extensions/extension_command_service.h

Issue 10201016: Conflict detection for Extension Keybinding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressed comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_command_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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_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 to see if
41 // the keybinding is active. Returns NULL if the extension has no browser
42 // action or no active keybinding for it.
43 const Extension::ExtensionKeybinding* GetActiveBrowserActionCommand(
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 // Records a keybinding |accelerator| as active for an extension with id
67 // |extension_id| and command with the name |command_name|. If
68 // |allow_overrides| is false, the keybinding must be free for the change to
69 // be recorded (as determined by the master list in |user_prefs|). If
70 // |allow_overwrites| is true, any previously recorded keybinding for this
71 // |accelerator| will be overwritten. Returns true if the change was
72 // successfully recorded.
73 bool AddKeybindingPref(const ui::Accelerator& accelerator,
74 std::string extension_id,
75 std::string command_name,
76 bool allow_overrides);
77
78 // Overridden from content::NotificationObserver.
79 virtual void Observe(int type,
80 const content::NotificationSource& source,
81 const content::NotificationDetails& details) OVERRIDE;
82
83 private:
84 // Assigns initial keybinding for a given |extension|'s page action, browser
85 // action and named commands. In each case, if the suggested keybinding is
86 // free, it will be taken by this extension. If not, that keybinding request
87 // is ignored. |user_pref| is the PrefService used to record the new
88 // keybinding assignment.
89 void AssignInitialKeybindings(const Extension* extension);
90
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_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_command_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698