From 5441ee79ff992b8362617e1bdc91ff3b8ec8a962 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 29 May 2018 15:10:12 -0700 Subject: [PATCH] Allow embedders to specify a custom advisory URI and entrypoint. (#5408) The Fuchsia embedder wants to specify the application name in the field for the advisory URI. This allows embedders to specify whatever they want. --- common/settings.h | 6 ++++++ runtime/dart_isolate.h | 4 ++-- runtime/dart_isolate_unittests.cc | 12 +++++++++--- runtime/runtime_controller.cc | 32 +++++++++++++++++++++---------- runtime/runtime_controller.h | 8 +++++++- shell/common/engine.cc | 16 +++++++++------- 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/common/settings.h b/common/settings.h index 7e55bf8e5..547673529 100644 --- a/common/settings.h +++ b/common/settings.h @@ -48,6 +48,12 @@ struct Settings { bool endless_trace_buffer = false; bool enable_dart_profiling = false; bool dart_non_checked_mode = 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"; + // Used as the script entrypoint in debug messages. Does not affect how the + // Dart code is executed. + std::string advisory_script_entrypoint = "main"; // Observatory settings bool enable_observatory = false; diff --git a/runtime/dart_isolate.h b/runtime/dart_isolate.h index 16b7f3764..e82194690 100644 --- a/runtime/dart_isolate.h +++ b/runtime/dart_isolate.h @@ -46,8 +46,8 @@ class DartIsolate : public UIDartState { std::unique_ptr window, fml::WeakPtr resource_context, fxl::RefPtr unref_queue, - std::string advisory_script_uri = "main.dart", - std::string advisory_script_entrypoint = "main", + std::string advisory_script_uri, + std::string advisory_script_entrypoint, Dart_IsolateFlags* flags = nullptr); DartIsolate(const DartVM* vm, diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index ba808e5b7..c367484f4 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -36,7 +36,9 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) { std::move(task_runners), // task runners nullptr, // window {}, // resource context - nullptr // unref qeueue + nullptr, // unref qeueue + "main.dart", // advisory uri + "main" // advisory entrypoint ); ASSERT_TRUE(root_isolate); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::LibrariesSetup); @@ -62,7 +64,9 @@ TEST_F(DartIsolateTest, IsolateCanAssociateSnapshot) { std::move(task_runners), // task runners nullptr, // window {}, // resource context - nullptr // unref qeueue + nullptr, // unref qeueue + "main.dart", // advisory uri + "main" // advisory entrypoint ); ASSERT_TRUE(root_isolate); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::LibrariesSetup); @@ -91,7 +95,9 @@ TEST_F(DartIsolateTest, CanResolveAndInvokeMethod) { std::move(task_runners), // task runners nullptr, // window {}, // resource context - nullptr // unref qeueue + nullptr, // unref qeueue + "main.dart", // advisory uri + "main" // advisory entrypoint ); ASSERT_TRUE(root_isolate); ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::LibrariesSetup); diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 56ba08314..4b4c2cdf3 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -25,7 +25,9 @@ RuntimeController::RuntimeController( fxl::RefPtr p_shared_snapshot, TaskRunners p_task_runners, fml::WeakPtr p_resource_context, - fxl::RefPtr p_unref_queue) + fxl::RefPtr p_unref_queue, + std::string p_advisory_script_uri, + std::string p_advisory_script_entrypoint) : RuntimeController(p_client, p_vm, std::move(p_isolate_snapshot), @@ -33,6 +35,8 @@ RuntimeController::RuntimeController( std::move(p_task_runners), std::move(p_resource_context), std::move(p_unref_queue), + std::move(p_advisory_script_uri), + std::move(p_advisory_script_entrypoint), WindowData{/* default window data */}) {} RuntimeController::RuntimeController( @@ -43,6 +47,8 @@ RuntimeController::RuntimeController( TaskRunners p_task_runners, fml::WeakPtr p_resource_context, fxl::RefPtr p_unref_queue, + std::string p_advisory_script_uri, + std::string p_advisory_script_entrypoint, WindowData p_window_data) : client_(p_client), vm_(p_vm), @@ -51,6 +57,8 @@ RuntimeController::RuntimeController( task_runners_(p_task_runners), resource_context_(p_resource_context), unref_queue_(p_unref_queue), + advisory_script_uri_(p_advisory_script_uri), + advisory_script_entrypoint_(p_advisory_script_entrypoint), window_data_(std::move(p_window_data)), root_isolate_( DartIsolate::CreateRootIsolate(vm_, @@ -59,7 +67,9 @@ RuntimeController::RuntimeController( task_runners_, std::make_unique(this), resource_context_, - unref_queue_)) { + unref_queue_, + p_advisory_script_uri, + p_advisory_script_entrypoint)) { root_isolate_->SetReturnCodeCallback([this](uint32_t code) { root_isolate_return_code_ = {true, code}; }); @@ -96,14 +106,16 @@ bool RuntimeController::IsRootIsolateRunning() const { std::unique_ptr RuntimeController::Clone() const { return std::unique_ptr(new RuntimeController( - client_, // - vm_, // - isolate_snapshot_, // - shared_snapshot_, // - task_runners_, // - resource_context_, // - unref_queue_, // - window_data_ // + client_, // + vm_, // + isolate_snapshot_, // + shared_snapshot_, // + task_runners_, // + resource_context_, // + unref_queue_, // + advisory_script_uri_, // + advisory_script_entrypoint_, // + window_data_ // )); } diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index a9d32484d..746845a7c 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -29,7 +29,9 @@ class RuntimeController final : public WindowClient { fxl::RefPtr shared_snapshot, TaskRunners task_runners, fml::WeakPtr resource_context, - fxl::RefPtr unref_queue); + fxl::RefPtr unref_queue, + std::string advisory_script_uri, + std::string advisory_script_entrypoint); ~RuntimeController(); @@ -86,6 +88,8 @@ class RuntimeController final : public WindowClient { TaskRunners task_runners_; fml::WeakPtr resource_context_; fxl::RefPtr unref_queue_; + std::string advisory_script_uri_; + std::string advisory_script_entrypoint_; WindowData window_data_; fml::WeakPtr root_isolate_; std::pair root_isolate_return_code_ = {false, 0}; @@ -97,6 +101,8 @@ class RuntimeController final : public WindowClient { TaskRunners task_runners, fml::WeakPtr resource_context, fxl::RefPtr unref_queue, + std::string advisory_script_uri, + std::string advisory_script_entrypoint, WindowData data); Window* GetWindowIfAvailable(); diff --git a/shell/common/engine.cc b/shell/common/engine.cc index b15a3bc31..0eea25f8d 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -55,13 +55,15 @@ Engine::Engine(Delegate& delegate, // object as its delegate. The delegate may be called in the constructor and // we want to be fully initilazed by that point. runtime_controller_ = std::make_unique( - *this, // runtime delegate - &vm, // VM - std::move(isolate_snapshot), // isolate snapshot - std::move(shared_snapshot), // shared snapshot - std::move(task_runners), // task runners - std::move(resource_context), // resource context - std::move(unref_queue) // skia unref queue + *this, // runtime delegate + &vm, // VM + std::move(isolate_snapshot), // isolate snapshot + std::move(shared_snapshot), // shared snapshot + std::move(task_runners), // task runners + std::move(resource_context), // resource context + std::move(unref_queue), // skia unref queue + settings_.advisory_script_uri, // advisory script uri + settings_.advisory_script_entrypoint // advisory script entrypoint ); } -- GitLab