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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service_new.cc

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
OLDNEW
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/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/api/commands/commands.h" 10 #include "chrome/browser/extensions/api/commands/commands.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool CommandService::AddKeybindingPref( 134 bool CommandService::AddKeybindingPref(
135 const ui::Accelerator& accelerator, 135 const ui::Accelerator& accelerator,
136 std::string extension_id, 136 std::string extension_id,
137 std::string command_name, 137 std::string command_name,
138 bool allow_overrides) { 138 bool allow_overrides) {
139 if (accelerator.key_code() == ui::VKEY_UNKNOWN) 139 if (accelerator.key_code() == ui::VKEY_UNKNOWN)
140 return false; 140 return false;
141 141
142 DictionaryPrefUpdate updater(profile_->GetPrefs(), 142 DictionaryPrefUpdate updater(profile_->GetPrefs(),
143 prefs::kExtensionCommands); 143 prefs::kExtensionCommands);
144 DictionaryValue* bindings = updater.Get(); 144 base::DictionaryValue* bindings = updater.Get();
145 145
146 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator); 146 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator);
147 147
148 if (!allow_overrides && bindings->HasKey(key)) 148 if (!allow_overrides && bindings->HasKey(key))
149 return false; // Already taken. 149 return false; // Already taken.
150 150
151 DictionaryValue* keybinding = new DictionaryValue(); 151 base::DictionaryValue* keybinding = new base::DictionaryValue();
152 keybinding->SetString(kExtension, extension_id); 152 keybinding->SetString(kExtension, extension_id);
153 keybinding->SetString(kCommandName, command_name); 153 keybinding->SetString(kCommandName, command_name);
154 154
155 bindings->Set(key, keybinding); 155 bindings->Set(key, keybinding);
156 156
157 std::pair<const std::string, const std::string> details = 157 std::pair<const std::string, const std::string> details =
158 std::make_pair(extension_id, command_name); 158 std::make_pair(extension_id, command_name);
159 content::NotificationService::current()->Notify( 159 content::NotificationService::current()->Notify(
160 chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, 160 chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED,
161 content::Source<Profile>(profile_), 161 content::Source<Profile>(profile_),
(...skipping 29 matching lines...) Expand all
191 // The extension command might be assigned another shortcut. Remove that 191 // The extension command might be assigned another shortcut. Remove that
192 // shortcut before proceeding. 192 // shortcut before proceeding.
193 RemoveKeybindingPrefs(extension_id, command_name); 193 RemoveKeybindingPrefs(extension_id, command_name);
194 194
195 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke); 195 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke);
196 AddKeybindingPref(accelerator, extension_id, command_name, true); 196 AddKeybindingPref(accelerator, extension_id, command_name, true);
197 } 197 }
198 198
199 ui::Accelerator CommandService::FindShortcutForCommand( 199 ui::Accelerator CommandService::FindShortcutForCommand(
200 const std::string& extension_id, const std::string& command) { 200 const std::string& extension_id, const std::string& command) {
201 const DictionaryValue* bindings = 201 const base::DictionaryValue* bindings =
202 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); 202 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands);
203 for (DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); it.Advance()) { 203 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd();
204 const DictionaryValue* item = NULL; 204 it.Advance()) {
205 const base::DictionaryValue* item = NULL;
205 it.value().GetAsDictionary(&item); 206 it.value().GetAsDictionary(&item);
206 207
207 std::string extension; 208 std::string extension;
208 item->GetString(kExtension, &extension); 209 item->GetString(kExtension, &extension);
209 if (extension != extension_id) 210 if (extension != extension_id)
210 continue; 211 continue;
211 std::string command_name; 212 std::string command_name;
212 item->GetString(kCommandName, &command_name); 213 item->GetString(kCommandName, &command_name);
213 if (command != command_name) 214 if (command != command_name)
214 continue; 215 continue;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 extension->id(), 263 extension->id(),
263 script_badge_command->command_name(), 264 script_badge_command->command_name(),
264 false); // Overwriting not allowed. 265 false); // Overwriting not allowed.
265 } 266 }
266 } 267 }
267 268
268 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, 269 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id,
269 const std::string& command_name) { 270 const std::string& command_name) {
270 DictionaryPrefUpdate updater(profile_->GetPrefs(), 271 DictionaryPrefUpdate updater(profile_->GetPrefs(),
271 prefs::kExtensionCommands); 272 prefs::kExtensionCommands);
272 DictionaryValue* bindings = updater.Get(); 273 base::DictionaryValue* bindings = updater.Get();
273 274
274 typedef std::vector<std::string> KeysToRemove; 275 typedef std::vector<std::string> KeysToRemove;
275 KeysToRemove keys_to_remove; 276 KeysToRemove keys_to_remove;
276 for (DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); it.Advance()) { 277 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd();
277 const DictionaryValue* item = NULL; 278 it.Advance()) {
279 const base::DictionaryValue* item = NULL;
278 it.value().GetAsDictionary(&item); 280 it.value().GetAsDictionary(&item);
279 281
280 std::string extension; 282 std::string extension;
281 item->GetString(kExtension, &extension); 283 item->GetString(kExtension, &extension);
282 284
283 if (extension == extension_id) { 285 if (extension == extension_id) {
284 // If |command_name| is specified, delete only that command. Otherwise, 286 // If |command_name| is specified, delete only that command. Otherwise,
285 // delete all commands. 287 // delete all commands.
286 if (!command_name.empty()) { 288 if (!command_name.empty()) {
287 std::string command; 289 std::string command;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return false; 354 return false;
353 355
354 *command = *requested_command; 356 *command = *requested_command;
355 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 357 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
356 command->set_accelerator(shortcut_assigned); 358 command->set_accelerator(shortcut_assigned);
357 359
358 return true; 360 return true;
359 } 361 }
360 362
361 } // namespace extensions 363 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698