| 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 13 matching lines...) Expand all  Loading... | 
|   24 } |   24 } | 
|   25  |   25  | 
|   26 class GURL; |   26 class GURL; | 
|   27  |   27  | 
|   28 namespace extensions { |   28 namespace extensions { | 
|   29  |   29  | 
|   30 class Extension; |   30 class Extension; | 
|   31 class ExtensionsClient; |   31 class ExtensionsClient; | 
|   32 class Feature; |   32 class Feature; | 
|   33  |   33  | 
 |   34 // Used when testing Feature availability to specify whether feature aliases | 
 |   35 // should be ignored or not - i.e. if a feature exposed only through an alias | 
 |   36 // should be considered available. | 
 |   37 enum class CheckAliasStatus { | 
 |   38   // Includes aliases in an availability check. | 
 |   39   ALLOWED, | 
 |   40   // Ignores aliases during an availability check. | 
 |   41   NOT_ALLOWED | 
 |   42 }; | 
 |   43  | 
|   34 // C++ Wrapper for the JSON API definitions in chrome/common/extensions/api/. |   44 // C++ Wrapper for the JSON API definitions in chrome/common/extensions/api/. | 
|   35 // |   45 // | 
|   36 // WARNING: This class is accessed on multiple threads in the browser process |   46 // WARNING: This class is accessed on multiple threads in the browser process | 
|   37 // (see ExtensionFunctionDispatcher). No state should be modified after |   47 // (see ExtensionFunctionDispatcher). No state should be modified after | 
|   38 // construction. |   48 // construction. | 
|   39 class ExtensionAPI { |   49 class ExtensionAPI { | 
|   40  public: |   50  public: | 
|   41   // Returns a single shared instance of this class. This is the typical use |   51   // Returns a single shared instance of this class. This is the typical use | 
|   42   // case in Chrome. |   52   // case in Chrome. | 
|   43   // |   53   // | 
| (...skipping 35 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 |   89   // Returns true if the API item called |api_full_name| and all of its | 
|   80   // dependencies are available in |context|. |   90   // dependencies are available in |context|. | 
|   81   // |   91   // | 
|   82   // |api_full_name| can be either a namespace name (like "bookmarks") or a |   92   // |api_full_name| can be either a namespace name (like "bookmarks") or a | 
|   83   // member name (like "bookmarks.create"). |   93   // member name (like "bookmarks.create"). | 
|   84   // |   94   // | 
|   85   // Depending on the configuration of |api| (in _api_features.json), either |   95   // Depending on the configuration of |api| (in _api_features.json), either | 
|   86   // |extension| or |url| (or both) may determine its availability, but this is |   96   // |extension| or |url| (or both) may determine its availability, but this is | 
|   87   // up to the configuration of the individual feature. |   97   // up to the configuration of the individual feature. | 
|   88   // |   98   // | 
 |   99   // |alias_status| determines whether it should be tested whether the API | 
 |  100   // is available through an alias. | 
 |  101   // | 
|   89   // TODO(kalman): This is just an unnecessary combination of finding a Feature |  102   // TODO(kalman): This is just an unnecessary combination of finding a Feature | 
|   90   // then calling Feature::IsAvailableToContext(..) on it. Just provide that |  103   // then calling Feature::IsAvailableToContext(..) on it. Just provide that | 
|   91   // FindFeature function and let callers compose if they want. |  104   // FindFeature function and let callers compose if they want. | 
|   92   Feature::Availability IsAvailable(const std::string& api_full_name, |  105   Feature::Availability IsAvailable(const std::string& api_full_name, | 
|   93                                     const Extension* extension, |  106                                     const Extension* extension, | 
|   94                                     Feature::Context context, |  107                                     Feature::Context context, | 
|   95                                     const GURL& url); |  108                                     const GURL& url, | 
 |  109                                     CheckAliasStatus alias_status); | 
|   96  |  110  | 
|   97   // Determines whether an API, or any parts of that API, are available in |  111   // Determines whether an API, or any parts of that API, can be exposed to | 
|   98   // |context|. |  112   // |context|. | 
 |  113   // | 
 |  114   // |alias_status| determines whether it should be tested whether the API | 
 |  115   // is available through an alias. | 
 |  116   // | 
|   99   bool IsAnyFeatureAvailableToContext(const Feature& api, |  117   bool IsAnyFeatureAvailableToContext(const Feature& api, | 
|  100                                       const Extension* extension, |  118                                       const Extension* extension, | 
|  101                                       Feature::Context context, |  119                                       Feature::Context context, | 
|  102                                       const GURL& url); |  120                                       const GURL& url, | 
 |  121                                       CheckAliasStatus alias_status); | 
|  103  |  122  | 
|  104   // Gets the StringPiece for the schema specified by |api_name|. |  123   // Gets the StringPiece for the schema specified by |api_name|. | 
|  105   base::StringPiece GetSchemaStringPiece(const std::string& api_name); |  124   base::StringPiece GetSchemaStringPiece(const std::string& api_name); | 
|  106  |  125  | 
|  107   // Gets the schema for the extension API with namespace |full_name|. |  126   // Gets the schema for the extension API with namespace |full_name|. | 
|  108   // Ownership remains with this object. |  127   // Ownership remains with this object. | 
|  109   // TODO(devlin): Now that we use GetSchemaStringPiece() in the renderer, we |  128   // TODO(devlin): Now that we use GetSchemaStringPiece() in the renderer, we | 
|  110   // may not really need this anymore. |  129   // may not really need this anymore. | 
|  111   const base::DictionaryValue* GetSchema(const std::string& full_name); |  130   const base::DictionaryValue* GetSchema(const std::string& full_name); | 
|  112  |  131  | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  129  private: |  148  private: | 
|  130   FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |  149   FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 
|  131   friend struct base::DefaultSingletonTraits<ExtensionAPI>; |  150   friend struct base::DefaultSingletonTraits<ExtensionAPI>; | 
|  132  |  151  | 
|  133   void InitDefaultConfiguration(); |  152   void InitDefaultConfiguration(); | 
|  134  |  153  | 
|  135   // Returns true if there exists an API with |name|. Declared virtual for |  154   // Returns true if there exists an API with |name|. Declared virtual for | 
|  136   // testing purposes. |  155   // testing purposes. | 
|  137   virtual bool IsKnownAPI(const std::string& name, ExtensionsClient* client); |  156   virtual bool IsKnownAPI(const std::string& name, ExtensionsClient* client); | 
|  138  |  157  | 
 |  158   // Checks if |full_name| is available to provided context and extension under | 
 |  159   // associated API's alias name. | 
 |  160   Feature::Availability IsAliasAvailable(const std::string& full_name, | 
 |  161                                          Feature* api, | 
 |  162                                          const Extension* extension, | 
 |  163                                          Feature::Context context, | 
 |  164                                          const GURL& url); | 
 |  165  | 
|  139   bool default_configuration_initialized_; |  166   bool default_configuration_initialized_; | 
|  140  |  167  | 
|  141   // Loads a schema. |  168   // Loads a schema. | 
|  142   void LoadSchema(const std::string& name, const base::StringPiece& schema); |  169   void LoadSchema(const std::string& name, const base::StringPiece& schema); | 
|  143  |  170  | 
|  144   // Schemas for each namespace. |  171   // Schemas for each namespace. | 
|  145   using SchemaMap = |  172   using SchemaMap = | 
|  146       std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; |  173       std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; | 
|  147   SchemaMap schemas_; |  174   SchemaMap schemas_; | 
|  148  |  175  | 
|  149   using StringPieceMap = std::map<std::string, base::StringPiece>; |  176   using StringPieceMap = std::map<std::string, base::StringPiece>; | 
|  150   StringPieceMap schema_strings_; |  177   StringPieceMap schema_strings_; | 
|  151  |  178  | 
|  152   // FeatureProviders used for resolving dependencies. |  179   // FeatureProviders used for resolving dependencies. | 
|  153   typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; |  180   typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; | 
|  154   FeatureProviderMap dependency_providers_; |  181   FeatureProviderMap dependency_providers_; | 
|  155  |  182  | 
|  156   DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |  183   DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 
|  157 }; |  184 }; | 
|  158  |  185  | 
|  159 }  // namespace extensions |  186 }  // namespace extensions | 
|  160  |  187  | 
|  161 #endif  // EXTENSIONS_COMMON_EXTENSION_API_H_ |  188 #endif  // EXTENSIONS_COMMON_EXTENSION_API_H_ | 
| OLD | NEW |