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
52
53
54
fuchsia_web / webengine / context_provider_impl.cc [blame]
// 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(
sys::OutgoingDirectory& outgoing_directory)
: web_instance_host_(outgoing_directory,
/*is_web_instance_component_in_same_package=*/true) {}
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;
}
// The CreateInstanceForContextWithCopiedArgs() call below requires that
// `params` has a service directory.
if (!params.has_service_directory()) {
context_request.Close(ZX_ERR_INVALID_ARGS);
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();
}