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

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

Issue 224163002: Move core features code to //extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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
(Empty)
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 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_
6 #define CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h"
16 #include "chrome/common/extensions/features/simple_feature_filter.h"
17 #include "extensions/common/extension.h"
18 #include "extensions/common/features/feature.h"
19 #include "extensions/common/manifest.h"
20
21 namespace extensions {
22
23 class ComplexFeature;
24
25 class SimpleFeature : public Feature {
26 public:
27 SimpleFeature();
28 virtual ~SimpleFeature();
29
30 std::set<std::string>* whitelist() { return &whitelist_; }
31 std::set<Manifest::Type>* extension_types() { return &extension_types_; }
32
33 // Adds a filter to this feature. The feature takes ownership of the filter.
34 void AddFilter(scoped_ptr<SimpleFeatureFilter> filter);
35
36 // Parses the JSON representation of a feature into the fields of this object.
37 // Unspecified values in the JSON are not modified in the object. This allows
38 // us to implement inheritance by parsing one value after another. Returns
39 // the error found, or an empty string on success.
40 virtual std::string Parse(const base::DictionaryValue* value);
41
42 Location location() const { return location_; }
43 void set_location(Location location) { location_ = location; }
44
45 std::set<Platform>* platforms() { return &platforms_; }
46
47 int min_manifest_version() const { return min_manifest_version_; }
48 void set_min_manifest_version(int min_manifest_version) {
49 min_manifest_version_ = min_manifest_version;
50 }
51
52 int max_manifest_version() const { return max_manifest_version_; }
53 void set_max_manifest_version(int max_manifest_version) {
54 max_manifest_version_ = max_manifest_version;
55 }
56
57 Availability IsAvailableToContext(const Extension* extension,
58 Context context) const {
59 return IsAvailableToContext(extension, context, GURL());
60 }
61 Availability IsAvailableToContext(const Extension* extension,
62 Context context,
63 Platform platform) const {
64 return IsAvailableToContext(extension, context, GURL(), platform);
65 }
66 Availability IsAvailableToContext(const Extension* extension,
67 Context context,
68 const GURL& url) const {
69 return IsAvailableToContext(extension, context, url, GetCurrentPlatform());
70 }
71
72 // extension::Feature:
73 virtual Availability IsAvailableToManifest(const std::string& extension_id,
74 Manifest::Type type,
75 Location location,
76 int manifest_version,
77 Platform platform) const OVERRIDE;
78
79 virtual Availability IsAvailableToContext(const Extension* extension,
80 Context context,
81 const GURL& url,
82 Platform platform) const OVERRIDE;
83
84 virtual std::string GetAvailabilityMessage(AvailabilityResult result,
85 Manifest::Type type,
86 const GURL& url,
87 Context context) const OVERRIDE;
88
89 virtual std::set<Context>* GetContexts() OVERRIDE;
90
91 virtual bool IsInternal() const OVERRIDE;
92 virtual bool IsBlockedInServiceWorker() const OVERRIDE;
93
94 virtual bool IsIdInWhitelist(const std::string& extension_id) const OVERRIDE;
95 static bool IsIdInWhitelist(const std::string& extension_id,
96 const std::set<std::string>& whitelist);
97
98 protected:
99 Availability CreateAvailability(AvailabilityResult result) const;
100 Availability CreateAvailability(AvailabilityResult result,
101 Manifest::Type type) const;
102 Availability CreateAvailability(AvailabilityResult result,
103 const GURL& url) const;
104 Availability CreateAvailability(AvailabilityResult result,
105 Context context) const;
106
107 private:
108 // For clarity and consistency, we handle the default value of each of these
109 // members the same way: it matches everything. It is up to the higher level
110 // code that reads Features out of static data to validate that data and set
111 // sensible defaults.
112 std::set<std::string> whitelist_;
113 std::set<Manifest::Type> extension_types_;
114 std::set<Context> contexts_;
115 URLPatternSet matches_;
116 Location location_; // we only care about component/not-component now
117 std::set<Platform> platforms_;
118 int min_manifest_version_;
119 int max_manifest_version_;
120 bool has_parent_;
121
122 typedef std::vector<linked_ptr<SimpleFeatureFilter> > FilterList;
123 FilterList filters_;
124
125 FRIEND_TEST_ALL_PREFIXES(ExtensionSimpleFeatureTest, Context);
126 DISALLOW_COPY_AND_ASSIGN(SimpleFeature);
127 };
128
129 } // namespace extensions
130
131 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_SIMPLE_FEATURE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698