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

Side by Side Diff: chrome/common/extensions/api/commands/commands_handler.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/common/extensions/api/commands/commands_handler.h" 5 #include "chrome/common/extensions/api/commands/commands_handler.h"
6 6
7 #include <memory>
8
7 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 11 #include "base/values.h"
10 #include "chrome/common/extensions/command.h" 12 #include "chrome/common/extensions/command.h"
11 #include "extensions/common/error_utils.h" 13 #include "extensions/common/error_utils.h"
12 #include "extensions/common/manifest_constants.h" 14 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/manifest_handlers/permissions_parser.h" 15 #include "extensions/common/manifest_handlers/permissions_parser.h"
14 16
15 namespace extensions { 17 namespace extensions {
16 18
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 53 }
52 54
53 CommandsHandler::CommandsHandler() { 55 CommandsHandler::CommandsHandler() {
54 } 56 }
55 57
56 CommandsHandler::~CommandsHandler() { 58 CommandsHandler::~CommandsHandler() {
57 } 59 }
58 60
59 bool CommandsHandler::Parse(Extension* extension, base::string16* error) { 61 bool CommandsHandler::Parse(Extension* extension, base::string16* error) {
60 if (!extension->manifest()->HasKey(keys::kCommands)) { 62 if (!extension->manifest()->HasKey(keys::kCommands)) {
61 scoped_ptr<CommandsInfo> commands_info(new CommandsInfo); 63 std::unique_ptr<CommandsInfo> commands_info(new CommandsInfo);
62 MaybeSetBrowserActionDefault(extension, commands_info.get()); 64 MaybeSetBrowserActionDefault(extension, commands_info.get());
63 extension->SetManifestData(keys::kCommands, 65 extension->SetManifestData(keys::kCommands,
64 commands_info.release()); 66 commands_info.release());
65 return true; 67 return true;
66 } 68 }
67 69
68 const base::DictionaryValue* dict = NULL; 70 const base::DictionaryValue* dict = NULL;
69 if (!extension->manifest()->GetDictionary(keys::kCommands, &dict)) { 71 if (!extension->manifest()->GetDictionary(keys::kCommands, &dict)) {
70 *error = base::ASCIIToUTF16(manifest_errors::kInvalidCommandsKey); 72 *error = base::ASCIIToUTF16(manifest_errors::kInvalidCommandsKey);
71 return false; 73 return false;
72 } 74 }
73 75
74 scoped_ptr<CommandsInfo> commands_info(new CommandsInfo); 76 std::unique_ptr<CommandsInfo> commands_info(new CommandsInfo);
75 77
76 int command_index = 0; 78 int command_index = 0;
77 int keybindings_found = 0; 79 int keybindings_found = 0;
78 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd(); 80 for (base::DictionaryValue::Iterator iter(*dict); !iter.IsAtEnd();
79 iter.Advance()) { 81 iter.Advance()) {
80 ++command_index; 82 ++command_index;
81 83
82 const base::DictionaryValue* command = NULL; 84 const base::DictionaryValue* command = NULL;
83 if (!iter.value().GetAsDictionary(&command)) { 85 if (!iter.value().GetAsDictionary(&command)) {
84 *error = ErrorUtils::FormatErrorMessageUTF16( 86 *error = ErrorUtils::FormatErrorMessageUTF16(
85 manifest_errors::kInvalidKeyBindingDictionary, 87 manifest_errors::kInvalidKeyBindingDictionary,
86 base::IntToString(command_index)); 88 base::IntToString(command_index));
87 return false; 89 return false;
88 } 90 }
89 91
90 scoped_ptr<extensions::Command> binding(new Command()); 92 std::unique_ptr<extensions::Command> binding(new Command());
91 if (!binding->Parse(command, iter.key(), command_index, error)) 93 if (!binding->Parse(command, iter.key(), command_index, error))
92 return false; // |error| already set. 94 return false; // |error| already set.
93 95
94 if (binding->accelerator().key_code() != ui::VKEY_UNKNOWN) { 96 if (binding->accelerator().key_code() != ui::VKEY_UNKNOWN) {
95 // Only media keys are allowed to work without modifiers, and because 97 // Only media keys are allowed to work without modifiers, and because
96 // media keys aren't registered exclusively they should not count towards 98 // media keys aren't registered exclusively they should not count towards
97 // the max of four shortcuts per extension. 99 // the max of four shortcuts per extension.
98 if (!Command::IsMediaKey(binding->accelerator())) 100 if (!Command::IsMediaKey(binding->accelerator()))
99 ++keybindings_found; 101 ++keybindings_found;
100 102
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 std::string(), 145 std::string(),
144 false)); 146 false));
145 } 147 }
146 } 148 }
147 149
148 const std::vector<std::string> CommandsHandler::Keys() const { 150 const std::vector<std::string> CommandsHandler::Keys() const {
149 return SingleKey(keys::kCommands); 151 return SingleKey(keys::kCommands);
150 } 152 }
151 153
152 } // namespace extensions 154 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698