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

Side by Side Diff: chrome/common/extensions/api/extension_api.h

Issue 12522004: Lazily load extension API schemas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 9 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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 void RegisterSchema(const std::string& api_name, 64 void RegisterSchema(const std::string& api_name,
65 const base::StringPiece& source); 65 const base::StringPiece& source);
66 66
67 void RegisterDependencyProvider(const std::string& name, 67 void RegisterDependencyProvider(const std::string& name,
68 FeatureProvider* provider); 68 FeatureProvider* provider);
69 69
70 // Returns true if the specified API is available. |api_full_name| can be 70 // 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 71 // either a namespace name (like "bookmarks") or a member name (like
72 // "bookmarks.create"). Returns true if the feature and all of its 72 // "bookmarks.create"). Returns true if the feature and all of its
73 // dependencies are available to the specified context. 73 // dependencies are available to the specified context.
74 bool IsAvailable(const std::string& api_full_name, 74 Feature::Availability IsAvailable(const std::string& api_full_name,
75 const Extension* extension, 75 const Extension* extension,
76 Feature::Context context); 76 Feature::Context context,
77 const GURL& url);
77 78
78 // Returns true if |name| is a privileged API path. Privileged paths can only 79 // Returns true if |name| is a privileged API path. Privileged paths can only
79 // be called from extension code which is running in its own designated 80 // be called from extension code which is running in its own designated
80 // extension process. They cannot be called from extension code running in 81 // extension process. They cannot be called from extension code running in
81 // content scripts, or other low-privileged contexts. 82 // content scripts, or other low-privileged contexts.
82 bool IsPrivileged(const std::string& name); 83 bool IsPrivileged(const std::string& name);
83 84
84 // Gets the schema for the extension API with namespace |full_name|. 85 // Gets the schema for the extension API with namespace |full_name|.
85 // Ownership remains with this object. 86 // Ownership remains with this object.
86 const base::DictionaryValue* GetSchema(const std::string& full_name); 87 const base::DictionaryValue* GetSchema(const std::string& full_name);
87 88
88 // Gets the APIs available to |context| given an |extension| and |url|. The
89 // extension or URL may not be relevant to all contexts, and may be left
90 // NULL/empty.
91 std::set<std::string> GetAPIsForContext(
92 Feature::Context context, const Extension* extension, const GURL& url);
93
94 std::set<std::string> GetAllAPINames(); 89 std::set<std::string> GetAllAPINames();
95 90
96 // Gets a Feature object describing the API with the specified |full_name|. 91 // Gets a Feature object describing the API with the specified |full_name|.
97 // This can be either an API namespace (like history, or 92 // This can be either an API namespace (like history, or
98 // experimental.bookmarks), or it can be an individual function or event. 93 // experimental.bookmarks), or it can be an individual function or event.
99 virtual Feature* GetFeature(const std::string& full_name) OVERRIDE; 94 virtual Feature* GetFeature(const std::string& full_name) OVERRIDE;
100 95
101 // 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
102 // parts. Some examples: 97 // parts. Some examples:
103 // 98 //
104 // "bookmarks.create" -> ("bookmarks", "create") 99 // "bookmarks.create" -> ("bookmarks", "create")
105 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") 100 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp")
106 // "storage.sync.set" -> ("storage", "sync.get") 101 // "storage.sync.set" -> ("storage", "sync.get")
107 // "<unknown-api>.monkey" -> ("", "") 102 // "<unknown-api>.monkey" -> ("", "")
108 // 103 //
109 // 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.
110 std::string GetAPINameFromFullName(const std::string& full_name, 105 std::string GetAPINameFromFullName(const std::string& full_name,
111 std::string* child_name); 106 std::string* child_name);
112 107
113 void InitDefaultConfiguration(); 108 void InitDefaultConfiguration();
114 109
115 // Loads the schemas registered with RegisterSchema().
116 void LoadAllSchemas();
117
118 private: 110 private:
119 friend struct DefaultSingletonTraits<ExtensionAPI>; 111 friend struct DefaultSingletonTraits<ExtensionAPI>;
120 112
121 // Loads a schema. 113 // Loads a schema.
122 void LoadSchema(const std::string& name, const base::StringPiece& schema); 114 void LoadSchema(const std::string& name, const base::StringPiece& schema);
123 115
124 // Returns true if the function or event under |namespace_node| with 116 // Returns true if the function or event under |namespace_node| with
125 // the specified |child_name| is privileged, or false otherwise. If the name 117 // the specified |child_name| is privileged, or false otherwise. If the name
126 // is not found, defaults to privileged. 118 // is not found, defaults to privileged.
127 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, 119 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node,
128 const std::string& child_name); 120 const std::string& child_name);
129 121
130 // Adds all APIs to |out| that |extension| has any permission (required or 122 // Checks if API |name| is allowed.
131 // optional) to use.
132 // NOTE: This only works for non-feature-controlled APIs. 123 // NOTE: This only works for non-feature-controlled APIs.
133 // TODO(aa): Remove this when all APIs are converted to the feature system. 124 // TODO(aa): Remove this when all APIs are converted to the feature system.
134 void GetAllowedAPIs(const Extension* extension, std::set<std::string>* out); 125 bool IsAPIAllowed(const std::string& name, const Extension* extension);
126
127 // Returns true if the API uses the feature system.
128 bool UsesFeatureSystem(const std::string& full_name);
129
130 // Check if an API is available to |context| given an |extension| and |url|.
131 // The extension or URL may not be relevant to all contexts, and may be left
132 // NULL/empty.
133 bool IsNonFeatureAPIAvailable(const std::string& name,
not at google - send to devlin 2013/03/22 18:13:48 cool, got it. move this up to line 126 and make t
cduvall 2013/03/22 20:26:45 Done.
134 Feature::Context context,
135 const Extension* extension,
136 const GURL& url);
135 137
136 // Gets a feature from any dependency provider. 138 // Gets a feature from any dependency provider.
137 Feature* GetFeatureDependency(const std::string& dependency_name); 139 Feature* GetFeatureDependency(const std::string& dependency_name);
138 140
139 // Adds dependent schemas to |out| as determined by the "dependencies" 141 // Adds dependent schemas to |out| as determined by the "dependencies"
140 // property. 142 // property.
141 // TODO(aa): Consider making public and adding tests. 143 // TODO(aa): Consider making public and adding tests.
142 void ResolveDependencies(std::set<std::string>* out); 144 void ResolveDependencies(std::set<std::string>* out);
143 145
144 // Adds any APIs listed in "dependencies" found in the schema for |api_name| 146 // Adds any APIs listed in "dependencies" found in the schema for |api_name|
145 // but not in |excluding| to |out|. 147 // but not in |excluding| to |out|.
146 void GetMissingDependencies( 148 void GetMissingDependencies(
147 const std::string& api_name, 149 const std::string& api_name,
148 const std::set<std::string>& excluding, 150 const std::set<std::string>& excluding,
149 std::set<std::string>* out); 151 std::set<std::string>* out);
150 152
151 // Removes all APIs from |apis| which are *entirely* privileged. This won't 153 // Checks if an API is *entirely* privileged. This won't include APIs such as
152 // include APIs such as "storage" which is entirely unprivileged, nor 154 // "storage" which is entirely unprivileged, nor "extension" which has
153 // "extension" which has unprivileged components. 155 // unprivileged components.
154 void RemovePrivilegedAPIs(std::set<std::string>* apis); 156 bool IsPrivilegedAPI(const std::string& name);
155
156 // Adds an APIs that match |url| to |out|.
157 // NOTE: This only works for non-feature-controlled APIs.
158 // TODO(aa): Remove this when all APIs are converted to the feature system.
159 void GetAPIsMatchingURL(const GURL& url, std::set<std::string>* out);
160 157
161 // Map from each API that hasn't been loaded yet to the schema which defines 158 // Map from each API that hasn't been loaded yet to the schema which defines
162 // it. Note that there may be multiple APIs per schema. 159 // it. Note that there may be multiple APIs per schema.
163 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; 160 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap;
164 UnloadedSchemaMap unloaded_schemas_; 161 UnloadedSchemaMap unloaded_schemas_;
165 162
166 // Schemas for each namespace. 163 // Schemas for each namespace.
167 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; 164 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap;
168 SchemaMap schemas_; 165 SchemaMap schemas_;
169 166
(...skipping 13 matching lines...) Expand all
183 // FeatureProviders used for resolving dependencies. 180 // FeatureProviders used for resolving dependencies.
184 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; 181 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap;
185 FeatureProviderMap dependency_providers_; 182 FeatureProviderMap dependency_providers_;
186 183
187 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); 184 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI);
188 }; 185 };
189 186
190 } // extensions 187 } // extensions
191 188
192 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ 189 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/extension_api.cc » ('j') | chrome/common/extensions/api/extension_api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698