Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: extensions/renderer/api_binding_hooks_test_delegate.h

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_
OLDNEW
« no previous file with comments | « extensions/renderer/api_binding_hooks_delegate.cc ('k') | extensions/renderer/api_binding_hooks_test_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698