| // Copyright 2018 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "fuchsia_web/webengine/context_provider_impl.h" |
| |
| #include <lib/sys/cpp/service_directory.h> |
| #include <utility> |
| |
| #include "base/command_line.h" |
| #include "base/logging.h" |
| |
| ContextProviderImpl::ContextProviderImpl() = default; |
| |
| ContextProviderImpl::~ContextProviderImpl() = default; |
| |
| void ContextProviderImpl::Create( |
| fuchsia::web::CreateContextParams params, |
| fidl::InterfaceRequest<fuchsia::web::Context> context_request) { |
| if (!context_request.is_valid()) { |
| DLOG(ERROR) << "Invalid |context_request|."; |
| return; |
| } |
| |
| // Create the instance and request access to its outgoing service directory. |
| fidl::InterfaceHandle<fuchsia::io::Directory> services_handle; |
| zx_status_t result = |
| web_instance_host_.CreateInstanceForContextWithCopiedArgs( |
| std::move(params), services_handle.NewRequest(), |
| *base::CommandLine::ForCurrentProcess()); |
| |
| if (result == ZX_OK) { |
| sys::ServiceDirectory services(services_handle.Bind()); |
| |
| // Route the fuchsia.web.Context request to the new Component. |
| services.Connect(std::move(context_request)); |
| } else { |
| context_request.Close(result); |
| } |
| } |
| |
| fuchsia::web::Debug* ContextProviderImpl::debug_api() { |
| return web_instance_host_.debug_api(); |
| } |