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 3317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3328 if (manifest_->HasKey(key)) { | 3328 if (manifest_->HasKey(key)) { |
3329 ListValue* permissions = NULL; | 3329 ListValue* permissions = NULL; |
3330 if (!manifest_->GetList(key, &permissions)) { | 3330 if (!manifest_->GetList(key, &permissions)) { |
3331 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3331 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3332 errors::kInvalidPermissions, ""); | 3332 errors::kInvalidPermissions, ""); |
3333 return false; | 3333 return false; |
3334 } | 3334 } |
3335 | 3335 |
3336 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 3336 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
3337 std::string permission_str; | 3337 std::string permission_str; |
3338 if (!permissions->GetString(i, &permission_str)) { | 3338 base::ListValue *permission_list = NULL; |
| 3339 if (!permissions->GetString(i, &permission_str) && |
| 3340 !(permissions->GetList(i, &permission_list) && |
| 3341 permission_list->GetString(0, &permission_str))) { |
3339 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3342 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3340 errors::kInvalidPermission, base::IntToString(i)); | 3343 errors::kInvalidPermission, base::IntToString(i)); |
3341 return false; | 3344 return false; |
3342 } | 3345 } |
3343 | 3346 |
3344 // NOTE: We need to get the APIPermission before the Feature | 3347 // NOTE: We need to get the APIPermission before the Feature |
3345 // object because the feature system does not know about aliases. | 3348 // object because the feature system does not know about aliases. |
3346 APIPermission* permission = | 3349 APIPermission* permission = |
3347 PermissionsInfo::GetInstance()->GetByName(permission_str); | 3350 PermissionsInfo::GetInstance()->GetByName(permission_str); |
3348 if (permission) { | 3351 if (permission) { |
(...skipping 23 matching lines...) Expand all Loading... |
3372 continue; | 3375 continue; |
3373 } | 3376 } |
3374 | 3377 |
3375 if (permission->id() == APIPermission::kExperimental) { | 3378 if (permission->id() == APIPermission::kExperimental) { |
3376 if (!CanSpecifyExperimentalPermission()) { | 3379 if (!CanSpecifyExperimentalPermission()) { |
3377 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); | 3380 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
3378 return false; | 3381 return false; |
3379 } | 3382 } |
3380 } | 3383 } |
3381 | 3384 |
3382 api_permissions->insert(permission->id()); | 3385 scoped_refptr<APIPermissionDetail> detail = permission->CreateDetail(); |
| 3386 base::Value *value = NULL; |
| 3387 if (permission_list) { |
| 3388 if (!(permission_list->Get(1, &value) && detail->FromValue(value))) { |
| 3389 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 3390 errors::kInvalidPermission, base::IntToString(i)); |
| 3391 return false; |
| 3392 } |
| 3393 } |
| 3394 |
| 3395 api_permissions->insert(detail); |
3383 continue; | 3396 continue; |
3384 } | 3397 } |
3385 | 3398 |
3386 // Check if it's a host pattern permission. | 3399 // Check if it's a host pattern permission. |
3387 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? | 3400 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? |
3388 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; | 3401 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; |
3389 | 3402 |
3390 URLPattern pattern = URLPattern(kAllowedSchemes); | 3403 URLPattern pattern = URLPattern(kAllowedSchemes); |
3391 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); | 3404 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); |
3392 if (parse_result == URLPattern::PARSE_SUCCESS) { | 3405 if (parse_result == URLPattern::PARSE_SUCCESS) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3469 APIPermission::ID permission) const { | 3482 APIPermission::ID permission) const { |
3470 base::AutoLock auto_lock(runtime_data_lock_); | 3483 base::AutoLock auto_lock(runtime_data_lock_); |
3471 if (runtime_data_.GetActivePermissions()->HasAPIPermission(permission)) | 3484 if (runtime_data_.GetActivePermissions()->HasAPIPermission(permission)) |
3472 return true; | 3485 return true; |
3473 scoped_refptr<const PermissionSet> tab_specific_permissions = | 3486 scoped_refptr<const PermissionSet> tab_specific_permissions = |
3474 runtime_data_.GetTabSpecificPermissions(tab_id); | 3487 runtime_data_.GetTabSpecificPermissions(tab_id); |
3475 return tab_specific_permissions.get() && | 3488 return tab_specific_permissions.get() && |
3476 tab_specific_permissions->HasAPIPermission(permission); | 3489 tab_specific_permissions->HasAPIPermission(permission); |
3477 } | 3490 } |
3478 | 3491 |
| 3492 bool Extension::CheckAPIPermissionWithDetail(APIPermission::ID permission, |
| 3493 const APIPermissionDetail::CheckParam* param) const { |
| 3494 base::AutoLock auto_lock(runtime_data_lock_); |
| 3495 return runtime_data_.GetActivePermissions()-> |
| 3496 CheckAPIPermissionWithDetail(permission, param); |
| 3497 } |
| 3498 |
3479 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { | 3499 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { |
3480 base::AutoLock auto_lock(runtime_data_lock_); | 3500 base::AutoLock auto_lock(runtime_data_lock_); |
3481 return runtime_data_.GetActivePermissions()->effective_hosts(); | 3501 return runtime_data_.GetActivePermissions()->effective_hosts(); |
3482 } | 3502 } |
3483 | 3503 |
3484 bool Extension::HasHostPermission(const GURL& url) const { | 3504 bool Extension::HasHostPermission(const GURL& url) const { |
3485 if (url.SchemeIs(chrome::kChromeUIScheme) && | 3505 if (url.SchemeIs(chrome::kChromeUIScheme) && |
3486 url.host() != chrome::kChromeUIFaviconHost && | 3506 url.host() != chrome::kChromeUIFaviconHost && |
3487 url.host() != chrome::kChromeUIThumbnailHost && | 3507 url.host() != chrome::kChromeUIThumbnailHost && |
3488 location() != Extension::COMPONENT) { | 3508 location() != Extension::COMPONENT) { |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3901 | 3921 |
3902 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3922 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3903 const Extension* extension, | 3923 const Extension* extension, |
3904 const PermissionSet* permissions, | 3924 const PermissionSet* permissions, |
3905 Reason reason) | 3925 Reason reason) |
3906 : reason(reason), | 3926 : reason(reason), |
3907 extension(extension), | 3927 extension(extension), |
3908 permissions(permissions) {} | 3928 permissions(permissions) {} |
3909 | 3929 |
3910 } // namespace extensions | 3930 } // namespace extensions |
OLD | NEW |