OLD | NEW |
---|---|
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_API_EXTENSION_API_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ |
6 #define CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ | 6 #define CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // "permission", or "api". The second part is the full name of the feature. | 54 // "permission", or "api". The second part is the full name of the feature. |
55 static void SplitDependencyName(const std::string& full_name, | 55 static void SplitDependencyName(const std::string& full_name, |
56 std::string* feature_type, | 56 std::string* feature_type, |
57 std::string* feature_name); | 57 std::string* feature_name); |
58 | 58 |
59 // Creates a completely clean instance. Configure using RegisterSchema() and | 59 // Creates a completely clean instance. Configure using RegisterSchema() and |
60 // RegisterDependencyProvider before use. | 60 // RegisterDependencyProvider before use. |
61 ExtensionAPI(); | 61 ExtensionAPI(); |
62 virtual ~ExtensionAPI(); | 62 virtual ~ExtensionAPI(); |
63 | 63 |
64 void RegisterSchema(const std::string& api_name, | 64 void RegisterSchemaResource(const std::string& api_name, int resource_id); |
65 const base::StringPiece& source); | |
66 | 65 |
67 void RegisterDependencyProvider(const std::string& name, | 66 void RegisterDependencyProvider(const std::string& name, |
68 FeatureProvider* provider); | 67 FeatureProvider* provider); |
69 | 68 |
70 // Returns true if the specified API is available. |api_full_name| can be | 69 // Returns true if the specified API is available. |api_full_name| can be |
71 // either a namespace name (like "bookmarks") or a member name (like | 70 // either a namespace name (like "bookmarks") or a member name (like |
72 // "bookmarks.create"). Returns true if the feature and all of its | 71 // "bookmarks.create"). Returns true if the feature and all of its |
73 // dependencies are available to the specified context. | 72 // dependencies are available to the specified context. |
74 Feature::Availability IsAvailable(const std::string& api_full_name, | 73 Feature::Availability IsAvailable(const std::string& api_full_name, |
75 const Extension* extension, | 74 const Extension* extension, |
76 Feature::Context context, | 75 Feature::Context context, |
77 const GURL& url); | 76 const GURL& url); |
78 | 77 |
79 // Determines whether an API, or any parts of that API, are available in | 78 // Determines whether an API, or any parts of that API, are available in |
80 // |context|. | 79 // |context|. |
81 bool IsAnyFeatureAvailableToContext(const std::string& api_name, | 80 bool IsAnyFeatureAvailableToContext(const std::string& api_name, |
82 Feature::Context context, | 81 Feature::Context context, |
83 const GURL& url); | 82 const GURL& url); |
84 | 83 |
85 // Returns true if |name| is a privileged API path. Privileged paths can only | 84 // Returns true if |name| is a privileged API path. Privileged paths can only |
86 // be called from extension code which is running in its own designated | 85 // be called from extension code which is running in its own designated |
87 // extension process. They cannot be called from extension code running in | 86 // extension process. They cannot be called from extension code running in |
88 // content scripts, or other low-privileged contexts. | 87 // content scripts, or other low-privileged contexts. |
89 bool IsPrivileged(const std::string& name); | 88 bool IsPrivileged(const std::string& name); |
not at google - send to devlin
2013/05/20 17:19:04
we should be able to convert all render-side uses
cduvall
2013/05/22 03:19:56
Done.
| |
90 | 89 |
91 // Gets the schema for the extension API with namespace |full_name|. | 90 // Gets the schema for the extension API with namespace |full_name|. |
92 // Ownership remains with this object. | 91 // Ownership remains with this object. |
93 const base::DictionaryValue* GetSchema(const std::string& full_name); | 92 const base::DictionaryValue* GetSchema(const std::string& full_name); |
94 | 93 |
95 std::set<std::string> GetAllAPINames(); | 94 std::set<std::string> GetAllAPINames(); |
96 | 95 |
97 // Splits a full name from the extension API into its API and child name | 96 // Splits a full name from the extension API into its API and child name |
98 // parts. Some examples: | 97 // parts. Some examples: |
99 // | 98 // |
100 // "bookmarks.create" -> ("bookmarks", "create") | 99 // "bookmarks.create" -> ("bookmarks", "create") |
101 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") | 100 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") |
102 // "storage.sync.set" -> ("storage", "sync.get") | 101 // "storage.sync.set" -> ("storage", "sync.get") |
103 // "<unknown-api>.monkey" -> ("", "") | 102 // "<unknown-api>.monkey" -> ("", "") |
104 // | 103 // |
105 // The |child_name| parameter can be be NULL if you don't need that part. | 104 // The |child_name| parameter can be be NULL if you don't need that part. |
106 std::string GetAPINameFromFullName(const std::string& full_name, | 105 std::string GetAPINameFromFullName(const std::string& full_name, |
107 std::string* child_name); | 106 std::string* child_name); |
108 | 107 |
109 void InitDefaultConfiguration(); | 108 void InitDefaultConfiguration(); |
not at google - send to devlin
2013/05/20 17:19:04
this can be private
cduvall
2013/05/22 03:19:56
Done.
| |
110 | 109 |
111 // Gets a feature from any dependency provider registered with ExtensionAPI. | 110 // Gets a feature from any dependency provider registered with ExtensionAPI. |
112 // Returns NULL if the feature could not be found. | 111 // Returns NULL if the feature could not be found. |
113 Feature* GetFeatureDependency(const std::string& dependency_name); | 112 Feature* GetFeatureDependency(const std::string& dependency_name); |
not at google - send to devlin
2013/05/20 17:19:04
maybe we should friend ExtensionAPITest so that al
cduvall
2013/05/22 03:19:56
Done.
| |
114 | 113 |
115 private: | 114 private: |
116 friend struct DefaultSingletonTraits<ExtensionAPI>; | 115 friend struct DefaultSingletonTraits<ExtensionAPI>; |
117 | 116 |
118 // Loads a schema. | 117 // Loads a schema. |
119 void LoadSchema(const std::string& name, const base::StringPiece& schema); | 118 void LoadSchema(const std::string& name, const base::StringPiece& schema); |
120 | 119 |
121 // Returns true if the function or event under |namespace_node| with | 120 // Returns true if the function or event under |namespace_node| with |
122 // the specified |child_name| is privileged, or false otherwise. If the name | 121 // the specified |child_name| is privileged, or false otherwise. If the name |
123 // is not found, defaults to privileged. | 122 // is not found, defaults to privileged. |
124 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, | 123 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, |
125 const std::string& child_name); | 124 const std::string& child_name); |
126 | 125 |
127 // NOTE: This IsAPIAllowed() and IsNonFeatureAPIAvailable only work for | |
128 // non-feature-controlled APIs. | |
129 // TODO(aa): Remove these when all APIs are converted to the feature system. | |
130 | |
131 // Checks if API |name| is allowed. | |
132 bool IsAPIAllowed(const std::string& name, const Extension* extension); | |
133 | |
134 // Check if an API is available to |context| given an |extension| and |url|. | |
135 // The extension or URL may not be relevant to all contexts, and may be left | |
136 // NULL/empty. | |
137 bool IsNonFeatureAPIAvailable(const std::string& name, | |
138 Feature::Context context, | |
139 const Extension* extension, | |
140 const GURL& url); | |
141 | |
142 // Checks if an API is *entirely* privileged. This won't include APIs such as | |
143 // "storage" which is entirely unprivileged, nor "extension" which has | |
144 // unprivileged components. | |
145 bool IsPrivilegedAPI(const std::string& name); | |
146 | |
147 // Map from each API that hasn't been loaded yet to the schema which defines | 126 // Map from each API that hasn't been loaded yet to the schema which defines |
148 // it. Note that there may be multiple APIs per schema. | 127 // it. Note that there may be multiple APIs per schema. |
149 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; | 128 typedef std::map<std::string, int> UnloadedSchemaMap; |
150 UnloadedSchemaMap unloaded_schemas_; | 129 UnloadedSchemaMap unloaded_schemas_; |
151 | 130 |
152 // Schemas for each namespace. | 131 // Schemas for each namespace. |
153 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; | 132 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; |
154 SchemaMap schemas_; | 133 SchemaMap schemas_; |
155 | 134 |
156 // APIs that are entirely unprivileged. | 135 // APIs that are entirely unprivileged. |
157 std::set<std::string> completely_unprivileged_apis_; | 136 std::set<std::string> completely_unprivileged_apis_; |
158 | 137 |
159 // APIs that are not entirely unprivileged, but have unprivileged components. | 138 // APIs that are not entirely unprivileged, but have unprivileged components. |
160 std::set<std::string> partially_unprivileged_apis_; | 139 std::set<std::string> partially_unprivileged_apis_; |
not at google - send to devlin
2013/05/20 17:19:04
following on from my comment in the cc file, shoul
cduvall
2013/05/22 03:19:56
Done.
| |
161 | 140 |
162 // FeatureProviders used for resolving dependencies. | 141 // FeatureProviders used for resolving dependencies. |
163 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; | 142 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; |
164 FeatureProviderMap dependency_providers_; | 143 FeatureProviderMap dependency_providers_; |
165 | 144 |
166 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 145 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |
167 }; | 146 }; |
168 | 147 |
169 } // extensions | 148 } // extensions |
170 | 149 |
171 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ | 150 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ |
OLD | NEW |