| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_RENDERER_API_BINDINGS_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Responds to the request with the given |request_id|, calling the callback | 63 // Responds to the request with the given |request_id|, calling the callback |
| 64 // with |response|. | 64 // with |response|. |
| 65 void CompleteRequest(int request_id, const base::ListValue& response); | 65 void CompleteRequest(int request_id, const base::ListValue& response); |
| 66 | 66 |
| 67 // Notifies the APIEventHandler to fire the corresponding event, notifying | 67 // Notifies the APIEventHandler to fire the corresponding event, notifying |
| 68 // listeners. | 68 // listeners. |
| 69 void FireEventInContext(const std::string& event_name, | 69 void FireEventInContext(const std::string& event_name, |
| 70 v8::Local<v8::Context> context, | 70 v8::Local<v8::Context> context, |
| 71 const base::ListValue& response); | 71 const base::ListValue& response); |
| 72 | 72 |
| 73 // Returns the APIBindingHooks object for the given api to allow for |
| 74 // registering custom hooks. These must be registered *before* the |
| 75 // binding is instantiated. |
| 76 // TODO(devlin): It's a little weird that we don't just expose a |
| 77 // RegisterHooks-type method. Depending on how complex the hook interface |
| 78 // is, maybe we should rethink this. Downside would be that it's less |
| 79 // efficient to register multiple hooks for the same API. |
| 80 APIBindingHooks* GetHooksForAPI(const std::string& api_name); |
| 81 |
| 73 private: | 82 private: |
| 74 // Creates a new APIBinding for the given |api_name|. | 83 // Creates a new APIBinding for the given |api_name|. |
| 75 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); | 84 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); |
| 76 | 85 |
| 77 // Handles a call into an API, adds a pending request to the | 86 // Handles a call into an API, adds a pending request to the |
| 78 // |request_handler_|, and calls |send_request_|. | 87 // |request_handler_|, and calls |send_request_|. |
| 79 void OnAPICall(const std::string& name, | 88 void OnAPICall(const std::string& name, |
| 80 std::unique_ptr<base::ListValue> arguments, | 89 std::unique_ptr<base::ListValue> arguments, |
| 81 v8::Isolate* isolate, | 90 v8::Isolate* isolate, |
| 82 v8::Local<v8::Context> context, | 91 v8::Local<v8::Context> context, |
| 83 v8::Local<v8::Function> callback); | 92 v8::Local<v8::Function> callback); |
| 84 | 93 |
| 85 // The map of cached API reference types. | 94 // The map of cached API reference types. |
| 86 ArgumentSpec::RefMap type_reference_map_; | 95 ArgumentSpec::RefMap type_reference_map_; |
| 87 | 96 |
| 88 // The request handler associated with the system. | 97 // The request handler associated with the system. |
| 89 APIRequestHandler request_handler_; | 98 APIRequestHandler request_handler_; |
| 90 | 99 |
| 91 // The event handler associated with the system. | 100 // The event handler associated with the system. |
| 92 APIEventHandler event_handler_; | 101 APIEventHandler event_handler_; |
| 93 | 102 |
| 94 // A map from api_name -> APIBinding for constructed APIs. APIBindings are | 103 // A map from api_name -> APIBinding for constructed APIs. APIBindings are |
| 95 // created lazily. | 104 // created lazily. |
| 96 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_; | 105 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_; |
| 97 | 106 |
| 107 // A map from api_name -> APIBindingHooks for registering custom hooks. |
| 108 // TODO(devlin): This map is pretty pointer-y. Is that going to be a |
| 109 // performance concern? |
| 110 std::map<std::string, std::unique_ptr<APIBindingHooks>> binding_hooks_; |
| 111 |
| 98 // The method to retrieve the DictionaryValue describing a given extension | 112 // The method to retrieve the DictionaryValue describing a given extension |
| 99 // API. Curried in for testing purposes so we can use fake APIs. | 113 // API. Curried in for testing purposes so we can use fake APIs. |
| 100 GetAPISchemaMethod get_api_schema_; | 114 GetAPISchemaMethod get_api_schema_; |
| 101 | 115 |
| 102 // The method to call when a new API call is triggered. Curried in for testing | 116 // The method to call when a new API call is triggered. Curried in for testing |
| 103 // purposes. Typically, this would send an IPC to the browser to begin the | 117 // purposes. Typically, this would send an IPC to the browser to begin the |
| 104 // function work. | 118 // function work. |
| 105 SendRequestMethod send_request_; | 119 SendRequestMethod send_request_; |
| 106 | 120 |
| 107 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); | 121 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); |
| 108 }; | 122 }; |
| 109 | 123 |
| 110 } // namespace | 124 } // namespace |
| 111 | 125 |
| 112 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ | 126 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| OLD | NEW |