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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 3319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3330 if (manifest_->HasKey(key)) { | 3330 if (manifest_->HasKey(key)) { |
3331 ListValue* permissions = NULL; | 3331 ListValue* permissions = NULL; |
3332 if (!manifest_->GetList(key, &permissions)) { | 3332 if (!manifest_->GetList(key, &permissions)) { |
3333 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3333 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3334 errors::kInvalidPermissions, ""); | 3334 errors::kInvalidPermissions, ""); |
3335 return false; | 3335 return false; |
3336 } | 3336 } |
3337 | 3337 |
3338 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 3338 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
3339 std::string permission_str; | 3339 std::string permission_str; |
| 3340 const base::Value* permission_detail = NULL; |
3340 if (!permissions->GetString(i, &permission_str)) { | 3341 if (!permissions->GetString(i, &permission_str)) { |
3341 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3342 const base::DictionaryValue *dict = NULL; |
3342 errors::kInvalidPermission, base::IntToString(i)); | 3343 // permission should be a string or a single key dict. |
3343 return false; | 3344 if (!permissions->GetDictionary(i, &dict) || dict->size() != 1) { |
| 3345 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 3346 errors::kInvalidPermission, base::IntToString(i)); |
| 3347 return false; |
| 3348 } |
| 3349 base::DictionaryValue::Iterator it(*dict); |
| 3350 permission_str = it.key(); |
| 3351 permission_detail = &it.value(); |
3344 } | 3352 } |
3345 | 3353 |
3346 // NOTE: We need to get the APIPermission before the Feature | 3354 // NOTE: We need to get the APIPermission before the Feature |
3347 // object because the feature system does not know about aliases. | 3355 // object because the feature system does not know about aliases. |
3348 APIPermission* permission = | 3356 APIPermission* permission = |
3349 PermissionsInfo::GetInstance()->GetByName(permission_str); | 3357 PermissionsInfo::GetInstance()->GetByName(permission_str); |
3350 if (permission) { | 3358 if (permission) { |
3351 extensions::SimpleFeatureProvider* permission_features = | 3359 extensions::SimpleFeatureProvider* permission_features = |
3352 extensions::SimpleFeatureProvider::GetPermissionFeatures(); | 3360 extensions::SimpleFeatureProvider::GetPermissionFeatures(); |
3353 extensions::Feature* feature = | 3361 extensions::Feature* feature = |
(...skipping 20 matching lines...) Expand all Loading... |
3374 continue; | 3382 continue; |
3375 } | 3383 } |
3376 | 3384 |
3377 if (permission->id() == APIPermission::kExperimental) { | 3385 if (permission->id() == APIPermission::kExperimental) { |
3378 if (!CanSpecifyExperimentalPermission()) { | 3386 if (!CanSpecifyExperimentalPermission()) { |
3379 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); | 3387 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
3380 return false; | 3388 return false; |
3381 } | 3389 } |
3382 } | 3390 } |
3383 | 3391 |
3384 api_permissions->insert(permission->id()); | 3392 scoped_refptr<APIPermissionDetail> detail = permission->CreateDetail(); |
| 3393 if (!detail->FromValue(permission_detail)) { |
| 3394 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 3395 errors::kInvalidPermission, base::IntToString(i)); |
| 3396 return false; |
| 3397 } |
| 3398 |
| 3399 api_permissions->insert(detail); |
3385 continue; | 3400 continue; |
3386 } | 3401 } |
3387 | 3402 |
3388 // Check if it's a host pattern permission. | 3403 // Check if it's a host pattern permission. |
3389 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? | 3404 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? |
3390 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; | 3405 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; |
3391 | 3406 |
3392 URLPattern pattern = URLPattern(kAllowedSchemes); | 3407 URLPattern pattern = URLPattern(kAllowedSchemes); |
3393 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); | 3408 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); |
3394 if (parse_result == URLPattern::PARSE_SUCCESS) { | 3409 if (parse_result == URLPattern::PARSE_SUCCESS) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3471 APIPermission::ID permission) const { | 3486 APIPermission::ID permission) const { |
3472 base::AutoLock auto_lock(runtime_data_lock_); | 3487 base::AutoLock auto_lock(runtime_data_lock_); |
3473 if (runtime_data_.GetActivePermissions()->HasAPIPermission(permission)) | 3488 if (runtime_data_.GetActivePermissions()->HasAPIPermission(permission)) |
3474 return true; | 3489 return true; |
3475 scoped_refptr<const PermissionSet> tab_specific_permissions = | 3490 scoped_refptr<const PermissionSet> tab_specific_permissions = |
3476 runtime_data_.GetTabSpecificPermissions(tab_id); | 3491 runtime_data_.GetTabSpecificPermissions(tab_id); |
3477 return tab_specific_permissions.get() && | 3492 return tab_specific_permissions.get() && |
3478 tab_specific_permissions->HasAPIPermission(permission); | 3493 tab_specific_permissions->HasAPIPermission(permission); |
3479 } | 3494 } |
3480 | 3495 |
| 3496 bool Extension::CheckAPIPermissionWithDetail(APIPermission::ID permission, |
| 3497 const APIPermissionDetail::CheckParam* param) const { |
| 3498 base::AutoLock auto_lock(runtime_data_lock_); |
| 3499 return runtime_data_.GetActivePermissions()-> |
| 3500 CheckAPIPermissionWithDetail(permission, param); |
| 3501 } |
| 3502 |
3481 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { | 3503 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { |
3482 base::AutoLock auto_lock(runtime_data_lock_); | 3504 base::AutoLock auto_lock(runtime_data_lock_); |
3483 return runtime_data_.GetActivePermissions()->effective_hosts(); | 3505 return runtime_data_.GetActivePermissions()->effective_hosts(); |
3484 } | 3506 } |
3485 | 3507 |
3486 bool Extension::HasHostPermission(const GURL& url) const { | 3508 bool Extension::HasHostPermission(const GURL& url) const { |
3487 if (url.SchemeIs(chrome::kChromeUIScheme) && | 3509 if (url.SchemeIs(chrome::kChromeUIScheme) && |
3488 url.host() != chrome::kChromeUIFaviconHost && | 3510 url.host() != chrome::kChromeUIFaviconHost && |
3489 url.host() != chrome::kChromeUIThumbnailHost && | 3511 url.host() != chrome::kChromeUIThumbnailHost && |
3490 location() != Extension::COMPONENT) { | 3512 location() != Extension::COMPONENT) { |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3903 | 3925 |
3904 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3926 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3905 const Extension* extension, | 3927 const Extension* extension, |
3906 const PermissionSet* permissions, | 3928 const PermissionSet* permissions, |
3907 Reason reason) | 3929 Reason reason) |
3908 : reason(reason), | 3930 : reason(reason), |
3909 extension(extension), | 3931 extension(extension), |
3910 permissions(permissions) {} | 3932 permissions(permissions) {} |
3911 | 3933 |
3912 } // namespace extensions | 3934 } // namespace extensions |
OLD | NEW |