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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
13 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/common/extensions/features/feature.h" | 19 #include "chrome/common/extensions/features/feature.h" |
19 #include "chrome/common/extensions/features/feature_provider.h" | 20 #include "chrome/common/extensions/features/feature_provider.h" |
20 #include "extensions/common/url_pattern_set.h" | 21 #include "extensions/common/url_pattern_set.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
(...skipping 31 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. | 55 // "permission", or "api". The second part is the full name of the feature. |
55 static void SplitDependencyName(const std::string& full_name, | 56 static void SplitDependencyName(const std::string& full_name, |
56 std::string* feature_type, | 57 std::string* feature_type, |
57 std::string* feature_name); | 58 std::string* feature_name); |
58 | 59 |
59 // Creates a completely clean instance. Configure using RegisterSchema() and | 60 // Creates a completely clean instance. Configure using RegisterSchema() and |
60 // RegisterDependencyProvider before use. | 61 // RegisterDependencyProvider before use. |
61 ExtensionAPI(); | 62 ExtensionAPI(); |
62 virtual ~ExtensionAPI(); | 63 virtual ~ExtensionAPI(); |
63 | 64 |
64 void RegisterSchema(const std::string& api_name, | 65 void RegisterSchema(const std::string& api_name, int resource_id); |
65 const base::StringPiece& source); | 66 void RegisterGeneratedSchema(const std::string& name); |
66 | 67 |
67 void RegisterDependencyProvider(const std::string& name, | 68 void RegisterDependencyProvider(const std::string& name, |
68 FeatureProvider* provider); | 69 FeatureProvider* provider); |
69 | 70 |
70 // Returns true if the specified API is available. |api_full_name| can be | 71 // 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 | 72 // either a namespace name (like "bookmarks") or a member name (like |
72 // "bookmarks.create"). Returns true if the feature and all of its | 73 // "bookmarks.create"). Returns true if the feature and all of its |
73 // dependencies are available to the specified context. | 74 // dependencies are available to the specified context. |
74 Feature::Availability IsAvailable(const std::string& api_full_name, | 75 Feature::Availability IsAvailable(const std::string& api_full_name, |
75 const Extension* extension, | 76 const Extension* extension, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const Extension* extension, | 140 const Extension* extension, |
140 const GURL& url); | 141 const GURL& url); |
141 | 142 |
142 // Checks if an API is *entirely* privileged. This won't include APIs such as | 143 // 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 // "storage" which is entirely unprivileged, nor "extension" which has |
144 // unprivileged components. | 145 // unprivileged components. |
145 bool IsPrivilegedAPI(const std::string& name); | 146 bool IsPrivilegedAPI(const std::string& name); |
146 | 147 |
147 // Map from each API that hasn't been loaded yet to the schema which defines | 148 // 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. | 149 // it. Note that there may be multiple APIs per schema. |
149 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; | 150 typedef std::map<std::string, base::Callback<base::StringPiece()> > |
| 151 UnloadedSchemaMap; |
150 UnloadedSchemaMap unloaded_schemas_; | 152 UnloadedSchemaMap unloaded_schemas_; |
151 | 153 |
152 // Schemas for each namespace. | 154 // Schemas for each namespace. |
153 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; | 155 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; |
154 SchemaMap schemas_; | 156 SchemaMap schemas_; |
155 | 157 |
156 // APIs that are entirely unprivileged. | 158 // APIs that are entirely unprivileged. |
157 std::set<std::string> completely_unprivileged_apis_; | 159 std::set<std::string> completely_unprivileged_apis_; |
158 | 160 |
159 // APIs that are not entirely unprivileged, but have unprivileged components. | 161 // APIs that are not entirely unprivileged, but have unprivileged components. |
160 std::set<std::string> partially_unprivileged_apis_; | 162 std::set<std::string> partially_unprivileged_apis_; |
161 | 163 |
162 // FeatureProviders used for resolving dependencies. | 164 // FeatureProviders used for resolving dependencies. |
163 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; | 165 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; |
164 FeatureProviderMap dependency_providers_; | 166 FeatureProviderMap dependency_providers_; |
165 | 167 |
166 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 168 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |
167 }; | 169 }; |
168 | 170 |
169 } // extensions | 171 } // extensions |
170 | 172 |
171 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ | 173 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ |
OLD | NEW |