| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/blink_connector_js_wrapper.h" | 5 #include "content/renderer/mojo/blink_connector_js_wrapper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "content/renderer/mojo/blink_connector_impl.h" | |
| 11 #include "mojo/edk/js/handle.h" | 10 #include "mojo/edk/js/handle.h" |
| 11 #include "services/service_manager/public/cpp/connector.h" |
| 12 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 gin::WrapperInfo BlinkConnectorJsWrapper::kWrapperInfo = { | 17 gin::WrapperInfo BlinkConnectorJsWrapper::kWrapperInfo = { |
| 17 gin::kEmbedderNativeGin}; | 18 gin::kEmbedderNativeGin}; |
| 18 const char BlinkConnectorJsWrapper::kModuleName[] = | 19 const char BlinkConnectorJsWrapper::kModuleName[] = |
| 19 "content/public/renderer/connector"; | 20 "content/public/renderer/connector"; |
| 20 | 21 |
| 21 BlinkConnectorJsWrapper::~BlinkConnectorJsWrapper() {} | 22 BlinkConnectorJsWrapper::~BlinkConnectorJsWrapper() {} |
| 22 | 23 |
| 23 // static | 24 // static |
| 24 gin::Handle<BlinkConnectorJsWrapper> BlinkConnectorJsWrapper::Create( | 25 gin::Handle<BlinkConnectorJsWrapper> BlinkConnectorJsWrapper::Create( |
| 25 v8::Isolate* isolate, | 26 v8::Isolate* isolate, |
| 26 v8::Handle<v8::Context> context, | 27 v8::Handle<v8::Context> context, |
| 27 BlinkConnectorImpl* connector) { | 28 service_manager::Connector* connector) { |
| 28 return gin::CreateHandle( | 29 return gin::CreateHandle( |
| 29 isolate, | 30 isolate, |
| 30 new BlinkConnectorJsWrapper(isolate, context, connector->GetWeakPtr())); | 31 new BlinkConnectorJsWrapper(isolate, context, connector->GetWeakPtr())); |
| 31 } | 32 } |
| 32 | 33 |
| 33 gin::ObjectTemplateBuilder BlinkConnectorJsWrapper::GetObjectTemplateBuilder( | 34 gin::ObjectTemplateBuilder BlinkConnectorJsWrapper::GetObjectTemplateBuilder( |
| 34 v8::Isolate* isolate) { | 35 v8::Isolate* isolate) { |
| 35 return Wrappable<BlinkConnectorJsWrapper>::GetObjectTemplateBuilder(isolate) | 36 return Wrappable<BlinkConnectorJsWrapper>::GetObjectTemplateBuilder(isolate) |
| 36 .SetMethod("bindInterface", &BlinkConnectorJsWrapper::BindInterface) | 37 .SetMethod("bindInterface", &BlinkConnectorJsWrapper::BindInterface) |
| 37 .SetMethod("addInterfaceOverrideForTesting", | 38 .SetMethod("addInterfaceOverrideForTesting", |
| 38 &BlinkConnectorJsWrapper::AddOverrideForTesting) | 39 &BlinkConnectorJsWrapper::AddOverrideForTesting) |
| 39 .SetMethod("clearInterfaceOverridesForTesting", | 40 .SetMethod("clearInterfaceOverridesForTesting", |
| 40 &BlinkConnectorJsWrapper::ClearOverridesForTesting); | 41 &BlinkConnectorJsWrapper::ClearOverridesForTesting); |
| 41 } | 42 } |
| 42 | 43 |
| 43 mojo::Handle BlinkConnectorJsWrapper::BindInterface( | 44 mojo::Handle BlinkConnectorJsWrapper::BindInterface( |
| 44 const std::string& service_name, | 45 const std::string& service_name, |
| 45 const std::string& interface_name) { | 46 const std::string& interface_name) { |
| 46 mojo::MessagePipe pipe; | 47 mojo::MessagePipe pipe; |
| 47 if (connector_) { | 48 if (connector_) { |
| 48 connector_->bindInterface(service_name.c_str(), interface_name.c_str(), | 49 connector_->BindInterface( |
| 49 std::move(pipe.handle0)); | 50 service_manager::Identity(service_name, |
| 51 service_manager::mojom::kInheritUserID), |
| 52 interface_name, std::move(pipe.handle0)); |
| 50 } | 53 } |
| 51 return pipe.handle1.release(); | 54 return pipe.handle1.release(); |
| 52 } | 55 } |
| 53 | 56 |
| 54 void BlinkConnectorJsWrapper::AddOverrideForTesting( | 57 void BlinkConnectorJsWrapper::AddOverrideForTesting( |
| 55 const std::string& service_name, | 58 const std::string& service_name, |
| 56 const std::string& interface_name, | 59 const std::string& interface_name, |
| 57 v8::Local<v8::Function> service_factory) { | 60 v8::Local<v8::Function> service_factory) { |
| 58 ScopedJsFactory factory(v8::Isolate::GetCurrent(), service_factory); | 61 ScopedJsFactory factory(v8::Isolate::GetCurrent(), service_factory); |
| 59 connector_->AddOverrideForTesting( | 62 service_manager::Connector::TestApi test_api(connector_.get()); |
| 63 test_api.OverrideBinderForTesting( |
| 60 service_name, interface_name, | 64 service_name, interface_name, |
| 61 base::Bind(&BlinkConnectorJsWrapper::CallJsFactory, | 65 base::Bind(&BlinkConnectorJsWrapper::CallJsFactory, |
| 62 weak_factory_.GetWeakPtr(), factory)); | 66 weak_factory_.GetWeakPtr(), factory)); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void BlinkConnectorJsWrapper::ClearOverridesForTesting() { | 69 void BlinkConnectorJsWrapper::ClearOverridesForTesting() { |
| 66 connector_->ClearOverridesForTesting(); | 70 service_manager::Connector::TestApi test_api(connector_.get()); |
| 71 test_api.ClearBinderOverrides(); |
| 67 } | 72 } |
| 68 | 73 |
| 69 BlinkConnectorJsWrapper::BlinkConnectorJsWrapper( | 74 BlinkConnectorJsWrapper::BlinkConnectorJsWrapper( |
| 70 v8::Isolate* isolate, | 75 v8::Isolate* isolate, |
| 71 v8::Handle<v8::Context> context, | 76 v8::Handle<v8::Context> context, |
| 72 base::WeakPtr<BlinkConnectorImpl> connector) | 77 base::WeakPtr<service_manager::Connector> connector) |
| 73 : isolate_(isolate), | 78 : isolate_(isolate), |
| 74 context_(isolate, context), | 79 context_(isolate, context), |
| 75 connector_(connector), | 80 connector_(connector), |
| 76 weak_factory_(this) { | 81 weak_factory_(this) { |
| 77 context_.SetWeak(this, &BlinkConnectorJsWrapper::ClearContext, | 82 context_.SetWeak(this, &BlinkConnectorJsWrapper::ClearContext, |
| 78 v8::WeakCallbackType::kParameter); | 83 v8::WeakCallbackType::kParameter); |
| 79 } | 84 } |
| 80 | 85 |
| 81 void BlinkConnectorJsWrapper::CallJsFactory( | 86 void BlinkConnectorJsWrapper::CallJsFactory( |
| 82 const ScopedJsFactory& factory, | 87 const ScopedJsFactory& factory, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 } | 100 } |
| 96 | 101 |
| 97 // static | 102 // static |
| 98 void BlinkConnectorJsWrapper::ClearContext( | 103 void BlinkConnectorJsWrapper::ClearContext( |
| 99 const v8::WeakCallbackInfo<BlinkConnectorJsWrapper>& data) { | 104 const v8::WeakCallbackInfo<BlinkConnectorJsWrapper>& data) { |
| 100 BlinkConnectorJsWrapper* registry = data.GetParameter(); | 105 BlinkConnectorJsWrapper* registry = data.GetParameter(); |
| 101 registry->context_.Reset(); | 106 registry->context_.Reset(); |
| 102 } | 107 } |
| 103 | 108 |
| 104 } // namespace content | 109 } // namespace content |
| OLD | NEW |