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 19 matching lines...) Expand all Loading... | |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 | 31 |
| 32 class Extension; | 32 class Extension; |
| 33 class Feature; | 33 class Feature; |
| 34 | 34 |
| 35 // C++ Wrapper for the JSON API definitions in chrome/common/extensions/api/. | 35 // C++ Wrapper for the JSON API definitions in chrome/common/extensions/api/. |
| 36 // | 36 // |
| 37 // WARNING: This class is accessed on multiple threads in the browser process | 37 // WARNING: This class is accessed on multiple threads in the browser process |
| 38 // (see ExtensionFunctionDispatcher). No state should be modified after | 38 // (see ExtensionFunctionDispatcher). No state should be modified after |
| 39 // construction. | 39 // construction. |
| 40 class ExtensionAPI : public FeatureProvider { | 40 class ExtensionAPI { |
| 41 public: | 41 public: |
| 42 // Returns a single shared instance of this class. This is the typical use | 42 // Returns a single shared instance of this class. This is the typical use |
| 43 // case in Chrome. | 43 // case in Chrome. |
| 44 // | 44 // |
| 45 // TODO(aa): Make this const to enforce thread-safe usage. | 45 // TODO(aa): Make this const to enforce thread-safe usage. |
| 46 static ExtensionAPI* GetSharedInstance(); | 46 static ExtensionAPI* GetSharedInstance(); |
| 47 | 47 |
| 48 // Creates a new instance configured the way ExtensionAPI typically is in | 48 // Creates a new instance configured the way ExtensionAPI typically is in |
| 49 // Chrome. Use the default constructor to get a clean instance. | 49 // Chrome. Use the default constructor to get a clean instance. |
| 50 static ExtensionAPI* CreateWithDefaultConfiguration(); | 50 static ExtensionAPI* CreateWithDefaultConfiguration(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 81 // extension process. They cannot be called from extension code running in | 81 // extension process. They cannot be called from extension code running in |
| 82 // content scripts, or other low-privileged contexts. | 82 // content scripts, or other low-privileged contexts. |
| 83 bool IsPrivileged(const std::string& name); | 83 bool IsPrivileged(const std::string& name); |
| 84 | 84 |
| 85 // Gets the schema for the extension API with namespace |full_name|. | 85 // Gets the schema for the extension API with namespace |full_name|. |
| 86 // Ownership remains with this object. | 86 // Ownership remains with this object. |
| 87 const base::DictionaryValue* GetSchema(const std::string& full_name); | 87 const base::DictionaryValue* GetSchema(const std::string& full_name); |
| 88 | 88 |
| 89 std::set<std::string> GetAllAPINames(); | 89 std::set<std::string> GetAllAPINames(); |
| 90 | 90 |
| 91 // Gets a Feature object describing the API with the specified |full_name|. | |
| 92 // This can be either an API namespace (like history, or | |
| 93 // experimental.bookmarks), or it can be an individual function or event. | |
| 94 virtual Feature* GetFeature(const std::string& full_name) OVERRIDE; | |
| 95 | |
| 96 // Splits a full name from the extension API into its API and child name | 91 // Splits a full name from the extension API into its API and child name |
| 97 // parts. Some examples: | 92 // parts. Some examples: |
| 98 // | 93 // |
| 99 // "bookmarks.create" -> ("bookmarks", "create") | 94 // "bookmarks.create" -> ("bookmarks", "create") |
| 100 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") | 95 // "experimental.input.ui.cursorUp" -> ("experimental.input.ui", "cursorUp") |
| 101 // "storage.sync.set" -> ("storage", "sync.get") | 96 // "storage.sync.set" -> ("storage", "sync.get") |
| 102 // "<unknown-api>.monkey" -> ("", "") | 97 // "<unknown-api>.monkey" -> ("", "") |
| 103 // | 98 // |
| 104 // The |child_name| parameter can be be NULL if you don't need that part. | 99 // The |child_name| parameter can be be NULL if you don't need that part. |
| 105 std::string GetAPINameFromFullName(const std::string& full_name, | 100 std::string GetAPINameFromFullName(const std::string& full_name, |
| 106 std::string* child_name); | 101 std::string* child_name); |
| 107 | 102 |
| 108 void InitDefaultConfiguration(); | 103 void InitDefaultConfiguration(); |
| 109 | 104 |
| 105 // Gets a feature from any dependency provider registered with ExtensionAPI. | |
| 106 Feature* GetFeatureDependency(const std::string& dependency_name); | |
|
not at google - send to devlin
2013/03/26 00:34:48
This doesn't appear to be used outside of this cla
cduvall
2013/03/26 19:24:05
It's used in the unit test.
| |
| 107 | |
| 110 private: | 108 private: |
| 111 friend struct DefaultSingletonTraits<ExtensionAPI>; | 109 friend struct DefaultSingletonTraits<ExtensionAPI>; |
| 112 | 110 |
| 113 // Loads a schema. | 111 // Loads a schema. |
| 114 void LoadSchema(const std::string& name, const base::StringPiece& schema); | 112 void LoadSchema(const std::string& name, const base::StringPiece& schema); |
| 115 | 113 |
| 116 // Returns true if the function or event under |namespace_node| with | 114 // Returns true if the function or event under |namespace_node| with |
| 117 // the specified |child_name| is privileged, or false otherwise. If the name | 115 // the specified |child_name| is privileged, or false otherwise. If the name |
| 118 // is not found, defaults to privileged. | 116 // is not found, defaults to privileged. |
| 119 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, | 117 bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 130 // The extension or URL may not be relevant to all contexts, and may be left | 128 // The extension or URL may not be relevant to all contexts, and may be left |
| 131 // NULL/empty. | 129 // NULL/empty. |
| 132 bool IsNonFeatureAPIAvailable(const std::string& name, | 130 bool IsNonFeatureAPIAvailable(const std::string& name, |
| 133 Feature::Context context, | 131 Feature::Context context, |
| 134 const Extension* extension, | 132 const Extension* extension, |
| 135 const GURL& url); | 133 const GURL& url); |
| 136 | 134 |
| 137 // Returns true if the API uses the feature system. | 135 // Returns true if the API uses the feature system. |
| 138 bool UsesFeatureSystem(const std::string& full_name); | 136 bool UsesFeatureSystem(const std::string& full_name); |
| 139 | 137 |
| 140 // Gets a feature from any dependency provider. | 138 // Attempts to get a feature from any dependency provider, and returns NULL |
| 141 Feature* GetFeatureDependency(const std::string& dependency_name); | 139 // if the feature could not be found. |
| 142 | 140 Feature* TryGetFeatureDependency(const std::string& dependency_name); |
| 143 // Adds dependent schemas to |out| as determined by the "dependencies" | |
| 144 // property. | |
| 145 // TODO(aa): Consider making public and adding tests. | |
| 146 void ResolveDependencies(std::set<std::string>* out); | |
| 147 | |
| 148 // Adds any APIs listed in "dependencies" found in the schema for |api_name| | |
| 149 // but not in |excluding| to |out|. | |
| 150 void GetMissingDependencies( | |
| 151 const std::string& api_name, | |
| 152 const std::set<std::string>& excluding, | |
| 153 std::set<std::string>* out); | |
| 154 | 141 |
| 155 // Checks if an API is *entirely* privileged. This won't include APIs such as | 142 // Checks if an API is *entirely* privileged. This won't include APIs such as |
| 156 // "storage" which is entirely unprivileged, nor "extension" which has | 143 // "storage" which is entirely unprivileged, nor "extension" which has |
| 157 // unprivileged components. | 144 // unprivileged components. |
| 158 bool IsPrivilegedAPI(const std::string& name); | 145 bool IsPrivilegedAPI(const std::string& name); |
| 159 | 146 |
| 160 // Map from each API that hasn't been loaded yet to the schema which defines | 147 // Map from each API that hasn't been loaded yet to the schema which defines |
| 161 // it. Note that there may be multiple APIs per schema. | 148 // it. Note that there may be multiple APIs per schema. |
| 162 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; | 149 typedef std::map<std::string, base::StringPiece> UnloadedSchemaMap; |
| 163 UnloadedSchemaMap unloaded_schemas_; | 150 UnloadedSchemaMap unloaded_schemas_; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 182 // FeatureProviders used for resolving dependencies. | 169 // FeatureProviders used for resolving dependencies. |
| 183 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; | 170 typedef std::map<std::string, FeatureProvider*> FeatureProviderMap; |
| 184 FeatureProviderMap dependency_providers_; | 171 FeatureProviderMap dependency_providers_; |
| 185 | 172 |
| 186 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 173 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |
| 187 }; | 174 }; |
| 188 | 175 |
| 189 } // extensions | 176 } // extensions |
| 190 | 177 |
| 191 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ | 178 #endif // CHROME_COMMON_EXTENSIONS_API_EXTENSION_API_H_ |
| OLD | NEW |