Skip to content

Commit

Permalink
Add support for setting allow http flag in Dart VM (flutter#17653)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetf authored Apr 11, 2020
1 parent 71d8edb commit 47a88e8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct Settings {
bool endless_trace_buffer = false;
bool enable_dart_profiling = false;
bool disable_dart_asserts = false;

// Used to signal the embedder whether HTTP connections are disabled.
bool disable_http = false;

// Used as the script URI in debug messages. Does not affect how the Dart code
// is executed.
std::string advisory_script_uri = "main.dart";
Expand Down
1 change: 1 addition & 0 deletions lib/io/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source_set("io") {
]

deps = [
"//flutter/fml",
"//flutter/third_party/tonic",
"//third_party/dart/runtime:dart_api",
"//third_party/dart/runtime/bin:dart_io_api",
Expand Down
18 changes: 14 additions & 4 deletions lib/io/dart_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

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

#include "flutter/fml/logging.h"

#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/logging/dart_error.h"

using tonic::LogIfError;
using tonic::ToDart;

namespace flutter {

void DartIO::InitForIsolate() {
void DartIO::InitForIsolate(bool disable_http) {
Dart_Handle result = Dart_SetNativeResolver(
Dart_LookupLibrary(ToDart("dart:io")), dart::bin::LookupIONative,
dart::bin::LookupIONativeSymbol);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
FML_CHECK(!LogIfError(result));

// The SDK expects this field to represent "allow http" so we switch the
// value.
Dart_Handle allow_http_value = disable_http ? Dart_False() : Dart_True();
Dart_Handle set_field_result =
Dart_SetField(Dart_LookupLibrary(ToDart("dart:_http")),
ToDart("_embedderAllowsHttp"), allow_http_value);
FML_CHECK(!LogIfError(set_field_result));
}

} // namespace flutter
2 changes: 1 addition & 1 deletion lib/io/dart_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace flutter {

class DartIO {
public:
static void InitForIsolate();
static void InitForIsolate(bool disable_http);

private:
FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartIO);
Expand Down
5 changes: 3 additions & 2 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ DartIsolate::DartIsolate(const Settings& settings,
settings.log_tag,
settings.unhandled_exception_callback,
DartVMRef::GetIsolateNameServer()),
is_root_isolate_(is_root_isolate) {
is_root_isolate_(is_root_isolate),
disable_http_(settings.disable_http) {
phase_ = Phase::Uninitialized;
}

Expand Down Expand Up @@ -261,7 +262,7 @@ bool DartIsolate::LoadLibraries() {

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

DartIO::InitForIsolate();
DartIO::InitForIsolate(disable_http_);

DartUI::InitForIsolate(IsRootIsolate());

Expand Down
1 change: 1 addition & 0 deletions runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ class DartIsolate : public UIDartState {
std::vector<std::unique_ptr<AutoFireClosure>> shutdown_callbacks_;
fml::RefPtr<fml::TaskRunner> message_handling_task_runner_;
const bool is_root_isolate_;
const bool disable_http_;

DartIsolate(const Settings& settings,
TaskRunners task_runners,
Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
}
}

settings.disable_http =
command_line.HasOption(FlagForSwitch(Switch::DisableHttp));

// Disable need for authentication codes for VM service communication, if
// specified.
settings.disable_service_auth_codes =
Expand Down
6 changes: 6 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ DEF_SWITCH(DisableDartAsserts,
"disabled. This flag may be specified if the user wishes to run "
"with assertions disabled in the debug product mode (i.e. with JIT "
"or DBC).")
DEF_SWITCH(DisableHttp,
"disable-http",
"Dart VM has a master switch that can be set to disable insecure "
"HTTP and WebSocket protocols. Localhost or loopback addresses are "
"exempted. This flag can be specified if the embedder wants this "
"for a particular platform.")
DEF_SWITCH(
ForceMultithreading,
"force-multithreading",
Expand Down

0 comments on commit 47a88e8

Please sign in to comment.