OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
Ken Rockot(use gerrit already)
2017/04/18 21:42:11
nice
| |
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 CONTENT_SHELL_RENDERER_LAYOUT_TEST_INTERFACE_REGISTRY_JS_WRAPPER_H_ | |
6 #define CONTENT_SHELL_RENDERER_LAYOUT_TEST_INTERFACE_REGISTRY_JS_WRAPPER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/macros.h" | |
11 #include "gin/handle.h" | |
12 #include "gin/object_template_builder.h" | |
13 #include "gin/wrappable.h" | |
14 #include "mojo/public/cpp/system/message_pipe.h" | |
15 #include "v8/include/v8.h" | |
16 | |
17 namespace service_manager { | |
18 class InterfaceRegistry; | |
19 } | |
20 | |
21 namespace content { | |
22 | |
23 // A JS wrapper around service_manager::InterfaceRegistry that allows connecting | |
24 // to | |
25 // interfaces exposed by the renderer for testing. | |
26 class InterfaceRegistryJsWrapper | |
27 : public gin::Wrappable<InterfaceRegistryJsWrapper> { | |
28 public: | |
29 static gin::Handle<InterfaceRegistryJsWrapper> Create( | |
30 v8::Isolate* isolate, | |
31 v8::Local<v8::Context> context, | |
32 service_manager::InterfaceRegistry* interface_registry); | |
33 | |
34 // gin::Wrappable<InterfaceRegistryJsWrapper> overrides. | |
35 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | |
36 v8::Isolate* isolate) override; | |
37 | |
38 // JS interface implementation. | |
39 mojo::Handle GetLocalInterfaceForTesting(const std::string& interface_name); | |
40 | |
41 static gin::WrapperInfo kWrapperInfo; | |
42 static const char kPerFrameModuleName[]; | |
43 static const char kPerProcessModuleName[]; | |
44 | |
45 private: | |
46 using ScopedJsFactory = | |
47 v8::Persistent<v8::Function, v8::CopyablePersistentTraits<v8::Function>>; | |
48 | |
49 InterfaceRegistryJsWrapper( | |
50 v8::Isolate* isolate, | |
51 v8::Local<v8::Context> context, | |
52 base::WeakPtr<service_manager::InterfaceRegistry> interface_registry); | |
53 ~InterfaceRegistryJsWrapper() override; | |
54 | |
55 void CallJsFactory(const ScopedJsFactory& factory, | |
56 mojo::ScopedMessagePipeHandle pipe); | |
57 | |
58 static void ClearContext( | |
59 const v8::WeakCallbackInfo<InterfaceRegistryJsWrapper>& data); | |
60 | |
61 v8::Isolate* isolate_; | |
62 v8::Global<v8::Context> context_; | |
63 base::WeakPtr<service_manager::InterfaceRegistry> interface_registry_; | |
64 | |
65 base::WeakPtrFactory<InterfaceRegistryJsWrapper> weak_factory_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistryJsWrapper); | |
68 }; | |
69 | |
70 } // namespace content | |
71 | |
72 #endif // CONTENT_SHELL_RENDERER_LAYOUT_TEST_INTERFACE_REGISTRY_JS_WRAPPER_H_ | |
OLD | NEW |