OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_BINDING_HOOKS_TEST_DELEGATE_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ |
6 #define EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ | 6 #define EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 v8::Local<v8::Context>, | 27 v8::Local<v8::Context>, |
28 const binding::RunJSFunctionSync& run_js, | 28 const binding::RunJSFunctionSync& run_js, |
29 const std::string& event_name)>; | 29 const std::string& event_name)>; |
30 | 30 |
31 using RequestHandler = base::Callback<APIBindingHooks::RequestResult( | 31 using RequestHandler = base::Callback<APIBindingHooks::RequestResult( |
32 const APISignature*, | 32 const APISignature*, |
33 v8::Local<v8::Context> context, | 33 v8::Local<v8::Context> context, |
34 std::vector<v8::Local<v8::Value>>*, | 34 std::vector<v8::Local<v8::Value>>*, |
35 const APITypeReferenceMap&)>; | 35 const APITypeReferenceMap&)>; |
36 | 36 |
| 37 using TemplateInitializer = base::Callback<void(v8::Isolate*, |
| 38 v8::Local<v8::ObjectTemplate>, |
| 39 const APITypeReferenceMap&)>; |
| 40 |
37 // Adds a custom |handler| for the method with the given |name|. | 41 // Adds a custom |handler| for the method with the given |name|. |
38 void AddHandler(base::StringPiece name, const RequestHandler& handler); | 42 void AddHandler(base::StringPiece name, const RequestHandler& handler); |
39 | 43 |
40 // Creates events with the given factory. | 44 // Creates events with the given factory. |
41 void SetCustomEvent(const CustomEventFactory& custom_event); | 45 void SetCustomEvent(const CustomEventFactory& custom_event); |
42 | 46 |
| 47 void SetTemplateInitializer(const TemplateInitializer& initializer); |
| 48 |
43 // APIBindingHooksDelegate: | 49 // APIBindingHooksDelegate: |
44 bool CreateCustomEvent(v8::Local<v8::Context> context, | 50 bool CreateCustomEvent(v8::Local<v8::Context> context, |
45 const binding::RunJSFunctionSync& run_js_sync, | 51 const binding::RunJSFunctionSync& run_js_sync, |
46 const std::string& event_name, | 52 const std::string& event_name, |
47 v8::Local<v8::Value>* event_out) override; | 53 v8::Local<v8::Value>* event_out) override; |
48 APIBindingHooks::RequestResult HandleRequest( | 54 APIBindingHooks::RequestResult HandleRequest( |
49 const std::string& method_name, | 55 const std::string& method_name, |
50 const APISignature* signature, | 56 const APISignature* signature, |
51 v8::Local<v8::Context> context, | 57 v8::Local<v8::Context> context, |
52 std::vector<v8::Local<v8::Value>>* arguments, | 58 std::vector<v8::Local<v8::Value>>* arguments, |
53 const APITypeReferenceMap& refs) override; | 59 const APITypeReferenceMap& refs) override; |
| 60 void InitializeTemplate(v8::Isolate* isolate, |
| 61 v8::Local<v8::ObjectTemplate> object_template, |
| 62 const APITypeReferenceMap& type_refs) override; |
54 | 63 |
55 private: | 64 private: |
56 std::map<std::string, RequestHandler> request_handlers_; | 65 std::map<std::string, RequestHandler> request_handlers_; |
57 CustomEventFactory custom_event_; | 66 CustomEventFactory custom_event_; |
| 67 TemplateInitializer template_initializer_; |
58 | 68 |
59 DISALLOW_COPY_AND_ASSIGN(APIBindingHooksTestDelegate); | 69 DISALLOW_COPY_AND_ASSIGN(APIBindingHooksTestDelegate); |
60 }; | 70 }; |
61 | 71 |
62 } // namespace extensions | 72 } // namespace extensions |
63 | 73 |
64 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ | 74 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ |
OLD | NEW |