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 // Adds a custom |handler| for the method with the given |name|. |
| 38 void AddHandler(base::StringPiece name, const RequestHandler& handler); |
| 39 |
| 40 // Creates events with the given factory. |
| 41 void SetCustomEvent(const CustomEventFactory& custom_event); |
| 42 |
| 43 // APIBindingHooksDelegate: |
| 44 bool CreateCustomEvent(v8::Local<v8::Context> context, |
| 45 const binding::RunJSFunctionSync& run_js_sync, |
| 46 const std::string& event_name, |
| 47 v8::Local<v8::Value>* event_out) override; |
| 48 APIBindingHooks::RequestResult HandleRequest( |
| 49 const std::string& method_name, |
| 50 const APISignature* signature, |
| 51 v8::Local<v8::Context> context, |
| 52 std::vector<v8::Local<v8::Value>>* arguments, |
| 53 const APITypeReferenceMap& refs) override; |
| 54 |
| 55 private: |
| 56 std::map<std::string, RequestHandler> request_handlers_; |
| 57 CustomEventFactory custom_event_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(APIBindingHooksTestDelegate); |
| 60 }; |
| 61 |
| 62 } // namespace extensions |
| 63 |
| 64 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_TEST_DELEGATE_H_ |
OLD | NEW |