Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/common/extensions/features/feature.h

Issue 11316164: Implement ComplexFeature to support permission features with multiple rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames and add TODO Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_
6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // Container for AvailabiltyResult that also exposes a user-visible error 67 // Container for AvailabiltyResult that also exposes a user-visible error
68 // message in cases where the feature is not available. 68 // message in cases where the feature is not available.
69 class Availability { 69 class Availability {
70 public: 70 public:
71 AvailabilityResult result() const { return result_; } 71 AvailabilityResult result() const { return result_; }
72 bool is_available() const { return result_ == IS_AVAILABLE; } 72 bool is_available() const { return result_ == IS_AVAILABLE; }
73 const std::string& message() const { return message_; } 73 const std::string& message() const { return message_; }
74 74
75 private: 75 private:
76 friend class Feature; 76 friend class SimpleFeature;
77 77
78 // Instances should be created via Feature::CreateAvailability. 78 // Instances should be created via Feature::CreateAvailability.
79 Availability(AvailabilityResult result, const std::string& message) 79 Availability(AvailabilityResult result, const std::string& message)
80 : result_(result), message_(message) { } 80 : result_(result), message_(message) { }
81 81
82 const AvailabilityResult result_; 82 const AvailabilityResult result_;
83 const std::string message_; 83 const std::string message_;
84 }; 84 };
85 85
86 Feature();
87 Feature(const Feature& other);
88 virtual ~Feature(); 86 virtual ~Feature();
89 87
90 // Gets the current channel as seen by the Feature system. 88 // Gets the current channel as seen by the Feature system.
91 static chrome::VersionInfo::Channel GetCurrentChannel(); 89 static chrome::VersionInfo::Channel GetCurrentChannel();
92 90
93 // Sets the current channel as seen by the Feature system. In the browser 91 // Sets the current channel as seen by the Feature system. In the browser
94 // process this should be chrome::VersionInfo::GetChannel(), and in the 92 // process this should be chrome::VersionInfo::GetChannel(), and in the
95 // renderer this will need to come from an IPC. 93 // renderer this will need to come from an IPC.
96 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); 94 static void SetCurrentChannel(chrome::VersionInfo::Channel channel);
97 95
(...skipping 19 matching lines...) Expand all
117 115
118 const std::string& name() const { return name_; } 116 const std::string& name() const { return name_; }
119 void set_name(const std::string& name) { name_ = name; } 117 void set_name(const std::string& name) { name_ = name; }
120 118
121 // Gets the platform the code is currently running on. 119 // Gets the platform the code is currently running on.
122 static Platform GetCurrentPlatform(); 120 static Platform GetCurrentPlatform();
123 121
124 // Gets the Feature::Location value for the specified Extension::Location. 122 // Gets the Feature::Location value for the specified Extension::Location.
125 static Location ConvertLocation(Extension::Location extension_location); 123 static Location ConvertLocation(Extension::Location extension_location);
126 124
127 std::set<std::string>* whitelist() { return &whitelist_; } 125 // TODO(justinlin): Remove and move to APIFeature when it exists.
128 std::set<Extension::Type>* extension_types() { return &extension_types_; } 126 virtual std::set<Context>* GetContexts() = 0;
129 std::set<Context>* contexts() { return &contexts_; }
130
131 Location location() const { return location_; }
132 void set_location(Location location) { location_ = location; }
133
134 Platform platform() const { return platform_; }
135 void set_platform(Platform platform) { platform_ = platform; }
136
137 int min_manifest_version() const { return min_manifest_version_; }
138 void set_min_manifest_version(int min_manifest_version) {
139 min_manifest_version_ = min_manifest_version;
140 }
141
142 int max_manifest_version() const { return max_manifest_version_; }
143 void set_max_manifest_version(int max_manifest_version) {
144 max_manifest_version_ = max_manifest_version;
145 }
146
147 // Parses the JSON representation of a feature into the fields of this object.
148 // Unspecified values in the JSON are not modified in the object. This allows
149 // us to implement inheritance by parsing one value after another.
150 void Parse(const DictionaryValue* value);
151
152 // Returns true if the feature contains the same values as another.
153 bool Equals(const Feature& other) const;
154 127
155 // Returns true if the feature is available to be parsed into a new extension 128 // Returns true if the feature is available to be parsed into a new extension
156 // manifest. 129 // manifest.
157 Availability IsAvailableToManifest(const std::string& extension_id, 130 Availability IsAvailableToManifest(const std::string& extension_id,
158 Extension::Type type, 131 Extension::Type type,
159 Location location, 132 Location location,
160 int manifest_version) const { 133 int manifest_version) const {
161 return IsAvailableToManifest(extension_id, type, location, manifest_version, 134 return IsAvailableToManifest(extension_id, type, location, manifest_version,
162 GetCurrentPlatform()); 135 GetCurrentPlatform());
163 } 136 }
164 Availability IsAvailableToManifest(const std::string& extension_id, 137 virtual Availability IsAvailableToManifest(const std::string& extension_id,
165 Extension::Type type, 138 Extension::Type type,
166 Location location, 139 Location location,
167 int manifest_version, 140 int manifest_version,
168 Platform platform) const; 141 Platform platform) const = 0;
169 142
170 // Returns true if the feature is available to be used in the specified 143 // Returns true if the feature is available to be used in the specified
171 // extension and context. 144 // extension and context.
172 Availability IsAvailableToContext(const Extension* extension, 145 Availability IsAvailableToContext(const Extension* extension,
173 Context context) const { 146 Context context) const {
174 return IsAvailableToContext(extension, context, GetCurrentPlatform()); 147 return IsAvailableToContext(extension, context, GetCurrentPlatform());
175 } 148 }
176 virtual Availability IsAvailableToContext(const Extension* extension, 149 virtual Availability IsAvailableToContext(const Extension* extension,
177 Context context, 150 Context context,
178 Platform platform) const; 151 Platform platform) const = 0;
152
153 virtual std::string GetAvailabilityMessage(
154 AvailabilityResult result, Extension::Type type) const = 0;
179 155
180 protected: 156 protected:
181 Availability CreateAvailability(AvailabilityResult result) const;
182 Availability CreateAvailability(AvailabilityResult result,
183 Extension::Type type) const;
184
185 private:
186 std::string GetAvailabilityMessage(
187 AvailabilityResult result, Extension::Type type) const;
188
189 std::string name_; 157 std::string name_;
190
191 // For clarify and consistency, we handle the default value of each of these
192 // members the same way: it matches everything. It is up to the higher level
193 // code that reads Features out of static data to validate that data and set
194 // sensible defaults.
195 std::set<std::string> whitelist_;
196 std::set<Extension::Type> extension_types_;
197 std::set<Context> contexts_;
198 Location location_; // we only care about component/not-component now
199 Platform platform_; // we only care about chromeos/not-chromeos now
200 int min_manifest_version_;
201 int max_manifest_version_;
202 chrome::VersionInfo::Channel channel_;
203 }; 158 };
204 159
205 } // namespace extensions 160 } // namespace extensions
206 161
207 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ 162 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/complex_feature_unittest.cc ('k') | chrome/common/extensions/features/feature.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698