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

Side by Side Diff: chrome/common/extensions/api/input_ime/input_components_handler.cc

Issue 11611004: Move the InputComponents out of extensions entirely. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 12 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
(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 #include "chrome/common/extensions/api/input_ime/input_components_handler.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_manifest_constants.h"
14 #include "extensions/common/error_utils.h"
15
16 namespace extensions {
17
18 InputComponentInfo::InputComponentInfo()
19 : type(INPUT_COMPONENT_TYPE_NONE),
20 shortcut_alt(false),
21 shortcut_ctrl(false),
22 shortcut_shift(false) {
23 }
24
25 InputComponentInfo::~InputComponentInfo() {}
26
27 // static
28 const InputComponents* InputComponents::GetInputComponents(
29 const Extension* extension) {
30 InputComponents* info = static_cast<InputComponents*>(
31 extension->GetManifestData(extension_manifest_keys::kInputComponents));
32 return info;
33 }
34
35 InputComponentsHandler::InputComponentsHandler() {
36 }
37
38 InputComponentsHandler::~InputComponentsHandler() {
39 }
40
41 bool InputComponentsHandler::Parse(const base::Value* value,
42 Extension* extension,
Yoyo Zhou 2012/12/28 21:04:28 fix indent
SanjoyPal 2012/12/28 22:38:30 Done.
43 string16* error) {
44 scoped_ptr<InputComponents> info(new InputComponents);
45 const ListValue* list_value = NULL;
46 if (!value->GetAsList(&list_value)) {
47 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidInputComponents);
48 return false;
49 }
50 for (size_t i = 0; i < list_value->GetSize(); ++i) {
51 const DictionaryValue* module_value = NULL;
52 std::string name_str;
53 InputComponentType type;
54 std::string id_str;
55 std::string description_str;
56 std::string language_str;
57 std::set<std::string> layouts;
58 std::string shortcut_keycode_str;
59 bool shortcut_alt = false;
60 bool shortcut_ctrl = false;
61 bool shortcut_shift = false;
62
63 if (!list_value->GetDictionary(i, &module_value)) {
64 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidInputComponents);
65 return false;
66 }
67
68 // Get input_components[i].name.
69 if (!module_value->GetString(extension_manifest_keys::kName, &name_str)) {
70 *error = ErrorUtils::FormatErrorMessageUTF16(
71 extension_manifest_errors::kInvalidInputComponentName,
72 base::IntToString(i));
73 return false;
74 }
75
76 // Get input_components[i].type.
77 std::string type_str;
78 if (module_value->GetString(extension_manifest_keys::kType, &type_str)) {
79 if (type_str == "ime") {
80 type = INPUT_COMPONENT_TYPE_IME;
81 } else {
82 *error = ErrorUtils::FormatErrorMessageUTF16(
83 extension_manifest_errors::kInvalidInputComponentType,
84 base::IntToString(i));
85 return false;
86 }
87 } else {
88 *error = ErrorUtils::FormatErrorMessageUTF16(
89 extension_manifest_errors::kInvalidInputComponentType,
90 base::IntToString(i));
91 return false;
92 }
93
94 // Get input_components[i].id.
95 if (!module_value->GetString(extension_manifest_keys::kId, &id_str)) {
96 id_str = "";
97 }
98
99 // Get input_components[i].description.
100 if (!module_value->GetString(extension_manifest_keys::kDescription,
101 &description_str)) {
102 *error = ErrorUtils::FormatErrorMessageUTF16(
103 extension_manifest_errors::kInvalidInputComponentDescription,
104 base::IntToString(i));
105 return false;
106 }
107 // Get input_components[i].language.
108 if (!module_value->GetString(extension_manifest_keys::kLanguage,
109 &language_str)) {
110 language_str = "";
111 }
112
113 // Get input_components[i].layouts.
114 const ListValue* layouts_value = NULL;
115 if (!module_value->GetList(extension_manifest_keys::kLayouts,
116 &layouts_value)) {
117 *error = ASCIIToUTF16(
118 extension_manifest_errors::kInvalidInputComponentLayouts);
119 return false;
120 }
121
122 for (size_t j = 0; j < layouts_value->GetSize(); ++j) {
123 std::string layout_name_str;
124 if (!layouts_value->GetString(j, &layout_name_str)) {
125 *error = ErrorUtils::FormatErrorMessageUTF16(
126 extension_manifest_errors::kInvalidInputComponentLayoutName,
127 base::IntToString(i), base::IntToString(j));
128 return false;
129 }
130 layouts.insert(layout_name_str);
131 }
132
133 if (module_value->HasKey(extension_manifest_keys::kShortcutKey)) {
134 const DictionaryValue* shortcut_value = NULL;
135 if (!module_value->GetDictionary(extension_manifest_keys::kShortcutKey,
136 &shortcut_value)) {
137 *error = ErrorUtils::FormatErrorMessageUTF16(
138 extension_manifest_errors::kInvalidInputComponentShortcutKey,
139 base::IntToString(i));
140 return false;
141 }
142
143 // Get input_components[i].shortcut_keycode.
144 if (!shortcut_value->GetString(extension_manifest_keys::kKeycode,
145 &shortcut_keycode_str)) {
146 *error = ErrorUtils::FormatErrorMessageUTF16(
147 extension_manifest_errors::kInvalidInputComponentShortcutKeycode,
148 base::IntToString(i));
149 return false;
150 }
151
152 // Get input_components[i].shortcut_alt.
153 if (!shortcut_value->GetBoolean(extension_manifest_keys::kAltKey,
154 &shortcut_alt)) {
155 shortcut_alt = false;
156 }
157
158 // Get input_components[i].shortcut_ctrl.
159 if (!shortcut_value->GetBoolean(extension_manifest_keys::kCtrlKey,
160 &shortcut_ctrl)) {
161 shortcut_ctrl = false;
162 }
163
164 // Get input_components[i].shortcut_shift.
165 if (!shortcut_value->GetBoolean(extension_manifest_keys::kShiftKey,
166 &shortcut_shift)) {
167 shortcut_shift = false;
168 }
169 }
170
171 info->input_components.push_back(InputComponentInfo());
172 info->input_components.back().name = name_str;
173 info->input_components.back().type = type;
174 info->input_components.back().id = id_str;
175 info->input_components.back().description = description_str;
176 info->input_components.back().language = language_str;
177 info->input_components.back().layouts.insert(layouts.begin(),
178 layouts.end());
179 info->input_components.back().shortcut_keycode = shortcut_keycode_str;
180 info->input_components.back().shortcut_alt = shortcut_alt;
181 info->input_components.back().shortcut_ctrl = shortcut_ctrl;
182 info->input_components.back().shortcut_shift = shortcut_shift;
183 }
184 extension->SetManifestData(extension_manifest_keys::kInputComponents,
185 info.release());
186 return true;
187 }
188
189 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698