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 #include "chrome/browser/extensions/api/commands/command_service.h" | 5 #include "chrome/browser/extensions/api/commands/command_service.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 9 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 | 19 |
19 using extensions::Extension; | 20 using extensions::Extension; |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const char kExtension[] = "extension"; | 24 const char kExtension[] = "extension"; |
24 const char kCommandName[] = "command_name"; | 25 const char kCommandName[] = "command_name"; |
25 | 26 |
26 std::string GetPlatformKeybindingKeyForAccelerator( | 27 std::string GetPlatformKeybindingKeyForAccelerator( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator); | 114 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator); |
114 | 115 |
115 if (!allow_overrides && bindings->HasKey(key)) | 116 if (!allow_overrides && bindings->HasKey(key)) |
116 return false; // Already taken. | 117 return false; // Already taken. |
117 | 118 |
118 DictionaryValue* keybinding = new DictionaryValue(); | 119 DictionaryValue* keybinding = new DictionaryValue(); |
119 keybinding->SetString(kExtension, extension_id); | 120 keybinding->SetString(kExtension, extension_id); |
120 keybinding->SetString(kCommandName, command_name); | 121 keybinding->SetString(kCommandName, command_name); |
121 | 122 |
122 bindings->Set(key, keybinding); | 123 bindings->Set(key, keybinding); |
| 124 |
| 125 std::pair<const std::string, const std::string> details = |
| 126 std::make_pair(extension_id, command_name); |
| 127 content::NotificationService::current()->Notify( |
| 128 chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| 129 content::Source<Profile>(profile_), |
| 130 content::Details< |
| 131 std::pair<const std::string, const std::string> >(&details)); |
| 132 |
123 return true; | 133 return true; |
124 } | 134 } |
125 | 135 |
126 void CommandService::Observe( | 136 void CommandService::Observe( |
127 int type, | 137 int type, |
128 const content::NotificationSource& source, | 138 const content::NotificationSource& source, |
129 const content::NotificationDetails& details) { | 139 const content::NotificationDetails& details) { |
130 switch (type) { | 140 switch (type) { |
131 case chrome::NOTIFICATION_EXTENSION_INSTALLED: | 141 case chrome::NOTIFICATION_EXTENSION_INSTALLED: |
132 AssignInitialKeybindings( | 142 AssignInitialKeybindings( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (command_name != command) | 246 if (command_name != command) |
237 continue; | 247 continue; |
238 } | 248 } |
239 | 249 |
240 keys_to_remove.push_back(key); | 250 keys_to_remove.push_back(key); |
241 } | 251 } |
242 } | 252 } |
243 | 253 |
244 for (KeysToRemove::const_iterator it = keys_to_remove.begin(); | 254 for (KeysToRemove::const_iterator it = keys_to_remove.begin(); |
245 it != keys_to_remove.end(); ++it) { | 255 it != keys_to_remove.end(); ++it) { |
246 bindings->Remove(*it, NULL); | 256 std::string key = *it; |
| 257 bindings->Remove(key, NULL); |
| 258 |
| 259 std::pair<const std::string, const std::string> details = |
| 260 std::make_pair(extension_id, command_name); |
| 261 content::NotificationService::current()->Notify( |
| 262 chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| 263 content::Source<Profile>(profile_), |
| 264 content::Details< |
| 265 std::pair<const std::string, const std::string> >(&details)); |
247 } | 266 } |
248 } | 267 } |
249 | 268 |
250 bool CommandService::GetExtensionActionCommand(const std::string& extension_id, | 269 bool CommandService::GetExtensionActionCommand(const std::string& extension_id, |
251 QueryType type, | 270 QueryType type, |
252 extensions::Command* command, | 271 extensions::Command* command, |
253 bool* active, | 272 bool* active, |
254 bool browser_action) { | 273 bool browser_action) { |
255 const ExtensionSet* extensions = | 274 const ExtensionSet* extensions = |
256 ExtensionSystem::Get(profile_)->extension_service()->extensions(); | 275 ExtensionSystem::Get(profile_)->extension_service()->extensions(); |
(...skipping 19 matching lines...) Expand all Loading... |
276 return false; | 295 return false; |
277 | 296 |
278 *command = *requested_command; | 297 *command = *requested_command; |
279 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 298 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
280 command->set_accelerator(shortcut_assigned); | 299 command->set_accelerator(shortcut_assigned); |
281 | 300 |
282 return true; | 301 return true; |
283 } | 302 } |
284 | 303 |
285 } // namespace extensions | 304 } // namespace extensions |
OLD | NEW |