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

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

Powered by Google App Engine
This is Rietveld 408576698