OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 CONTENT_RENDERER_MOJO_INTERFACE_PROVIDER_JS_WRAPPER_H_ |
| 6 #define CONTENT_RENDERER_MOJO_INTERFACE_PROVIDER_JS_WRAPPER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "gin/handle.h" |
| 13 #include "gin/object_template_builder.h" |
| 14 #include "gin/wrappable.h" |
| 15 #include "mojo/public/cpp/system/message_pipe.h" |
| 16 #include "v8/include/v8.h" |
| 17 |
| 18 namespace shell { |
| 19 class InterfaceProvider; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 // A JS wrapper around shell::InterfaceProvider that allows connecting to |
| 25 // remote services. |
| 26 class CONTENT_EXPORT InterfaceProviderJsWrapper |
| 27 : public gin::Wrappable<InterfaceProviderJsWrapper> { |
| 28 public: |
| 29 ~InterfaceProviderJsWrapper() override; |
| 30 static gin::Handle<InterfaceProviderJsWrapper> Create( |
| 31 v8::Isolate* isolate, |
| 32 v8::Handle<v8::Context> context, |
| 33 shell::InterfaceProvider* remote_interfaces); |
| 34 |
| 35 // gin::Wrappable<InterfaceProviderJsWrapper> overrides. |
| 36 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 37 v8::Isolate* isolate) override; |
| 38 |
| 39 // JS interface implementation. |
| 40 void AddOverrideForTesting(const std::string& interface_name, |
| 41 v8::Local<v8::Function> interface_factory); |
| 42 void ClearOverridesForTesting(); |
| 43 mojo::Handle GetInterface(const std::string& interface_name); |
| 44 |
| 45 static gin::WrapperInfo kWrapperInfo; |
| 46 static const char kPerFrameModuleName[]; |
| 47 static const char kPerProcessModuleName[]; |
| 48 |
| 49 private: |
| 50 using ScopedJsFactory = |
| 51 v8::Persistent<v8::Function, v8::CopyablePersistentTraits<v8::Function>>; |
| 52 |
| 53 InterfaceProviderJsWrapper( |
| 54 v8::Isolate* isolate, |
| 55 v8::Handle<v8::Context> context, |
| 56 base::WeakPtr<shell::InterfaceProvider> remote_interfaces); |
| 57 |
| 58 void CallJsFactory(const ScopedJsFactory& factory, |
| 59 mojo::ScopedMessagePipeHandle pipe); |
| 60 |
| 61 static void ClearContext( |
| 62 const v8::WeakCallbackInfo<InterfaceProviderJsWrapper>& data); |
| 63 |
| 64 v8::Isolate* isolate_; |
| 65 v8::Global<v8::Context> context_; |
| 66 base::WeakPtr<shell::InterfaceProvider> remote_interfaces_; |
| 67 |
| 68 base::WeakPtrFactory<InterfaceProviderJsWrapper> weak_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(InterfaceProviderJsWrapper); |
| 71 }; |
| 72 |
| 73 } // namespace content |
| 74 |
| 75 #endif // CONTENT_RENDERER_MOJO_INTERFACE_PROVIDER_JS_WRAPPER_H_ |
OLD | NEW |