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_permissions_api.h" | 5 #include "chrome/browser/extensions/extension_permissions_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_event_router.h" | 9 #include "chrome/browser/extensions/extension_event_router.h" |
10 #include "chrome/browser/extensions/extension_permissions_api_constants.h" | 10 #include "chrome/browser/extensions/extension_permissions_api_constants.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; | 33 AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; |
34 | 34 |
35 DictionaryValue* PackPermissionsToValue(const ExtensionPermissionSet* set) { | 35 DictionaryValue* PackPermissionsToValue(const ExtensionPermissionSet* set) { |
36 DictionaryValue* value = new DictionaryValue(); | 36 DictionaryValue* value = new DictionaryValue(); |
37 | 37 |
38 // Generate the list of API permissions. | 38 // Generate the list of API permissions. |
39 ListValue* apis = new ListValue(); | 39 ListValue* apis = new ListValue(); |
40 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | 40 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); |
41 for (ExtensionAPIPermissionSet::const_iterator i = set->apis().begin(); | 41 for (ExtensionAPIPermissionSet::const_iterator i = set->apis().begin(); |
42 i != set->apis().end(); ++i) | 42 i != set->apis().end(); ++i) |
43 apis->Append(Value::CreateStringValue(info->GetByID(*i)->name())); | 43 apis->Append(base::StringValue::New(info->GetByID(*i)->name())); |
44 | 44 |
45 // Generate the list of origin permissions. | 45 // Generate the list of origin permissions. |
46 URLPatternSet hosts = set->explicit_hosts(); | 46 URLPatternSet hosts = set->explicit_hosts(); |
47 ListValue* origins = new ListValue(); | 47 ListValue* origins = new ListValue(); |
48 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) | 48 for (URLPatternSet::const_iterator i = hosts.begin(); i != hosts.end(); ++i) |
49 origins->Append(Value::CreateStringValue(i->GetAsString())); | 49 origins->Append(base::StringValue::New(i->GetAsString())); |
50 | 50 |
51 value->Set(keys::kApisKey, apis); | 51 value->Set(keys::kApisKey, apis); |
52 value->Set(keys::kOriginsKey, origins); | 52 value->Set(keys::kOriginsKey, origins); |
53 return value; | 53 return value; |
54 } | 54 } |
55 | 55 |
56 // Creates a new ExtensionPermissionSet from its |value| and passes ownership to | 56 // Creates a new ExtensionPermissionSet from its |value| and passes ownership to |
57 // the caller through |ptr|. Sets |bad_message| to true if the message is badly | 57 // the caller through |ptr|. Sets |bad_message| to true if the message is badly |
58 // formed. Returns false if the method fails to unpack a permission set. | 58 // formed. Returns false if the method fails to unpack a permission set. |
59 bool UnpackPermissionsFromValue(DictionaryValue* value, | 59 bool UnpackPermissionsFromValue(DictionaryValue* value, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 224 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
225 std::string error; | 225 std::string error; |
226 if (!args) | 226 if (!args) |
227 return false; | 227 return false; |
228 | 228 |
229 scoped_refptr<ExtensionPermissionSet> permissions; | 229 scoped_refptr<ExtensionPermissionSet> permissions; |
230 if (!UnpackPermissionsFromValue(args, &permissions, &bad_message_, &error_)) | 230 if (!UnpackPermissionsFromValue(args, &permissions, &bad_message_, &error_)) |
231 return false; | 231 return false; |
232 CHECK(permissions.get()); | 232 CHECK(permissions.get()); |
233 | 233 |
234 result_.reset(Value::CreateBooleanValue( | 234 result_.reset(base::BooleanValue::New( |
235 GetExtension()->GetActivePermissions()->Contains(*permissions))); | 235 GetExtension()->GetActivePermissions()->Contains(*permissions))); |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 bool GetAllPermissionsFunction::RunImpl() { | 239 bool GetAllPermissionsFunction::RunImpl() { |
240 result_.reset(PackPermissionsToValue( | 240 result_.reset(PackPermissionsToValue( |
241 GetExtension()->GetActivePermissions())); | 241 GetExtension()->GetActivePermissions())); |
242 return true; | 242 return true; |
243 } | 243 } |
244 | 244 |
(...skipping 24 matching lines...) Expand all Loading... |
269 return false; | 269 return false; |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 // Make sure we don't remove any required pemissions. | 273 // Make sure we don't remove any required pemissions. |
274 const ExtensionPermissionSet* required = extension->required_permission_set(); | 274 const ExtensionPermissionSet* required = extension->required_permission_set(); |
275 scoped_refptr<ExtensionPermissionSet> intersection( | 275 scoped_refptr<ExtensionPermissionSet> intersection( |
276 ExtensionPermissionSet::CreateIntersection(permissions.get(), required)); | 276 ExtensionPermissionSet::CreateIntersection(permissions.get(), required)); |
277 if (!intersection->IsEmpty()) { | 277 if (!intersection->IsEmpty()) { |
278 error_ = keys::kCantRemoveRequiredPermissionsError; | 278 error_ = keys::kCantRemoveRequiredPermissionsError; |
279 result_.reset(Value::CreateBooleanValue(false)); | 279 result_.reset(base::FalseValue()); |
280 return false; | 280 return false; |
281 } | 281 } |
282 | 282 |
283 perms_manager->RemovePermissions(extension, permissions.get()); | 283 perms_manager->RemovePermissions(extension, permissions.get()); |
284 result_.reset(Value::CreateBooleanValue(true)); | 284 result_.reset(base::TrueValue()); |
285 return true; | 285 return true; |
286 } | 286 } |
287 | 287 |
288 // static | 288 // static |
289 void RequestPermissionsFunction::SetAutoConfirmForTests(bool should_proceed) { | 289 void RequestPermissionsFunction::SetAutoConfirmForTests(bool should_proceed) { |
290 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; | 290 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; |
291 } | 291 } |
292 | 292 |
293 RequestPermissionsFunction::RequestPermissionsFunction() {} | 293 RequestPermissionsFunction::RequestPermissionsFunction() {} |
294 RequestPermissionsFunction::~RequestPermissionsFunction() {} | 294 RequestPermissionsFunction::~RequestPermissionsFunction() {} |
(...skipping 24 matching lines...) Expand all Loading... |
319 error_ = ExtensionErrorUtils::FormatErrorMessage( | 319 error_ = ExtensionErrorUtils::FormatErrorMessage( |
320 keys::kNotWhitelistedError, api->name()); | 320 keys::kNotWhitelistedError, api->name()); |
321 return false; | 321 return false; |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 // The requested permissions must be defined as optional in the manifest. | 325 // The requested permissions must be defined as optional in the manifest. |
326 if (!extension_->optional_permission_set()->Contains( | 326 if (!extension_->optional_permission_set()->Contains( |
327 *requested_permissions_)) { | 327 *requested_permissions_)) { |
328 error_ = keys::kNotInOptionalPermissionsError; | 328 error_ = keys::kNotInOptionalPermissionsError; |
329 result_.reset(Value::CreateBooleanValue(false)); | 329 result_.reset(base::FalseValue()); |
330 return false; | 330 return false; |
331 } | 331 } |
332 | 332 |
333 // We don't need to prompt the user if the requested permissions are a subset | 333 // We don't need to prompt the user if the requested permissions are a subset |
334 // of the granted permissions set. | 334 // of the granted permissions set. |
335 const ExtensionPermissionSet* granted = | 335 const ExtensionPermissionSet* granted = |
336 prefs->GetGrantedPermissions(extension_->id()); | 336 prefs->GetGrantedPermissions(extension_->id()); |
337 if (granted && granted->Contains(*requested_permissions_)) { | 337 if (granted && granted->Contains(*requested_permissions_)) { |
338 perms_manager->AddPermissions(extension_, requested_permissions_.get()); | 338 perms_manager->AddPermissions(extension_, requested_permissions_.get()); |
339 result_.reset(Value::CreateBooleanValue(true)); | 339 result_.reset(base::TrueValue()); |
340 SendResponse(true); | 340 SendResponse(true); |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 // Filter out the granted permissions so we only prompt for new ones. | 344 // Filter out the granted permissions so we only prompt for new ones. |
345 requested_permissions_ = ExtensionPermissionSet::CreateDifference( | 345 requested_permissions_ = ExtensionPermissionSet::CreateDifference( |
346 requested_permissions_.get(), granted); | 346 requested_permissions_.get(), granted); |
347 | 347 |
348 // Balanced with Release() in InstallUIProceed() and InstallUIAbort(). | 348 // Balanced with Release() in InstallUIProceed() and InstallUIAbort(). |
349 AddRef(); | 349 AddRef(); |
(...skipping 15 matching lines...) Expand all Loading... |
365 } | 365 } |
366 | 366 |
367 return true; | 367 return true; |
368 } | 368 } |
369 | 369 |
370 void RequestPermissionsFunction::InstallUIProceed() { | 370 void RequestPermissionsFunction::InstallUIProceed() { |
371 ExtensionPermissionsManager* perms_manager = | 371 ExtensionPermissionsManager* perms_manager = |
372 profile()->GetExtensionService()->permissions_manager(); | 372 profile()->GetExtensionService()->permissions_manager(); |
373 | 373 |
374 install_ui_.reset(); | 374 install_ui_.reset(); |
375 result_.reset(Value::CreateBooleanValue(true)); | 375 result_.reset(base::TrueValue()); |
376 perms_manager->AddPermissions(extension_, requested_permissions_.get()); | 376 perms_manager->AddPermissions(extension_, requested_permissions_.get()); |
377 | 377 |
378 SendResponse(true); | 378 SendResponse(true); |
379 | 379 |
380 Release(); | 380 Release(); |
381 } | 381 } |
382 | 382 |
383 void RequestPermissionsFunction::InstallUIAbort(bool user_initiated) { | 383 void RequestPermissionsFunction::InstallUIAbort(bool user_initiated) { |
384 install_ui_.reset(); | 384 install_ui_.reset(); |
385 result_.reset(Value::CreateBooleanValue(false)); | 385 result_.reset(base::FalseValue()); |
386 requested_permissions_ = NULL; | 386 requested_permissions_ = NULL; |
387 | 387 |
388 SendResponse(true); | 388 SendResponse(true); |
389 Release(); | 389 Release(); |
390 } | 390 } |
OLD | NEW |