| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ | |
| 6 #define EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/strings/string_piece.h" | |
| 14 #include "extensions/renderer/api_binding_hooks_delegate.h" | |
| 15 #include "extensions/renderer/api_binding_types.h" | |
| 16 #include "v8/include/v8.h" | |
| 17 | |
| 18 namespace extensions { | |
| 19 | |
| 20 // A test class to simply adding custom events or handlers for API hooks. | |
| 21 class APIBindingHooksTestDelegate : public APIBindingHooksDelegate { | |
| 22 public: | |
| 23 APIBindingHooksTestDelegate(); | |
| 24 ~APIBindingHooksTestDelegate() override; | |
| 25 | |
| 26 using CustomEventFactory = base::Callback<v8::Local<v8::Value>( | |
| 27 v8::Local<v8::Context>, | |
| 28 const binding::RunJSFunctionSync& run_js, | |
| 29 const std::string& event_name)>; | |
| 30 | |
| 31 using RequestHandler = base::Callback<APIBindingHooks::RequestResult( | |
| 32 const APISignature*, | |
| 33 v8::Local<v8::Context> context, | |
| 34 std::vector<v8::Local<v8::Value>>*, | |
| 35 const APITypeReferenceMap&)>; | |
| 36 | |
| 37 using TemplateInitializer = base::Callback<void(v8::Isolate*, | |
| 38 v8::Local<v8::ObjectTemplate>, | |
| 39 const APITypeReferenceMap&)>; | |
| 40 | |
| 41 // Adds a custom |handler| for the method with the given |name|. | |
| 42 void AddHandler(base::StringPiece name, const RequestHandler& handler); | |
| 43 | |
| 44 // Creates events with the given factory. | |
| 45 void SetCustomEvent(const CustomEventFactory& custom_event); | |
| 46 | |
| 47 void SetTemplateInitializer(const TemplateInitializer& initializer); | |
| 48 | |
| 49 // APIBindingHooksDelegate: | |
| 50 bool CreateCustomEvent(v8::Local<v8::Context> context, | |
| 51 const binding::RunJSFunctionSync& run_js_sync, | |
| 52 const std::string& event_name, | |
| 53 v8::Local<v8::Value>* event_out) override; | |
| 54 APIBindingHooks::RequestResult HandleRequest( | |
| 55 const std::string& method_name, | |
| 56 const APISignature* signature, | |
| 57 v8::Local<v8::Context> context, | |
| 58 std::vector<v8::Local<v8::Value>>* arguments, | |
| 59 const APITypeReferenceMap& refs) override; | |
| 60 void InitializeTemplate(v8::Isolate* isolate, | |
| 61 v8::Local<v8::ObjectTemplate> object_template, | |
| 62 const APITypeReferenceMap& type_refs) override; | |
| 63 | |
| 64 private: | |
| 65 std::map<std::string, RequestHandler> request_handlers_; | |
| 66 CustomEventFactory custom_event_; | |
| 67 TemplateInitializer template_initializer_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(APIBindingHooksTestDelegate); | |
| 70 }; | |
| 71 | |
| 72 } // namespace extensions | |
| 73 | |
| 74 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ | |
| OLD | NEW |