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 CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_JS_WRAPPER_H_ |
| 6 #define CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_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 content { |
| 19 |
| 20 class BlinkConnectorImpl; |
| 21 |
| 22 // A JS wrapper around blink::Connector that allows connecting to remote |
| 23 // services. |
| 24 class CONTENT_EXPORT BlinkConnectorJsWrapper |
| 25 : public gin::Wrappable<BlinkConnectorJsWrapper> { |
| 26 public: |
| 27 ~BlinkConnectorJsWrapper() override; |
| 28 static gin::Handle<BlinkConnectorJsWrapper> Create( |
| 29 v8::Isolate* isolate, |
| 30 v8::Handle<v8::Context> context, |
| 31 BlinkConnectorImpl* remote_interfaces); |
| 32 |
| 33 // gin::Wrappable<BlinkConnectorJsWrapper> overrides. |
| 34 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 35 v8::Isolate* isolate) override; |
| 36 |
| 37 // JS interface implementation. |
| 38 void AddOverrideForTesting(const std::string& service_name, |
| 39 const std::string& interface_name, |
| 40 v8::Local<v8::Function> interface_factory); |
| 41 void ClearOverridesForTesting(); |
| 42 mojo::Handle BindInterface(const std::string& service_name, |
| 43 const std::string& interface_name); |
| 44 |
| 45 static gin::WrapperInfo kWrapperInfo; |
| 46 static const char kModuleName[]; |
| 47 |
| 48 private: |
| 49 using ScopedJsFactory = |
| 50 v8::Persistent<v8::Function, v8::CopyablePersistentTraits<v8::Function>>; |
| 51 |
| 52 BlinkConnectorJsWrapper(v8::Isolate* isolate, |
| 53 v8::Handle<v8::Context> context, |
| 54 base::WeakPtr<BlinkConnectorImpl> connector); |
| 55 |
| 56 void CallJsFactory(const ScopedJsFactory& factory, |
| 57 mojo::ScopedMessagePipeHandle pipe); |
| 58 |
| 59 static void ClearContext( |
| 60 const v8::WeakCallbackInfo<BlinkConnectorJsWrapper>& data); |
| 61 |
| 62 v8::Isolate* isolate_; |
| 63 v8::Global<v8::Context> context_; |
| 64 base::WeakPtr<BlinkConnectorImpl> connector_; |
| 65 |
| 66 base::WeakPtrFactory<BlinkConnectorJsWrapper> weak_factory_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(BlinkConnectorJsWrapper); |
| 69 }; |
| 70 |
| 71 } // namespace content |
| 72 |
| 73 #endif // CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_JS_WRAPPER_H_ |
OLD | NEW |