OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_management_api.h" | 5 #include "chrome/browser/extensions/extension_management_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_utility_messages.h" | 25 #include "chrome/common/chrome_utility_messages.h" |
26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
28 #include "chrome/common/extensions/extension_error_utils.h" | 28 #include "chrome/common/extensions/extension_error_utils.h" |
29 #include "chrome/common/extensions/extension_icon_set.h" | 29 #include "chrome/common/extensions/extension_icon_set.h" |
30 #include "chrome/common/extensions/url_pattern.h" | 30 #include "chrome/common/extensions/url_pattern.h" |
31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/utility_process_host.h" |
| 34 #include "content/public/browser/utility_process_host_client.h" |
33 | 35 |
34 using base::IntToString; | 36 using base::IntToString; |
35 using content::BrowserThread; | 37 using content::BrowserThread; |
| 38 using content::UtilityProcessHost; |
| 39 using content::UtilityProcessHostClient; |
36 | 40 |
37 namespace events = extension_event_names; | 41 namespace events = extension_event_names; |
38 namespace keys = extension_management_api_constants; | 42 namespace keys = extension_management_api_constants; |
39 | 43 |
40 ExtensionService* ExtensionManagementFunction::service() { | 44 ExtensionService* ExtensionManagementFunction::service() { |
41 return profile()->GetExtensionService(); | 45 return profile()->GetExtensionService(); |
42 } | 46 } |
43 | 47 |
44 ExtensionService* AsyncExtensionManagementFunction::service() { | 48 ExtensionService* AsyncExtensionManagementFunction::service() { |
45 return profile()->GetExtensionService(); | 49 return profile()->GetExtensionService(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 i < warnings.end(); ++i) | 190 i < warnings.end(); ++i) |
187 result->Append(Value::CreateStringValue(i->message())); | 191 result->Append(Value::CreateStringValue(i->message())); |
188 result_.reset(result); | 192 result_.reset(result); |
189 return true; | 193 return true; |
190 } | 194 } |
191 | 195 |
192 namespace { | 196 namespace { |
193 | 197 |
194 // This class helps GetPermissionWarningsByManifestFunction manage | 198 // This class helps GetPermissionWarningsByManifestFunction manage |
195 // sending manifest JSON strings to the utility process for parsing. | 199 // sending manifest JSON strings to the utility process for parsing. |
196 class SafeManifestJSONParser : public UtilityProcessHost::Client { | 200 class SafeManifestJSONParser : public UtilityProcessHostClient { |
197 public: | 201 public: |
198 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, | 202 SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, |
199 const std::string& manifest) | 203 const std::string& manifest) |
200 : client_(client), | 204 : client_(client), |
201 manifest_(manifest), | 205 manifest_(manifest) {} |
202 utility_host_(NULL) {} | |
203 | 206 |
204 void Start() { | 207 void Start() { |
205 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
206 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
207 BrowserThread::IO, | 210 BrowserThread::IO, |
208 FROM_HERE, | 211 FROM_HERE, |
209 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this)); | 212 base::Bind(&SafeManifestJSONParser::StartWorkOnIOThread, this)); |
210 } | 213 } |
211 | 214 |
212 void StartWorkOnIOThread() { | 215 void StartWorkOnIOThread() { |
213 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 216 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
214 utility_host_ = new UtilityProcessHost(this, BrowserThread::IO); | 217 UtilityProcessHost* host = |
215 utility_host_->set_use_linux_zygote(true); | 218 UtilityProcessHost::Create(this, BrowserThread::IO); |
216 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); | 219 host->EnableZygote(); |
| 220 host->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); |
217 } | 221 } |
218 | 222 |
219 virtual bool OnMessageReceived(const IPC::Message& message) { | 223 virtual bool OnMessageReceived(const IPC::Message& message) { |
220 bool handled = true; | 224 bool handled = true; |
221 IPC_BEGIN_MESSAGE_MAP(SafeManifestJSONParser, message) | 225 IPC_BEGIN_MESSAGE_MAP(SafeManifestJSONParser, message) |
222 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, | 226 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, |
223 OnJSONParseSucceeded) | 227 OnJSONParseSucceeded) |
224 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, | 228 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, |
225 OnJSONParseFailed) | 229 OnJSONParseFailed) |
226 IPC_MESSAGE_UNHANDLED(handled = false) | 230 IPC_MESSAGE_UNHANDLED(handled = false) |
227 IPC_END_MESSAGE_MAP() | 231 IPC_END_MESSAGE_MAP() |
228 return handled; | 232 return handled; |
229 } | 233 } |
230 | 234 |
231 void OnJSONParseSucceeded(const ListValue& wrapper) { | 235 void OnJSONParseSucceeded(const ListValue& wrapper) { |
232 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
233 Value* value = NULL; | 237 Value* value = NULL; |
234 CHECK(wrapper.Get(0, &value)); | 238 CHECK(wrapper.Get(0, &value)); |
235 if (value->IsType(Value::TYPE_DICTIONARY)) | 239 if (value->IsType(Value::TYPE_DICTIONARY)) |
236 parsed_manifest_.reset(static_cast<DictionaryValue*>(value)->DeepCopy()); | 240 parsed_manifest_.reset(static_cast<DictionaryValue*>(value)->DeepCopy()); |
237 else | 241 else |
238 error_ = keys::kManifestParseError; | 242 error_ = keys::kManifestParseError; |
239 | 243 |
240 utility_host_ = NULL; // has already deleted itself | |
241 BrowserThread::PostTask( | 244 BrowserThread::PostTask( |
242 BrowserThread::UI, | 245 BrowserThread::UI, |
243 FROM_HERE, | 246 FROM_HERE, |
244 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this)); | 247 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this)); |
245 } | 248 } |
246 | 249 |
247 void OnJSONParseFailed(const std::string& error) { | 250 void OnJSONParseFailed(const std::string& error) { |
248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 251 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
249 error_ = error; | 252 error_ = error; |
250 utility_host_ = NULL; // has already deleted itself | |
251 BrowserThread::PostTask( | 253 BrowserThread::PostTask( |
252 BrowserThread::UI, | 254 BrowserThread::UI, |
253 FROM_HERE, | 255 FROM_HERE, |
254 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this)); | 256 base::Bind(&SafeManifestJSONParser::ReportResultFromUIThread, this)); |
255 } | 257 } |
256 | 258 |
257 void ReportResultFromUIThread() { | 259 void ReportResultFromUIThread() { |
258 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 if (error_.empty() && parsed_manifest_.get()) | 261 if (error_.empty() && parsed_manifest_.get()) |
260 client_->OnParseSuccess(parsed_manifest_.release()); | 262 client_->OnParseSuccess(parsed_manifest_.release()); |
261 else | 263 else |
262 client_->OnParseFailure(error_); | 264 client_->OnParseFailure(error_); |
263 } | 265 } |
264 | 266 |
265 private: | 267 private: |
266 ~SafeManifestJSONParser() {} | 268 ~SafeManifestJSONParser() {} |
267 | 269 |
268 // The client who we'll report results back to. | 270 // The client who we'll report results back to. |
269 GetPermissionWarningsByManifestFunction* client_; | 271 GetPermissionWarningsByManifestFunction* client_; |
270 | 272 |
271 // Data to parse. | 273 // Data to parse. |
272 std::string manifest_; | 274 std::string manifest_; |
273 | 275 |
274 // Results of parsing. | 276 // Results of parsing. |
275 scoped_ptr<DictionaryValue> parsed_manifest_; | 277 scoped_ptr<DictionaryValue> parsed_manifest_; |
276 | 278 |
277 std::string error_; | 279 std::string error_; |
278 UtilityProcessHost* utility_host_; | |
279 }; | 280 }; |
280 | 281 |
281 } // namespace | 282 } // namespace |
282 | 283 |
283 bool GetPermissionWarningsByManifestFunction::RunImpl() { | 284 bool GetPermissionWarningsByManifestFunction::RunImpl() { |
284 std::string manifest_str; | 285 std::string manifest_str; |
285 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &manifest_str)); | 286 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &manifest_str)); |
286 | 287 |
287 scoped_refptr<SafeManifestJSONParser> parser = | 288 scoped_refptr<SafeManifestJSONParser> parser = |
288 new SafeManifestJSONParser(this, manifest_str); | 289 new SafeManifestJSONParser(this, manifest_str); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 bool escalated = prefs ->DidExtensionEscalatePermissions(extension->id()); | 510 bool escalated = prefs ->DidExtensionEscalatePermissions(extension->id()); |
510 args.Append(CreateExtensionInfo(*extension, enabled, escalated)); | 511 args.Append(CreateExtensionInfo(*extension, enabled, escalated)); |
511 } | 512 } |
512 | 513 |
513 std::string args_json; | 514 std::string args_json; |
514 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 515 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
515 | 516 |
516 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 517 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
517 event_name, args_json, NULL, GURL()); | 518 event_name, args_json, NULL, GURL()); |
518 } | 519 } |
OLD | NEW |