Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
isolate_configurator.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9#include "third_party/dart/runtime/include/dart_api.h"
13
14namespace flutter_runner {
15
17 zx::channel directory_request,
18 zx::eventpair view_ref)
19 : fdio_ns_(std::move(fdio_ns)),
20 directory_request_(std::move(directory_request)),
21 view_ref_(std::move(view_ref)) {}
22
24
26 if (used_) {
27 return false;
28 }
29 used_ = true;
30
31 BindFuchsia();
32 BindZircon();
33 BindDartIO();
34
35 // This is now owned by the Dart bindings. So relinquish our ownership of the
36 // handle.
37 (void)fdio_ns_.release();
38
39 return true;
40}
41
42void IsolateConfigurator::BindFuchsia() {
43 fuchsia::dart::Initialize(std::move(directory_request_),
44 std::move(view_ref_));
45}
46
47void IsolateConfigurator::BindZircon() {
48 // Tell dart:zircon about the FDIO namespace configured for this instance.
49 Dart_Handle zircon_lib = Dart_LookupLibrary(tonic::ToDart("dart:zircon"));
51
52 Dart_Handle namespace_type = Dart_GetNonNullableType(
53 zircon_lib, tonic::ToDart("_Namespace"), 0, nullptr);
54 FML_CHECK(!tonic::CheckAndHandleError(namespace_type));
55
57 Dart_SetField(namespace_type, //
58 tonic::ToDart("_namespace"), //
59 tonic::ToDart(reinterpret_cast<intptr_t>(fdio_ns_.get())));
61}
62
63void IsolateConfigurator::BindDartIO() {
64 // Grab the dart:io lib.
65 Dart_Handle io_lib = Dart_LookupLibrary(tonic::ToDart("dart:io"));
67
68 // Disable dart:io exit()
69 Dart_Handle embedder_config_type = Dart_GetNonNullableType(
70 io_lib, tonic::ToDart("_EmbedderConfig"), 0, nullptr);
71 FML_CHECK(!tonic::CheckAndHandleError(embedder_config_type));
72
73 Dart_Handle result = Dart_SetField(embedder_config_type,
74 tonic::ToDart("_mayExit"), Dart_False());
76
77 // Tell dart:io about the FDIO namespace configured for this instance.
78 Dart_Handle namespace_type =
79 Dart_GetNonNullableType(io_lib, tonic::ToDart("_Namespace"), 0, nullptr);
80 FML_CHECK(!tonic::CheckAndHandleError(namespace_type));
81
82 Dart_Handle namespace_args[] = {
83 Dart_NewInteger(reinterpret_cast<intptr_t>(fdio_ns_.get())), //
84 };
85 result = Dart_Invoke(namespace_type, tonic::ToDart("_setupNamespace"), 1,
86 namespace_args);
88}
89
90} // namespace flutter_runner
IsolateConfigurator(UniqueFDIONS fdio_ns, zx::channel directory_request, zx::eventpair view_ref)
const T & get() const
DART_EXPORT Dart_Handle Dart_GetNonNullableType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle *type_arguments)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Handle Dart_False(void)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
GAsyncResult * result
#define FML_CHECK(condition)
Definition logging.h:85
void Initialize(zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition fuchsia.cc:103
Definition ref_ptr.h:256
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33