1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_COMMON_EXTENSIONS_FEATURE_H_
#define CHROME_COMMON_EXTENSIONS_FEATURE_H_
#pragma once
#include <set>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/common/extensions/extension.h"
namespace extensions {
// Represents a single feature accessible to an extension developer, such as a
// top-level manifest key, a permission, or a programmatic API. A feature can
// express requirements for where it can be accessed, and supports testing
// support for those requirements.
class Feature {
public:
// The JavaScript contexts the feature is supported in.
enum Context {
UNSPECIFIED_CONTEXT,
// A context in a privileged extension process.
BLESSED_EXTENSION_CONTEXT,
// A context in an unprivileged extension process.
UNBLESSED_EXTENSION_CONTEXT,
// A context from a content script.
CONTENT_SCRIPT_CONTEXT,
// A normal web page. This should have an associated URL matching pattern.
WEB_PAGE_CONTEXT,
};
// The location required of extensions the feature is supported in.
enum Location {
UNSPECIFIED_LOCATION,
COMPONENT_LOCATION
};
// The platforms the feature is supported in.
enum Platform {
UNSPECIFIED_PLATFORM,
CHROMEOS_PLATFORM
};
// Whether a feature is available in a given situation or not, and if not,
// why not.
enum Availability {
IS_AVAILABLE,
NOT_FOUND_IN_WHITELIST,
INVALID_TYPE,
INVALID_CONTEXT,
INVALID_LOCATION,
INVALID_PLATFORM,
INVALID_MIN_MANIFEST_VERSION,
INVALID_MAX_MANIFEST_VERSION,
NOT_PRESENT,
DEPENDENCY_NOT_PRESENT
};
Feature();
Feature(const Feature& other);
virtual ~Feature();
const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }
// Gets the platform the code is currently running on.
static Platform GetCurrentPlatform();
// Gets the Feature::Location value for the specified Extension::Location.
static Location ConvertLocation(Extension::Location extension_location);
std::set<std::string>* whitelist() { return &whitelist_; }
std::set<Extension::Type>* extension_types() { return &extension_types_; }
std::set<Context>* contexts() { return &contexts_; }
Location location() const { return location_; }
void set_location(Location location) { location_ = location; }
Platform platform() const { return platform_; }
void set_platform(Platform platform) { platform_ = platform; }
int min_manifest_version() const { return min_manifest_version_; }
void set_min_manifest_version(int min_manifest_version) {
min_manifest_version_ = min_manifest_version;
}
int max_manifest_version() const { return max_manifest_version_; }
void set_max_manifest_version(int max_manifest_version) {
max_manifest_version_ = max_manifest_version;
}
// Parses the JSON representation of a feature into the fields of this object.
// Unspecified values in the JSON are not modified in the object. This allows
// us to implement inheritance by parsing one value after another.
void Parse(const DictionaryValue* value);
// Returns true if the feature contains the same values as another.
bool Equals(const Feature& other) const;
// Returns true if the feature is available to be parsed into a new extension
// manifest.
Availability IsAvailableToManifest(const std::string& extension_id,
Extension::Type type,
Location location,
int manifest_version) const {
return IsAvailableToManifest(extension_id, type, location, manifest_version,
GetCurrentPlatform());
}
Availability IsAvailableToManifest(const std::string& extension_id,
Extension::Type type,
Location location,
int manifest_version,
Platform platform) const;
// Returns true if the feature is available to be used in the specified
// extension and context.
Availability IsAvailableToContext(const Extension* extension,
Context context) const {
return IsAvailableToContext(extension, context, GetCurrentPlatform());
}
virtual Availability IsAvailableToContext(const Extension* extension,
Context context,
Platform platform) const;
// Returns an error message for an Availability code.
std::string GetErrorMessage(Availability result);
private:
std::string name_;
// For clarify and consistency, we handle the default value of each of these
// members the same way: it matches everything. It is up to the higher level
// code that reads Features out of static data to validate that data and set
// sensible defaults.
std::set<std::string> whitelist_;
std::set<Extension::Type> extension_types_;
std::set<Context> contexts_;
Location location_; // we only care about component/not-component now
Platform platform_; // we only care about chromeos/not-chromeos now
int min_manifest_version_;
int max_manifest_version_;
};
} // namespace extensions
#endif // CHROME_COMMON_EXTENSIONS_FEATURE_H_
|