Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_COMMON_EXTENSION_API_H_ | 5 #ifndef EXTENSIONS_COMMON_EXTENSION_API_H_ |
| 6 #define EXTENSIONS_COMMON_EXTENSION_API_H_ | 6 #define EXTENSIONS_COMMON_EXTENSION_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // Returns true if the API item called |api_full_name| and all of its | 79 // Returns true if the API item called |api_full_name| and all of its |
| 80 // dependencies are available in |context|. | 80 // dependencies are available in |context|. |
| 81 // | 81 // |
| 82 // |api_full_name| can be either a namespace name (like "bookmarks") or a | 82 // |api_full_name| can be either a namespace name (like "bookmarks") or a |
| 83 // member name (like "bookmarks.create"). | 83 // member name (like "bookmarks.create"). |
| 84 // | 84 // |
| 85 // Depending on the configuration of |api| (in _api_features.json), either | 85 // Depending on the configuration of |api| (in _api_features.json), either |
| 86 // |extension| or |url| (or both) may determine its availability, but this is | 86 // |extension| or |url| (or both) may determine its availability, but this is |
| 87 // up to the configuration of the individual feature. | 87 // up to the configuration of the individual feature. |
| 88 // | 88 // |
| 89 // |allow_alias| determines whether it should be tested whether the API | |
| 90 // is available through an alias. | |
| 91 // | |
| 89 // TODO(kalman): This is just an unnecessary combination of finding a Feature | 92 // TODO(kalman): This is just an unnecessary combination of finding a Feature |
| 90 // then calling Feature::IsAvailableToContext(..) on it. Just provide that | 93 // then calling Feature::IsAvailableToContext(..) on it. Just provide that |
| 91 // FindFeature function and let callers compose if they want. | 94 // FindFeature function and let callers compose if they want. |
| 92 Feature::Availability IsAvailable(const std::string& api_full_name, | 95 Feature::Availability IsAvailable(const std::string& api_full_name, |
| 93 const Extension* extension, | 96 const Extension* extension, |
| 94 Feature::Context context, | 97 Feature::Context context, |
| 95 const GURL& url); | 98 const GURL& url, |
| 99 bool allow_alias); | |
|
Devlin
2016/11/14 18:03:56
I think this would be more clear with an enum, ALL
tbarzic
2016/11/15 04:45:07
Done.
| |
| 96 | 100 |
| 97 // Determines whether an API, or any parts of that API, are available in | 101 // Determines whether an API, or any parts of that API, can be exposed to |
| 98 // |context|. | 102 // |context|. |
| 103 // | |
| 104 // |allow_alias| determines whether it should be tested whether the API | |
| 105 // is available through an alias. | |
| 106 // | |
| 99 bool IsAnyFeatureAvailableToContext(const Feature& api, | 107 bool IsAnyFeatureAvailableToContext(const Feature& api, |
| 100 const Extension* extension, | 108 const Extension* extension, |
| 101 Feature::Context context, | 109 Feature::Context context, |
| 102 const GURL& url); | 110 const GURL& url, |
| 111 bool allow_alias); | |
|
Devlin
2016/11/14 18:03:56
ditto
tbarzic
2016/11/15 04:45:07
Done.
| |
| 103 | 112 |
| 104 // Gets the StringPiece for the schema specified by |api_name|. | 113 // Gets the StringPiece for the schema specified by |api_name|. |
| 105 base::StringPiece GetSchemaStringPiece(const std::string& api_name); | 114 base::StringPiece GetSchemaStringPiece(const std::string& api_name); |
| 106 | 115 |
| 107 // Gets the schema for the extension API with namespace |full_name|. | 116 // Gets the schema for the extension API with namespace |full_name|. |
| 108 // Ownership remains with this object. | 117 // Ownership remains with this object. |
| 109 // TODO(devlin): Now that we use GetSchemaStringPiece() in the renderer, we | 118 // TODO(devlin): Now that we use GetSchemaStringPiece() in the renderer, we |
| 110 // may not really need this anymore. | 119 // may not really need this anymore. |
| 111 const base::DictionaryValue* GetSchema(const std::string& full_name); | 120 const base::DictionaryValue* GetSchema(const std::string& full_name); |
| 112 | 121 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 129 private: | 138 private: |
| 130 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 139 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |
| 131 friend struct base::DefaultSingletonTraits<ExtensionAPI>; | 140 friend struct base::DefaultSingletonTraits<ExtensionAPI>; |
| 132 | 141 |
| 133 void InitDefaultConfiguration(); | 142 void InitDefaultConfiguration(); |
| 134 | 143 |
| 135 // Returns true if there exists an API with |name|. Declared virtual for | 144 // Returns true if there exists an API with |name|. Declared virtual for |
| 136 // testing purposes. | 145 // testing purposes. |
| 137 virtual bool IsKnownAPI(const std::string& name, ExtensionsClient* client); | 146 virtual bool IsKnownAPI(const std::string& name, ExtensionsClient* client); |
| 138 | 147 |
| 148 // Checks if |full_name| is available to provided context and extension under | |
| 149 // associated API's alias name. | |
| 150 Feature::Availability IsAliasAvailable(const std::string& full_name, | |
| 151 Feature* api, | |
| 152 const Extension* extension, | |
| 153 Feature::Context context, | |
| 154 const GURL& url); | |
| 155 | |
| 139 bool default_configuration_initialized_; | 156 bool default_configuration_initialized_; |
| 140 | 157 |
| 141 // Loads a schema. | 158 // Loads a schema. |
| 142 void LoadSchema(const std::string& name, const base::StringPiece& schema); | 159 void LoadSchema(const std::string& name, const base::StringPiece& schema); |
| 143 | 160 |
| 144 // Schemas for each namespace. | 161 // Schemas for each namespace. |
| 145 using SchemaMap = | 162 using SchemaMap = |
| 146 std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; | 163 std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; |
| 147 SchemaMap schemas_; | 164 SchemaMap schemas_; |
| 148 | 165 |
| 149 using StringPieceMap = std::map<std::string, base::StringPiece>; | 166 using StringPieceMap = std::map<std::string, base::StringPiece>; |
| 150 StringPieceMap schema_strings_; | 167 StringPieceMap schema_strings_; |
| 151 | 168 |
| 152 // FeatureProviders used for resolving dependencies. | 169 // FeatureProviders used for resolving dependencies. |
| 153 typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; | 170 typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; |
| 154 FeatureProviderMap dependency_providers_; | 171 FeatureProviderMap dependency_providers_; |
| 155 | 172 |
| 156 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 173 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |
| 157 }; | 174 }; |
| 158 | 175 |
| 159 } // namespace extensions | 176 } // namespace extensions |
| 160 | 177 |
| 161 #endif // EXTENSIONS_COMMON_EXTENSION_API_H_ | 178 #endif // EXTENSIONS_COMMON_EXTENSION_API_H_ |
| OLD | NEW |