Home | History | Annotate | Download | only in features
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/extensions/features/permission_feature.h"
      6 
      7 #include "chrome/common/extensions/permissions/permission_set.h"
      8 #include "chrome/common/extensions/permissions/permissions_data.h"
      9 
     10 namespace extensions {
     11 
     12 PermissionFeature::PermissionFeature() {
     13 }
     14 
     15 PermissionFeature::~PermissionFeature() {
     16 }
     17 
     18 Feature::Availability PermissionFeature::IsAvailableToContext(
     19     const Extension* extension,
     20     Feature::Context context,
     21     const GURL& url,
     22     Feature::Platform platform) const {
     23   Availability availability = SimpleFeature::IsAvailableToContext(extension,
     24                                                                   context,
     25                                                                   url,
     26                                                                   platform);
     27   if (!availability.is_available())
     28     return availability;
     29 
     30   if (extension && !PermissionsData::HasAPIPermission(extension, name()))
     31     return CreateAvailability(NOT_PRESENT, extension->GetType());
     32 
     33   return CreateAvailability(IS_AVAILABLE);
     34 }
     35 
     36 std::string PermissionFeature::Parse(const base::DictionaryValue* value) {
     37   std::string error = SimpleFeature::Parse(value);
     38   if (!error.empty())
     39     return error;
     40 
     41   if (extension_types()->empty()) {
     42     return name() + ": Permission features must specify at least one " +
     43         "value for extension_types.";
     44   }
     45 
     46   if (!GetContexts()->empty())
     47     return name() + ": Permission features do not support contexts.";
     48 
     49   return std::string();
     50 }
     51 
     52 }  // namespace extensions
     53