Chromium Code Reviews| 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 APIBindingHooks* GetHooksForAPI(const std::string& api_name); | |
|
jbroman
2016/12/08 16:58:56
The use of GetHooksForAPI to do the registration s
Devlin
2016/12/08 19:12:03
I wasn't sure there was much useful to test here (
| |
| 77 | |
|
jbroman
2016/12/08 16:58:56
Is there a reason for the asymmetry, where API sch
Devlin
2016/12/08 19:12:03
Let's say we have a custom hook (call it CustomHoo
| |
| 73 private: | 78 private: |
| 74 // Creates a new APIBinding for the given |api_name|. | 79 // Creates a new APIBinding for the given |api_name|. |
| 75 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); | 80 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); |
| 76 | 81 |
| 77 // Handles a call into an API, adds a pending request to the | 82 // Handles a call into an API, adds a pending request to the |
| 78 // |request_handler_|, and calls |send_request_|. | 83 // |request_handler_|, and calls |send_request_|. |
| 79 void OnAPICall(const std::string& name, | 84 void OnAPICall(const std::string& name, |
| 80 std::unique_ptr<base::ListValue> arguments, | 85 std::unique_ptr<base::ListValue> arguments, |
| 81 v8::Isolate* isolate, | 86 v8::Isolate* isolate, |
| 82 v8::Local<v8::Context> context, | 87 v8::Local<v8::Context> context, |
| 83 v8::Local<v8::Function> callback); | 88 v8::Local<v8::Function> callback); |
| 84 | 89 |
| 85 // The map of cached API reference types. | 90 // The map of cached API reference types. |
| 86 ArgumentSpec::RefMap type_reference_map_; | 91 ArgumentSpec::RefMap type_reference_map_; |
| 87 | 92 |
| 88 // The request handler associated with the system. | 93 // The request handler associated with the system. |
| 89 APIRequestHandler request_handler_; | 94 APIRequestHandler request_handler_; |
| 90 | 95 |
| 91 // The event handler associated with the system. | 96 // The event handler associated with the system. |
| 92 APIEventHandler event_handler_; | 97 APIEventHandler event_handler_; |
| 93 | 98 |
| 94 // A map from api_name -> APIBinding for constructed APIs. APIBindings are | 99 // A map from api_name -> APIBinding for constructed APIs. APIBindings are |
| 95 // created lazily. | 100 // created lazily. |
| 96 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_; | 101 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_; |
| 97 | 102 |
| 103 // A map from api_name -> APIBindingHooks for registering custom hooks. | |
| 104 std::map<std::string, std::unique_ptr<APIBindingHooks>> binding_hooks_; | |
|
jbroman
2016/12/08 16:58:56
We might want to watch out for this later -- it is
Devlin
2016/12/08 19:12:03
Added a note in the code.
| |
| 105 | |
| 98 // The method to retrieve the DictionaryValue describing a given extension | 106 // The method to retrieve the DictionaryValue describing a given extension |
| 99 // API. Curried in for testing purposes so we can use fake APIs. | 107 // API. Curried in for testing purposes so we can use fake APIs. |
| 100 GetAPISchemaMethod get_api_schema_; | 108 GetAPISchemaMethod get_api_schema_; |
| 101 | 109 |
| 102 // The method to call when a new API call is triggered. Curried in for testing | 110 // 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 | 111 // purposes. Typically, this would send an IPC to the browser to begin the |
| 104 // function work. | 112 // function work. |
| 105 SendRequestMethod send_request_; | 113 SendRequestMethod send_request_; |
| 106 | 114 |
| 107 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); | 115 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); |
| 108 }; | 116 }; |
| 109 | 117 |
| 110 } // namespace | 118 } // namespace |
| 111 | 119 |
| 112 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ | 120 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| OLD | NEW |