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

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

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: optimize and "parent" property Created 7 years, 7 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>
10 #include <string> 9 #include <string>
11 10
12 #include "base/basictypes.h" 11 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
16 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
17 #include "base/values.h" 16 #include "base/values.h"
18 #include "chrome/common/extensions/features/feature.h" 17 #include "chrome/common/extensions/features/feature.h"
19 #include "chrome/common/extensions/features/feature_provider.h" 18 #include "chrome/common/extensions/features/feature_provider.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // "permission", or "api". The second part is the full name of the feature. 53 // "permission", or "api". The second part is the full name of the feature.
55 static void SplitDependencyName(const std::string& full_name, 54 static void SplitDependencyName(const std::string& full_name,
56 std::string* feature_type, 55 std::string* feature_type,
57 std::string* feature_name); 56 std::string* feature_name);
58 57
59 // Creates a completely clean instance. Configure using RegisterSchema() and 58 // Creates a completely clean instance. Configure using RegisterSchema() and
60 // RegisterDependencyProvider before use. 59 // RegisterDependencyProvider before use.
61 ExtensionAPI(); 60 ExtensionAPI();
62 virtual ~ExtensionAPI(); 61 virtual ~ExtensionAPI();
63 62
64 void RegisterSchema(const std::string& api_name, 63 void RegisterSchemaResource(const std::string& api_name, int resource_id);
65 const base::StringPiece& source);
66 64
67 void RegisterDependencyProvider(const std::string& name, 65 void RegisterDependencyProvider(const std::string& name,
68 FeatureProvider* provider); 66 FeatureProvider* provider);
69 67
70 // Returns true if the specified API is available. |api_full_name| can be 68 // 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 69 // either a namespace name (like "bookmarks") or a member name (like
72 // "bookmarks.create"). Returns true if the feature and all of its 70 // "bookmarks.create"). Returns true if the feature and all of its
73 // dependencies are available to the specified context. 71 // dependencies are available to the specified context.
74 Feature::Availability IsAvailable(const std::string& api_full_name, 72 Feature::Availability IsAvailable(const std::string& api_full_name,
75 const Extension* extension, 73 const Extension* extension,
76 Feature::Context context, 74 Feature::Context context,
77 const GURL& url); 75 const GURL& url);
78 76
79 // Determines whether an API, or any parts of that API, are available in 77 // Determines whether an API, or any parts of that API, are available in
80 // |context|. 78 // |context|.
81 bool IsAnyFeatureAvailableToContext(const std::string& api_name, 79 bool IsAnyFeatureAvailableToContext(const std::string& api_name,
82 Feature::Context context, 80 Feature::Context context,
83 const GURL& url); 81 const GURL& url);
84 82
85 // Returns true if |name| is a privileged API path. Privileged paths can only 83 // 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 84 // be called from extension code which is running in its own designated
87 // extension process. They cannot be called from extension code running in 85 // extension process. They cannot be called from extension code running in
88 // content scripts, or other low-privileged contexts. 86 // content scripts, or other low-privileged contexts.
89 bool IsPrivileged(const std::string& name); 87 bool IsPrivileged(const std::string& name);
90 88
91 // Gets the schema for the extension API with namespace |full_name|. 89 // Gets the schema for the extension API with namespace |full_name|.
92 // Ownership remains with this object. 90 // Ownership remains with this object.
93 const base::DictionaryValue* GetSchema(const std::string& full_name); 91 const base::DictionaryValue* GetSchema(const std::string& full_name);
94 92
95 std::set<std::string> GetAllAPINames();
96
97 // Splits a full name from the extension API into its API and child name 93 // Splits a full name from the extension API into its API and child name
98 // parts. Some examples: 94 // parts. Some examples:
99 // 95 //
100 // "bookmarks.create" -> ("bookmarks", "create") 96 // "bookmarks.create" -> ("bookmarks", "create")
101 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") 97 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp")
102 // "storage.sync.set" -> ("storage", "sync.get") 98 // "storage.sync.set" -> ("storage", "sync.get")
103 // "<unknown-api>.monkey" -> ("", "") 99 // "<unknown-api>.monkey" -> ("", "")
104 // 100 //
105 // The |child_name| parameter can be be NULL if you don't need that part. 101 // The |child_name| parameter can be be NULL if you don't need that part.
106 std::string GetAPINameFromFullName(const std::string& full_name, 102 std::string GetAPINameFromFullName(const std::string& full_name,
107 std::string* child_name); 103 std::string* child_name);
108 104
105 private:
106 friend struct DefaultSingletonTraits<ExtensionAPI>;
107 friend class ExtensionAPITest;
cduvall 2013/05/22 03:19:57 For some reason this still didn't allow ExtensionA
not at google - send to devlin 2013/05/23 00:09:40 I don't know gtest that well, but maybe they need
cduvall 2013/05/24 03:13:49 Ah figured it out with gtest docs.
108
109 void InitDefaultConfiguration(); 109 void InitDefaultConfiguration();
110 110
111 // Gets a feature from any dependency provider registered with ExtensionAPI. 111 // Gets a feature from any dependency provider registered with ExtensionAPI.
112 // Returns NULL if the feature could not be found. 112 // Returns NULL if the feature could not be found.
113 Feature* GetFeatureDependency(const std::string& dependency_name); 113 Feature* GetFeatureDependency(const std::string& dependency_name);
114 114
115 private:
116 friend struct DefaultSingletonTraits<ExtensionAPI>;
117
118 // Loads a schema. 115 // Loads a schema.
119 void LoadSchema(const std::string& name, const base::StringPiece& schema); 116 void LoadSchema(const std::string& name, const base::StringPiece& schema);
120 117
121 // Returns true if the function or event under |namespace_node| with
122 // the specified |child_name| is privileged, or false otherwise. If the name
123 // is not found, defaults to privileged.
124 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node,
125 const std::string& child_name);
126
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 118 // 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. 119 // it. Note that there may be multiple APIs per schema.
149 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; 120 typedef std::map<std::string, int> UnloadedSchemaMap;
150 UnloadedSchemaMap unloaded_schemas_; 121 UnloadedSchemaMap unloaded_schemas_;
151 122
152 // Schemas for each namespace. 123 // Schemas for each namespace.
153 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap; 124 typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap;
154 SchemaMap schemas_; 125 SchemaMap schemas_;
155 126
156 // APIs that are entirely unprivileged.
157 std::set<std::string> completely_unprivileged_apis_;
158
159 // APIs that are not entirely unprivileged, but have unprivileged components.
160 std::set<std::string> partially_unprivileged_apis_;
161
162 // FeatureProviders used for resolving dependencies. 127 // FeatureProviders used for resolving dependencies.
163 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; 128 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap;
164 FeatureProviderMap dependency_providers_; 129 FeatureProviderMap dependency_providers_;
165 130
166 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); 131 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI);
167 }; 132 };
168 133
169 } // extensions 134 } // extensions
170 135
171 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ 136 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698