Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); | |
| 78 | |
| 79 // Returns true if the API uses the feature system. | |
| 80 bool UsesFeatureSystem(const std::string& full_name); | |
|
not at google - send to devlin
2013/03/14 19:16:46
looks like this can be moved back out of public:
cduvall
2013/03/21 22:27:55
Done.
| |
| 77 | 81 |
| 78 // Returns true if |name| is a privileged API path. Privileged paths can only | 82 // 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 | 83 // be called from extension code which is running in its own designated |
| 80 // extension process. They cannot be called from extension code running in | 84 // extension process. They cannot be called from extension code running in |
| 81 // content scripts, or other low-privileged contexts. | 85 // content scripts, or other low-privileged contexts. |
| 82 bool IsPrivileged(const std::string& name); | 86 bool IsPrivileged(const std::string& name); |
| 83 | 87 |
| 84 // Gets the schema for the extension API with namespace |full_name|. | 88 // Gets the schema for the extension API with namespace |full_name|. |
| 85 // Ownership remains with this object. | 89 // Ownership remains with this object. |
| 86 const base::DictionaryValue* GetSchema(const std::string& full_name); | 90 const base::DictionaryValue* GetSchema(const std::string& full_name); |
| 87 | 91 |
| 88 // Gets the APIs available to |context| given an |extension| and |url|. The | 92 // Check if an API is available to |context| given an |extension| and |url|. |
| 89 // extension or URL may not be relevant to all contexts, and may be left | 93 // The extension or URL may not be relevant to all contexts, and may be left |
| 90 // NULL/empty. | 94 // NULL/empty. |
| 91 std::set<std::string> GetAPIsForContext( | 95 bool IsNonFeatureAvailable(const std::string& name, |
|
not at google - send to devlin
2013/03/14 19:16:46
First file I'm reading: this name confuses me.
Al
cduvall
2013/03/21 22:27:55
renamed to IsNonFeatureAPIAvailable()
| |
| 92 Feature::Context context, const Extension* extension, const GURL& url); | 96 Feature::Context context, |
| 97 const Extension* extension, | |
| 98 const GURL& url); | |
| 93 | 99 |
| 94 std::set<std::string> GetAllAPINames(); | 100 std::set<std::string> GetAllAPINames(); |
| 95 | 101 |
| 96 // Gets a Feature object describing the API with the specified |full_name|. | 102 // Gets a Feature object describing the API with the specified |full_name|. |
| 97 // This can be either an API namespace (like history, or | 103 // This can be either an API namespace (like history, or |
| 98 // experimental.bookmarks), or it can be an individual function or event. | 104 // experimental.bookmarks), or it can be an individual function or event. |
| 99 virtual Feature* GetFeature(const std::string& full_name) OVERRIDE; | 105 virtual Feature* GetFeature(const std::string& full_name) OVERRIDE; |
| 100 | 106 |
| 101 // Splits a full name from the extension API into its API and child name | 107 // Splits a full name from the extension API into its API and child name |
| 102 // parts. Some examples: | 108 // parts. Some examples: |
| 103 // | 109 // |
| 104 // "bookmarks.create" -> ("bookmarks", "create") | 110 // "bookmarks.create" -> ("bookmarks", "create") |
| 105 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") | 111 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") |
| 106 // "storage.sync.set" -> ("storage", "sync.get") | 112 // "storage.sync.set" -> ("storage", "sync.get") |
| 107 // "<unknown-api>.monkey" -> ("", "") | 113 // "<unknown-api>.monkey" -> ("", "") |
| 108 // | 114 // |
| 109 // The |child_name| parameter can be be NULL if you don't need that part. | 115 // The |child_name| parameter can be be NULL if you don't need that part. |
| 110 std::string GetAPINameFromFullName(const std::string& full_name, | 116 std::string GetAPINameFromFullName(const std::string& full_name, |
| 111 std::string* child_name); | 117 std::string* child_name); |
| 112 | 118 |
| 113 void InitDefaultConfiguration(); | 119 void InitDefaultConfiguration(); |
| 114 | 120 |
| 115 // Loads the schemas registered with RegisterSchema(). | |
| 116 void LoadAllSchemas(); | |
| 117 | |
| 118 private: | 121 private: |
| 119 friend struct DefaultSingletonTraits<ExtensionAPI>; | 122 friend struct DefaultSingletonTraits<ExtensionAPI>; |
| 120 | 123 |
| 121 // Loads a schema. | 124 // Loads a schema. |
| 122 void LoadSchema(const std::string& name, const base::StringPiece& schema); | 125 void LoadSchema(const std::string& name, const base::StringPiece& schema); |
| 123 | 126 |
| 124 // Returns true if the function or event under |namespace_node| with | 127 // Returns true if the function or event under |namespace_node| with |
| 125 // the specified |child_name| is privileged, or false otherwise. If the name | 128 // the specified |child_name| is privileged, or false otherwise. If the name |
| 126 // is not found, defaults to privileged. | 129 // is not found, defaults to privileged. |
| 127 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, | 130 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, |
| 128 const std::string& child_name); | 131 const std::string& child_name); |
| 129 | 132 |
| 130 // Adds all APIs to |out| that |extension| has any permission (required or | 133 // Checks if API |name| is allowed. |
| 131 // optional) to use. | |
| 132 // NOTE: This only works for non-feature-controlled APIs. | 134 // NOTE: This only works for non-feature-controlled APIs. |
| 133 // TODO(aa): Remove this when all APIs are converted to the feature system. | 135 // TODO(aa): Remove this when all APIs are converted to the feature system. |
| 134 void GetAllowedAPIs(const Extension* extension, std::set<std::string>* out); | 136 bool IsAPIAllowed(const std::string& name, const Extension* extension); |
| 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 Loading... | |
| 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_ |
| OLD | NEW |