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