Revert "Re-land: content: Enable one-copy tile updates on Android."
[chromium-blink-merge.git] / extensions / common / features / feature.h
blob304f6cb160a25f9c3c2e4214cf52a0c662756599
1 // Copyright 2013 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.
5 #ifndef EXTENSIONS_COMMON_FEATURES_FEATURE_H_
6 #define EXTENSIONS_COMMON_FEATURES_FEATURE_H_
8 #include <set>
9 #include <string>
11 #include "base/values.h"
12 #include "extensions/common/manifest.h"
14 class GURL;
16 namespace extensions {
18 class Extension;
20 // Represents a single feature accessible to an extension developer, such as a
21 // top-level manifest key, a permission, or a programmatic API. A feature can
22 // express requirements for where it can be accessed, and supports testing
23 // support for those requirements. If platforms are not specified, then feature
24 // is available on all platforms.
25 class Feature {
26 public:
27 // The JavaScript contexts the feature is supported in.
28 enum Context {
29 UNSPECIFIED_CONTEXT,
31 // A context in a privileged extension process.
32 BLESSED_EXTENSION_CONTEXT,
34 // A context in an unprivileged extension process.
35 UNBLESSED_EXTENSION_CONTEXT,
37 // A context from a content script.
38 CONTENT_SCRIPT_CONTEXT,
40 // A normal web page. This should have an associated URL matching pattern.
41 WEB_PAGE_CONTEXT,
43 // A web page context which has been blessed by the user. Typically this
44 // will be via the installation of a hosted app, so this may host an
45 // extension. This is not affected by the URL matching pattern.
46 BLESSED_WEB_PAGE_CONTEXT,
48 // A page within webui.
49 WEBUI_CONTEXT,
52 // The platforms the feature is supported in.
53 enum Platform {
54 UNSPECIFIED_PLATFORM,
55 CHROMEOS_PLATFORM,
56 LINUX_PLATFORM,
57 MACOSX_PLATFORM,
58 WIN_PLATFORM
61 // Whether a feature is available in a given situation or not, and if not,
62 // why not.
63 enum AvailabilityResult {
64 IS_AVAILABLE,
65 NOT_FOUND_IN_WHITELIST,
66 INVALID_URL,
67 INVALID_TYPE,
68 INVALID_CONTEXT,
69 INVALID_LOCATION,
70 INVALID_PLATFORM,
71 INVALID_MIN_MANIFEST_VERSION,
72 INVALID_MAX_MANIFEST_VERSION,
73 NOT_PRESENT,
74 UNSUPPORTED_CHANNEL,
75 FOUND_IN_BLACKLIST,
76 MISSING_COMMAND_LINE_SWITCH,
79 // Container for AvailabiltyResult that also exposes a user-visible error
80 // message in cases where the feature is not available.
81 class Availability {
82 public:
83 Availability(AvailabilityResult result, const std::string& message)
84 : result_(result), message_(message) {}
86 AvailabilityResult result() const { return result_; }
87 bool is_available() const { return result_ == IS_AVAILABLE; }
88 const std::string& message() const { return message_; }
90 private:
91 friend class SimpleFeature;
92 friend class Feature;
94 const AvailabilityResult result_;
95 const std::string message_;
98 Feature();
99 virtual ~Feature();
101 const std::string& name() const { return name_; }
102 void set_name(const std::string& name) { name_ = name; }
103 bool no_parent() const { return no_parent_; }
105 // Gets the platform the code is currently running on.
106 static Platform GetCurrentPlatform();
108 // Tests whether this is an internal API or not.
109 virtual bool IsInternal() const = 0;
111 // Returns true if the feature is available to be parsed into a new extension
112 // manifest.
113 Availability IsAvailableToManifest(const std::string& extension_id,
114 Manifest::Type type,
115 Manifest::Location location,
116 int manifest_version) const {
117 return IsAvailableToManifest(extension_id, type, location, manifest_version,
118 GetCurrentPlatform());
120 virtual Availability IsAvailableToManifest(const std::string& extension_id,
121 Manifest::Type type,
122 Manifest::Location location,
123 int manifest_version,
124 Platform platform) const = 0;
126 // Returns true if the feature is available to |extension|.
127 Availability IsAvailableToExtension(const Extension* extension) const;
129 // Returns true if the feature is available to be used in the specified
130 // extension and context.
131 Availability IsAvailableToContext(const Extension* extension,
132 Context context,
133 const GURL& url) const {
134 return IsAvailableToContext(extension, context, url, GetCurrentPlatform());
136 virtual Availability IsAvailableToContext(const Extension* extension,
137 Context context,
138 const GURL& url,
139 Platform platform) const = 0;
141 virtual std::string GetAvailabilityMessage(AvailabilityResult result,
142 Manifest::Type type,
143 const GURL& url,
144 Context context) const = 0;
146 // Returns true if the feature is available to the current environment,
147 // without needing to know information about an Extension or any other
148 // contextual information. Typically used when the Feature is purely
149 // configured by command line flags and/or Chrome channel.
151 // Generally try not to use this function. Even if you don't think a Feature
152 // relies on an Extension now - maybe it will, one day, so if there's an
153 // Extension available (or a runtime context, etc) then use the more targeted
154 // method instead.
155 Availability IsAvailableToEnvironment() const;
157 virtual bool IsIdInBlacklist(const std::string& extension_id) const = 0;
158 virtual bool IsIdInWhitelist(const std::string& extension_id) const = 0;
160 protected:
161 std::string name_;
162 bool no_parent_;
165 } // namespace extensions
167 #endif // EXTENSIONS_COMMON_FEATURES_FEATURE_H_