Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: content/renderer/mojo/service_registry_js_wrapper.cc

Issue 1639233004: Revert of [mojo] Enable ServiceRegistryImpl to override remote services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-testing-3
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "content/renderer/mojo/service_registry_js_wrapper.h" 5 #include "content/renderer/mojo/service_registry_js_wrapper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/mojo/service_registry_impl.h" 9 #include "content/common/mojo/service_registry_impl.h"
11 #include "content/public/common/service_registry.h" 10 #include "content/public/common/service_registry.h"
12 #include "third_party/mojo/src/mojo/edk/js/handle.h" 11 #include "third_party/mojo/src/mojo/edk/js/handle.h"
13 #include "v8/include/v8.h"
14 12
15 namespace content { 13 namespace content {
16 14
17 namespace {
18
19 void CallJsFactory(scoped_ptr<v8::Persistent<v8::Function>> factory,
20 mojo::ScopedMessagePipeHandle pipe) {
21 v8::Isolate* isolate = v8::Isolate::GetCurrent();
22 v8::Local<v8::Value> argv[] = {
23 gin::ConvertToV8(isolate, mojo::Handle(pipe.release().value()))
24 };
25 factory->Get(isolate)->Call(v8::Undefined(isolate), 1, argv);
26 }
27
28 } // namespace
29
30 gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = { 15 gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = {
31 gin::kEmbedderNativeGin}; 16 gin::kEmbedderNativeGin};
32 const char ServiceRegistryJsWrapper::kModuleName[] = 17 const char ServiceRegistryJsWrapper::kModuleName[] =
33 "content/public/renderer/service_provider"; 18 "content/public/renderer/service_provider";
34 19
35 ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() { 20 ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() {
36 } 21 }
37 22
38 // static 23 // static
39 gin::Handle<ServiceRegistryJsWrapper> ServiceRegistryJsWrapper::Create( 24 gin::Handle<ServiceRegistryJsWrapper> ServiceRegistryJsWrapper::Create(
40 v8::Isolate* isolate, 25 v8::Isolate* isolate,
41 ServiceRegistry* service_registry) { 26 ServiceRegistry* service_registry) {
42 return gin::CreateHandle( 27 return gin::CreateHandle(
43 isolate, 28 isolate,
44 new ServiceRegistryJsWrapper( 29 new ServiceRegistryJsWrapper(
45 static_cast<ServiceRegistryImpl*>(service_registry)->GetWeakPtr())); 30 static_cast<ServiceRegistryImpl*>(service_registry)->GetWeakPtr()));
46 } 31 }
47 32
48 gin::ObjectTemplateBuilder ServiceRegistryJsWrapper::GetObjectTemplateBuilder( 33 gin::ObjectTemplateBuilder ServiceRegistryJsWrapper::GetObjectTemplateBuilder(
49 v8::Isolate* isolate) { 34 v8::Isolate* isolate) {
50 return Wrappable<ServiceRegistryJsWrapper>::GetObjectTemplateBuilder(isolate). 35 return Wrappable<ServiceRegistryJsWrapper>::GetObjectTemplateBuilder(isolate).
51 SetMethod("connectToService", 36 SetMethod("connectToService",
52 &ServiceRegistryJsWrapper::ConnectToService). 37 &ServiceRegistryJsWrapper::ConnectToService);
53 SetMethod("addServiceOverrideForTesting",
54 &ServiceRegistryJsWrapper::AddServiceOverrideForTesting);
55 } 38 }
56 39
57 mojo::Handle ServiceRegistryJsWrapper::ConnectToService( 40 mojo::Handle ServiceRegistryJsWrapper::ConnectToService(
58 const std::string& service_name) { 41 const std::string& service_name) {
59 mojo::MessagePipe pipe; 42 mojo::MessagePipe pipe;
60 if (service_registry_) 43 if (service_registry_)
61 service_registry_->ConnectToRemoteService(service_name, 44 service_registry_->ConnectToRemoteService(service_name,
62 std::move(pipe.handle0)); 45 std::move(pipe.handle0));
63 return pipe.handle1.release(); 46 return pipe.handle1.release();
64 } 47 }
65 48
66 void ServiceRegistryJsWrapper::AddServiceOverrideForTesting(
67 const std::string& service_name,
68 v8::Local<v8::Function> service_factory) {
69 ServiceRegistryImpl* registry =
70 static_cast<ServiceRegistryImpl*>(service_registry_.get());
71 if (!registry)
72 return;
73 scoped_ptr<v8::Persistent<v8::Function>> factory(
74 new v8::Persistent<v8::Function>(v8::Isolate::GetCurrent(),
75 service_factory));
76 registry->AddServiceOverrideForTesting(
77 service_name, base::Bind(&CallJsFactory, base::Passed(&factory)));
78 }
79
80 ServiceRegistryJsWrapper::ServiceRegistryJsWrapper( 49 ServiceRegistryJsWrapper::ServiceRegistryJsWrapper(
81 base::WeakPtr<ServiceRegistry> service_registry) 50 base::WeakPtr<ServiceRegistry> service_registry)
82 : service_registry_(service_registry) { 51 : service_registry_(service_registry) {
83 } 52 }
84 53
85 } // namespace content 54 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mojo/service_registry_js_wrapper.h ('k') | third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698