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
5#include "flutter/lib/io/dart_io.h"
6
7#include "flutter/fml/logging.h"
8
9#include "third_party/dart/runtime/include/bin/dart_io_api.h"
10#include "third_party/dart/runtime/include/dart_api.h"
11#include "third_party/tonic/converter/dart_converter.h"
12#include "third_party/tonic/logging/dart_error.h"
13
14using tonic::LogIfError;
15using tonic::ToDart;
16
17namespace flutter {
18
19void DartIO::InitForIsolate(bool may_insecurely_connect_to_all_domains,
20 std::string domain_network_policy) {
21 Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
22 Dart_Handle result = Dart_SetNativeResolver(io_lib, dart::bin::LookupIONative,
23 dart::bin::LookupIONativeSymbol);
24 FML_CHECK(!LogIfError(result));
25
26 Dart_Handle embedder_config_type =
27 Dart_GetType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
28 FML_CHECK(!LogIfError(embedder_config_type));
29
30 Dart_Handle allow_insecure_connections_result = Dart_SetField(
31 embedder_config_type, ToDart("_mayInsecurelyConnectToAllDomains"),
32 ToDart(may_insecurely_connect_to_all_domains));
33 FML_CHECK(!LogIfError(allow_insecure_connections_result));
34
35 Dart_Handle dart_args[1];
36 dart_args[0] = ToDart(domain_network_policy);
37 Dart_Handle set_domain_network_policy_result = Dart_Invoke(
38 embedder_config_type, ToDart("_setDomainPolicies"), 1, dart_args);
39 FML_CHECK(!LogIfError(set_domain_network_policy_result));
40}
41
42} // namespace flutter
43