| 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/features/permission_feature.h" | 5 #include "chrome/common/extensions/features/permission_feature.h" |
| 6 | 6 |
| 7 #include "chrome/common/extensions/permissions/permission_set.h" | 7 #include "chrome/common/extensions/permissions/permission_set.h" |
| 8 #include "chrome/common/extensions/permissions/permissions_data.h" | 8 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 | 11 |
| 12 PermissionFeature::PermissionFeature() { | 12 PermissionFeature::PermissionFeature() { |
| 13 } | 13 } |
| 14 | 14 |
| 15 PermissionFeature::~PermissionFeature() { | 15 PermissionFeature::~PermissionFeature() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 Feature::Availability PermissionFeature::IsAvailableToContext( | 18 Feature::Availability PermissionFeature::IsAvailableToContext( |
| 19 const Extension* extension, | 19 const Extension* extension, |
| 20 Feature::Context context, | 20 Feature::Context context, |
| 21 const GURL& url, | 21 const GURL& url, |
| 22 Feature::Platform platform) const { | 22 Feature::Platform platform) const { |
| 23 Availability availability = SimpleFeature::IsAvailableToContext(extension, | 23 Availability availability = SimpleFeature::IsAvailableToContext(extension, |
| 24 context, | 24 context, |
| 25 url, | 25 url, |
| 26 platform); | 26 platform); |
| 27 if (!availability.is_available()) | 27 if (!availability.is_available()) |
| 28 return availability; | 28 return availability; |
| 29 | 29 |
| 30 // Optional permissions need to be checked so an API will not be set to | |
| 31 // undefined forever, when it could just need optional permissions. | |
| 32 if (extension && !extension->HasAPIPermission(name()) && | 30 if (extension && !extension->HasAPIPermission(name()) && |
| 33 !PermissionsData::GetOptionalPermissions(extension)-> | 31 !PermissionsData::GetActivePermissions(extension)-> |
| 34 HasAnyAccessToAPI(name())) { | 32 HasAnyAccessToAPI(name())) { |
| 35 return CreateAvailability(NOT_PRESENT, extension->GetType()); | 33 return CreateAvailability(NOT_PRESENT, extension->GetType()); |
| 36 } | 34 } |
| 37 | 35 |
| 38 return CreateAvailability(IS_AVAILABLE); | 36 return CreateAvailability(IS_AVAILABLE); |
| 39 } | 37 } |
| 40 | 38 |
| 41 std::string PermissionFeature::Parse(const DictionaryValue* value) { | 39 std::string PermissionFeature::Parse(const DictionaryValue* value) { |
| 42 std::string error = SimpleFeature::Parse(value); | 40 std::string error = SimpleFeature::Parse(value); |
| 43 if (!error.empty()) | 41 if (!error.empty()) |
| 44 return error; | 42 return error; |
| 45 | 43 |
| 46 if (extension_types()->empty()) { | 44 if (extension_types()->empty()) { |
| 47 return name() + ": Permission features must specify at least one " + | 45 return name() + ": Permission features must specify at least one " + |
| 48 "value for extension_types."; | 46 "value for extension_types."; |
| 49 } | 47 } |
| 50 | 48 |
| 51 if (!GetContexts()->empty()) | 49 if (!GetContexts()->empty()) |
| 52 return name() + ": Permission features do not support contexts."; | 50 return name() + ": Permission features do not support contexts."; |
| 53 | 51 |
| 54 return std::string(); | 52 return std::string(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 } // namespace | 55 } // namespace |
| OLD | NEW |