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