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/manifest_feature.h"
6
7 #include "extensions/common/manifest.h"
8
9 namespace extensions {
10
ManifestFeature()11 ManifestFeature::ManifestFeature() {
12 }
13
~ManifestFeature()14 ManifestFeature::~ManifestFeature() {
15 }
16
IsAvailableToContext(const Extension * extension,Feature::Context context,const GURL & url,Feature::Platform platform) const17 Feature::Availability ManifestFeature::IsAvailableToContext(
18 const Extension* extension,
19 Feature::Context context,
20 const GURL& url,
21 Feature::Platform platform) const {
22 Availability availability = SimpleFeature::IsAvailableToContext(extension,
23 context,
24 url,
25 platform);
26 if (!availability.is_available())
27 return availability;
28
29 // We know we can skip manifest()->GetKey() here because we just did the same
30 // validation it would do above.
31 if (extension && !extension->manifest()->value()->HasKey(name()))
32 return CreateAvailability(NOT_PRESENT, extension->GetType());
33
34 return CreateAvailability(IS_AVAILABLE);
35 }
36
Parse(const base::DictionaryValue * value)37 std::string ManifestFeature::Parse(const base::DictionaryValue* value) {
38 std::string error = SimpleFeature::Parse(value);
39 if (!error.empty())
40 return error;
41
42 if (extension_types()->empty()) {
43 return name() + ": Manifest features must specify at least one " +
44 "value for extension_types.";
45 }
46
47 if (!GetContexts()->empty())
48 return name() + ": Manifest features do not support contexts.";
49
50 return std::string();
51 }
52
53 } // namespace extensions
54