| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/shell/renderer/layout_test/interface_registry_js_wrapper.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "mojo/edk/js/handle.h" | |
| 11 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 gin::WrapperInfo InterfaceRegistryJsWrapper::kWrapperInfo = { | |
| 16 gin::kEmbedderNativeGin}; | |
| 17 const char InterfaceRegistryJsWrapper::kPerFrameModuleName[] = | |
| 18 "content/shell/renderer/layout_test/frame_interface_registry"; | |
| 19 const char InterfaceRegistryJsWrapper::kPerProcessModuleName[] = | |
| 20 "content/shell/renderer/layout_test/interface_registry"; | |
| 21 | |
| 22 InterfaceRegistryJsWrapper::~InterfaceRegistryJsWrapper() = default; | |
| 23 | |
| 24 // static | |
| 25 gin::Handle<InterfaceRegistryJsWrapper> InterfaceRegistryJsWrapper::Create( | |
| 26 v8::Isolate* isolate, | |
| 27 v8::Local<v8::Context> context, | |
| 28 service_manager::InterfaceRegistry* interface_registry) { | |
| 29 return gin::CreateHandle( | |
| 30 isolate, new InterfaceRegistryJsWrapper( | |
| 31 isolate, context, interface_registry->GetWeakPtr())); | |
| 32 } | |
| 33 | |
| 34 gin::ObjectTemplateBuilder InterfaceRegistryJsWrapper::GetObjectTemplateBuilder( | |
| 35 v8::Isolate* isolate) { | |
| 36 return Wrappable<InterfaceRegistryJsWrapper>::GetObjectTemplateBuilder( | |
| 37 isolate) | |
| 38 .SetMethod("getLocalInterfaceForTesting", | |
| 39 &InterfaceRegistryJsWrapper::GetLocalInterfaceForTesting); | |
| 40 } | |
| 41 | |
| 42 mojo::Handle InterfaceRegistryJsWrapper::GetLocalInterfaceForTesting( | |
| 43 const std::string& interface_name) { | |
| 44 mojo::MessagePipe pipe; | |
| 45 if (interface_registry_) { | |
| 46 service_manager::InterfaceRegistry::TestApi test_api( | |
| 47 interface_registry_.get()); | |
| 48 test_api.GetLocalInterface(interface_name, std::move(pipe.handle0)); | |
| 49 } | |
| 50 return pipe.handle1.release(); | |
| 51 } | |
| 52 | |
| 53 InterfaceRegistryJsWrapper::InterfaceRegistryJsWrapper( | |
| 54 v8::Isolate* isolate, | |
| 55 v8::Local<v8::Context> context, | |
| 56 base::WeakPtr<service_manager::InterfaceRegistry> interface_registry) | |
| 57 : isolate_(isolate), | |
| 58 context_(isolate, context), | |
| 59 interface_registry_(interface_registry), | |
| 60 weak_factory_(this) { | |
| 61 context_.SetWeak(this, &InterfaceRegistryJsWrapper::ClearContext, | |
| 62 v8::WeakCallbackType::kParameter); | |
| 63 } | |
| 64 | |
| 65 // static | |
| 66 void InterfaceRegistryJsWrapper::ClearContext( | |
| 67 const v8::WeakCallbackInfo<InterfaceRegistryJsWrapper>& data) { | |
| 68 InterfaceRegistryJsWrapper* registry = data.GetParameter(); | |
| 69 registry->context_.Reset(); | |
| 70 } | |
| 71 | |
| 72 } // namespace content | |
| OLD | NEW |