Skip to content

Commit 47a88e8

Browse files
authored
Add support for setting allow http flag in Dart VM (flutter#17653)
1 parent 71d8edb commit 47a88e8

File tree

8 files changed

+33
-7
lines changed

8 files changed

+33
-7
lines changed

common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ struct Settings {
9999
bool endless_trace_buffer = false;
100100
bool enable_dart_profiling = false;
101101
bool disable_dart_asserts = false;
102+
103+
// Used to signal the embedder whether HTTP connections are disabled.
104+
bool disable_http = false;
105+
102106
// Used as the script URI in debug messages. Does not affect how the Dart code
103107
// is executed.
104108
std::string advisory_script_uri = "main.dart";

lib/io/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ source_set("io") {
99
]
1010

1111
deps = [
12+
"//flutter/fml",
1213
"//flutter/third_party/tonic",
1314
"//third_party/dart/runtime:dart_api",
1415
"//third_party/dart/runtime/bin:dart_io_api",

lib/io/dart_io.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44

55
#include "flutter/lib/io/dart_io.h"
66

7+
#include "flutter/fml/logging.h"
8+
79
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
810
#include "third_party/dart/runtime/include/dart_api.h"
911
#include "third_party/tonic/converter/dart_converter.h"
12+
#include "third_party/tonic/logging/dart_error.h"
1013

14+
using tonic::LogIfError;
1115
using tonic::ToDart;
1216

1317
namespace flutter {
1418

15-
void DartIO::InitForIsolate() {
19+
void DartIO::InitForIsolate(bool disable_http) {
1620
Dart_Handle result = Dart_SetNativeResolver(
1721
Dart_LookupLibrary(ToDart("dart:io")), dart::bin::LookupIONative,
1822
dart::bin::LookupIONativeSymbol);
19-
if (Dart_IsError(result)) {
20-
Dart_PropagateError(result);
21-
}
23+
FML_CHECK(!LogIfError(result));
24+
25+
// The SDK expects this field to represent "allow http" so we switch the
26+
// value.
27+
Dart_Handle allow_http_value = disable_http ? Dart_False() : Dart_True();
28+
Dart_Handle set_field_result =
29+
Dart_SetField(Dart_LookupLibrary(ToDart("dart:_http")),
30+
ToDart("_embedderAllowsHttp"), allow_http_value);
31+
FML_CHECK(!LogIfError(set_field_result));
2232
}
2333

2434
} // namespace flutter

lib/io/dart_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace flutter {
1313

1414
class DartIO {
1515
public:
16-
static void InitForIsolate();
16+
static void InitForIsolate(bool disable_http);
1717

1818
private:
1919
FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartIO);

runtime/dart_isolate.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ DartIsolate::DartIsolate(const Settings& settings,
137137
settings.log_tag,
138138
settings.unhandled_exception_callback,
139139
DartVMRef::GetIsolateNameServer()),
140-
is_root_isolate_(is_root_isolate) {
140+
is_root_isolate_(is_root_isolate),
141+
disable_http_(settings.disable_http) {
141142
phase_ = Phase::Uninitialized;
142143
}
143144

@@ -261,7 +262,7 @@ bool DartIsolate::LoadLibraries() {
261262

262263
tonic::DartState::Scope scope(this);
263264

264-
DartIO::InitForIsolate();
265+
DartIO::InitForIsolate(disable_http_);
265266

266267
DartUI::InitForIsolate(IsRootIsolate());
267268

runtime/dart_isolate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ class DartIsolate : public UIDartState {
402402
std::vector<std::unique_ptr<AutoFireClosure>> shutdown_callbacks_;
403403
fml::RefPtr<fml::TaskRunner> message_handling_task_runner_;
404404
const bool is_root_isolate_;
405+
const bool disable_http_;
405406

406407
DartIsolate(const Settings& settings,
407408
TaskRunners task_runners,

shell/common/switches.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
237237
}
238238
}
239239

240+
settings.disable_http =
241+
command_line.HasOption(FlagForSwitch(Switch::DisableHttp));
242+
240243
// Disable need for authentication codes for VM service communication, if
241244
// specified.
242245
settings.disable_service_auth_codes =

shell/common/switches.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ DEF_SWITCH(DisableDartAsserts,
174174
"disabled. This flag may be specified if the user wishes to run "
175175
"with assertions disabled in the debug product mode (i.e. with JIT "
176176
"or DBC).")
177+
DEF_SWITCH(DisableHttp,
178+
"disable-http",
179+
"Dart VM has a master switch that can be set to disable insecure "
180+
"HTTP and WebSocket protocols. Localhost or loopback addresses are "
181+
"exempted. This flag can be specified if the embedder wants this "
182+
"for a particular platform.")
177183
DEF_SWITCH(
178184
ForceMultithreading,
179185
"force-multithreading",

0 commit comments

Comments
 (0)