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/automation/automation_provider_json.h" | 5 #include "chrome/browser/automation/automation_provider_json.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
11 #include "chrome/browser/automation/automation_provider.h" | 11 #include "chrome/browser/automation/automation_provider.h" |
12 #include "chrome/browser/automation/automation_util.h" | 12 #include "chrome/browser/automation/automation_util.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/automation_id.h" | 15 #include "chrome/common/automation_id.h" |
16 #include "chrome/common/automation_messages.h" | 16 #include "chrome/common/automation_messages.h" |
| 17 #include "chrome/common/extensions/extension.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 | 19 |
19 using automation::Error; | 20 using automation::Error; |
20 using automation::ErrorCode; | 21 using automation::ErrorCode; |
21 using content::WebContents; | 22 using content::WebContents; |
22 | 23 |
23 AutomationJSONReply::AutomationJSONReply(AutomationProvider* provider, | 24 AutomationJSONReply::AutomationJSONReply(AutomationProvider* provider, |
24 IPC::Message* reply_message) | 25 IPC::Message* reply_message) |
25 : provider_(provider), | 26 : provider_(provider), |
26 message_(reply_message) { | 27 message_(reply_message) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return true; | 175 return true; |
175 } | 176 } |
176 | 177 |
177 namespace { | 178 namespace { |
178 | 179 |
179 bool GetExtensionFromJSONArgsHelper( | 180 bool GetExtensionFromJSONArgsHelper( |
180 base::DictionaryValue* args, | 181 base::DictionaryValue* args, |
181 const std::string& key, | 182 const std::string& key, |
182 Profile* profile, | 183 Profile* profile, |
183 bool include_disabled, | 184 bool include_disabled, |
184 const Extension** extension, | 185 const extensions::Extension** extension, |
185 std::string* error) { | 186 std::string* error) { |
186 std::string id; | 187 std::string id; |
187 if (!args->GetString(key, &id)) { | 188 if (!args->GetString(key, &id)) { |
188 *error = base::StringPrintf("Missing or invalid key: %s", key.c_str()); | 189 *error = base::StringPrintf("Missing or invalid key: %s", key.c_str()); |
189 return false; | 190 return false; |
190 } | 191 } |
191 ExtensionService* service = profile->GetExtensionService(); | 192 ExtensionService* service = profile->GetExtensionService(); |
192 if (!service) { | 193 if (!service) { |
193 *error = "No extensions service."; | 194 *error = "No extensions service."; |
194 return false; | 195 return false; |
195 } | 196 } |
196 if (!service->GetInstalledExtension(id)) { | 197 if (!service->GetInstalledExtension(id)) { |
197 // The extension ID does not correspond to any extension, whether crashed | 198 // The extension ID does not correspond to any extension, whether crashed |
198 // or not. | 199 // or not. |
199 *error = base::StringPrintf("Extension %s is not installed.", | 200 *error = base::StringPrintf("Extension %s is not installed.", |
200 id.c_str()); | 201 id.c_str()); |
201 return false; | 202 return false; |
202 } | 203 } |
203 const Extension* installed_extension = | 204 const extensions::Extension* installed_extension = |
204 service->GetExtensionById(id, include_disabled); | 205 service->GetExtensionById(id, include_disabled); |
205 if (!installed_extension) { | 206 if (!installed_extension) { |
206 *error = "Extension is disabled or has crashed."; | 207 *error = "Extension is disabled or has crashed."; |
207 return false; | 208 return false; |
208 } | 209 } |
209 *extension = installed_extension; | 210 *extension = installed_extension; |
210 return true; | 211 return true; |
211 } | 212 } |
212 | 213 |
213 } // namespace | 214 } // namespace |
214 | 215 |
215 bool GetExtensionFromJSONArgs( | 216 bool GetExtensionFromJSONArgs( |
216 base::DictionaryValue* args, | 217 base::DictionaryValue* args, |
217 const std::string& key, | 218 const std::string& key, |
218 Profile* profile, | 219 Profile* profile, |
219 const Extension** extension, | 220 const extensions::Extension** extension, |
220 std::string* error) { | 221 std::string* error) { |
221 return GetExtensionFromJSONArgsHelper( | 222 return GetExtensionFromJSONArgsHelper( |
222 args, key, profile, true /* include_disabled */, extension, error); | 223 args, key, profile, true /* include_disabled */, extension, error); |
223 } | 224 } |
224 | 225 |
225 bool GetEnabledExtensionFromJSONArgs( | 226 bool GetEnabledExtensionFromJSONArgs( |
226 base::DictionaryValue* args, | 227 base::DictionaryValue* args, |
227 const std::string& key, | 228 const std::string& key, |
228 Profile* profile, | 229 Profile* profile, |
229 const Extension** extension, | 230 const extensions::Extension** extension, |
230 std::string* error) { | 231 std::string* error) { |
231 return GetExtensionFromJSONArgsHelper( | 232 return GetExtensionFromJSONArgsHelper( |
232 args, key, profile, false /* include_disabled */, extension, error); | 233 args, key, profile, false /* include_disabled */, extension, error); |
233 } | 234 } |
OLD | NEW |