| OLD | NEW |
| 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" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/common/mojo/service_registry_impl.h" | 10 #include "content/common/mojo/service_registry_impl.h" |
| 11 #include "content/public/common/service_registry.h" | 11 #include "content/public/common/service_registry.h" |
| 12 #include "mojo/edk/js/handle.h" | 12 #include "mojo/edk/js/handle.h" |
| 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = { | 17 gin::WrapperInfo ServiceRegistryJsWrapper::kWrapperInfo = { |
| 18 gin::kEmbedderNativeGin}; | 18 gin::kEmbedderNativeGin}; |
| 19 const char ServiceRegistryJsWrapper::kModuleName[] = | 19 const char ServiceRegistryJsWrapper::kPerFrameModuleName[] = |
| 20 "content/public/renderer/service_provider"; | 20 "content/public/renderer/frame_service_registry"; |
| 21 const char ServiceRegistryJsWrapper::kPerProcessModuleName[] = |
| 22 "content/public/renderer/service_registry"; |
| 21 | 23 |
| 22 ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() { | 24 ServiceRegistryJsWrapper::~ServiceRegistryJsWrapper() { |
| 23 } | 25 } |
| 24 | 26 |
| 25 // static | 27 // static |
| 26 gin::Handle<ServiceRegistryJsWrapper> ServiceRegistryJsWrapper::Create( | 28 gin::Handle<ServiceRegistryJsWrapper> ServiceRegistryJsWrapper::Create( |
| 27 v8::Isolate* isolate, | 29 v8::Isolate* isolate, |
| 28 v8::Handle<v8::Context> context, | 30 v8::Handle<v8::Context> context, |
| 29 ServiceRegistry* service_registry) { | 31 ServiceRegistry* service_registry) { |
| 30 return gin::CreateHandle( | 32 return gin::CreateHandle( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 mojo::MessagePipe pipe; | 52 mojo::MessagePipe pipe; |
| 51 if (service_registry_) | 53 if (service_registry_) |
| 52 service_registry_->ConnectToRemoteService(service_name, | 54 service_registry_->ConnectToRemoteService(service_name, |
| 53 std::move(pipe.handle0)); | 55 std::move(pipe.handle0)); |
| 54 return pipe.handle1.release(); | 56 return pipe.handle1.release(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void ServiceRegistryJsWrapper::AddServiceOverrideForTesting( | 59 void ServiceRegistryJsWrapper::AddServiceOverrideForTesting( |
| 58 const std::string& service_name, | 60 const std::string& service_name, |
| 59 v8::Local<v8::Function> service_factory) { | 61 v8::Local<v8::Function> service_factory) { |
| 60 ServiceRegistryImpl* registry = | 62 ServiceRegistry* registry = service_registry_.get(); |
| 61 static_cast<ServiceRegistryImpl*>(service_registry_.get()); | |
| 62 if (!registry) | 63 if (!registry) |
| 63 return; | 64 return; |
| 64 ScopedJsFactory factory(v8::Isolate::GetCurrent(), service_factory); | 65 ScopedJsFactory factory(v8::Isolate::GetCurrent(), service_factory); |
| 65 registry->AddServiceOverrideForTesting( | 66 registry->AddServiceOverrideForTesting( |
| 66 service_name, base::Bind(&ServiceRegistryJsWrapper::CallJsFactory, | 67 service_name, base::Bind(&ServiceRegistryJsWrapper::CallJsFactory, |
| 67 weak_factory_.GetWeakPtr(), factory)); | 68 weak_factory_.GetWeakPtr(), factory)); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ServiceRegistryJsWrapper::ClearServiceOverridesForTesting() { | 71 void ServiceRegistryJsWrapper::ClearServiceOverridesForTesting() { |
| 71 ServiceRegistryImpl* registry = | 72 ServiceRegistryImpl* registry = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 | 107 |
| 107 // static | 108 // static |
| 108 void ServiceRegistryJsWrapper::ClearContext( | 109 void ServiceRegistryJsWrapper::ClearContext( |
| 109 const v8::WeakCallbackInfo<ServiceRegistryJsWrapper>& data) { | 110 const v8::WeakCallbackInfo<ServiceRegistryJsWrapper>& data) { |
| 110 ServiceRegistryJsWrapper* service_registry = data.GetParameter(); | 111 ServiceRegistryJsWrapper* service_registry = data.GetParameter(); |
| 111 service_registry->context_.Reset(); | 112 service_registry->context_.Reset(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 } // namespace content | 115 } // namespace content |
| OLD | NEW |