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.
5 #include "content/renderer/mojo/service_registry_js_wrapper.h"
7 #include "content/common/mojo/service_registry_impl.h"
8 #include "content/public/common/service_registry.h"
9 #include "third_party/mojo/src/mojo/edk/js/handle.h"
13 gin::WrapperInfo
ServiceRegistryJsWrapper::kWrapperInfo
= {
14 gin::kEmbedderNativeGin
};
15 const char ServiceRegistryJsWrapper::kModuleName
[] =
16 "content/public/renderer/service_provider";
18 ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() {
22 gin::Handle
<ServiceRegistryJsWrapper
> ServiceRegistryJsWrapper::Create(
24 ServiceRegistry
* service_registry
) {
25 return gin::CreateHandle(
27 new ServiceRegistryJsWrapper(
28 static_cast<ServiceRegistryImpl
*>(service_registry
)->GetWeakPtr()));
31 gin::ObjectTemplateBuilder
ServiceRegistryJsWrapper::GetObjectTemplateBuilder(
32 v8::Isolate
* isolate
) {
33 return Wrappable
<ServiceRegistryJsWrapper
>::GetObjectTemplateBuilder(isolate
).
34 SetMethod("connectToService",
35 &ServiceRegistryJsWrapper::ConnectToService
);
38 mojo::Handle
ServiceRegistryJsWrapper::ConnectToService(
39 const std::string
& service_name
) {
40 mojo::MessagePipe pipe
;
41 if (service_registry_
)
42 service_registry_
->ConnectToRemoteService(service_name
,
44 return pipe
.handle1
.release();
47 ServiceRegistryJsWrapper::ServiceRegistryJsWrapper(
48 base::WeakPtr
<ServiceRegistry
> service_registry
)
49 : service_registry_(service_registry
) {
52 } // namespace content