summaryrefslogtreecommitdiffstats
path: root/content/renderer/mojo/service_registry_js_wrapper.cc
blob: 19c2bd7a7ae247ee05de7afcc6c868a6a72a596a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/mojo/service_registry_js_wrapper.h"

#include <utility>

#include "content/common/mojo/service_registry_impl.h"
#include "content/public/common/service_registry.h"
#include "third_party/mojo/src/mojo/edk/js/handle.h"

namespace content {

gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = {
    gin::kEmbedderNativeGin};
const char ServiceRegistryJsWrapper::kModuleName[] =
    "content/public/renderer/service_provider";

ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() {
}

// static
gin::Handle<ServiceRegistryJsWrapper> ServiceRegistryJsWrapper::Create(
    v8::Isolate* isolate,
    base::WeakPtr<ServiceRegistry> service_registry) {
  return gin::CreateHandle(
      isolate, new ServiceRegistryJsWrapper(service_registry));
}

gin::ObjectTemplateBuilder ServiceRegistryJsWrapper::GetObjectTemplateBuilder(
    v8::Isolate* isolate) {
  return Wrappable<ServiceRegistryJsWrapper>::GetObjectTemplateBuilder(isolate).
      SetMethod("connectToService",
                &ServiceRegistryJsWrapper::ConnectToService);
}

mojo::Handle ServiceRegistryJsWrapper::ConnectToService(
    const std::string& service_name) {
  mojo::MessagePipe pipe;
  if (service_registry_)
    service_registry_->Connect(service_name, std::move(pipe.handle0));
  return pipe.handle1.release();
}

ServiceRegistryJsWrapper::ServiceRegistryJsWrapper(
    base::WeakPtr<ServiceRegistry> service_registry)
    : service_registry_(service_registry) {
}

}  // namespace content