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