From 198b278be2ca4ed37f49d5c6022340ef8e55ecf8 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 29 Apr 2020 15:30:49 -0700 Subject: [PATCH 1/5] Revert "Do not register UI-related native functions in secondary isolates (#6401)" This reverts commit 69ae5694de54d2a163743dcec727fcea1c7bc8e1 as it doesn't work when root and secondary isolates run in the same isolate group. --- lib/ui/dart_ui.cc | 26 +++----------------------- lib/ui/dart_ui.h | 2 +- runtime/dart_isolate.cc | 2 +- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/lib/ui/dart_ui.cc b/lib/ui/dart_ui.cc index 5b3189dfa80f8..a61b95ee55223 100644 --- a/lib/ui/dart_ui.cc +++ b/lib/ui/dart_ui.cc @@ -42,7 +42,6 @@ namespace flutter { namespace { static tonic::DartLibraryNatives* g_natives; -static tonic::DartLibraryNatives* g_natives_secondary; Dart_NativeFunction GetNativeFunction(Dart_Handle name, int argument_count, @@ -50,21 +49,10 @@ Dart_NativeFunction GetNativeFunction(Dart_Handle name, return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope); } -Dart_NativeFunction GetNativeFunctionSecondary(Dart_Handle name, - int argument_count, - bool* auto_setup_scope) { - return g_natives_secondary->GetNativeFunction(name, argument_count, - auto_setup_scope); -} - const uint8_t* GetSymbol(Dart_NativeFunction native_function) { return g_natives->GetSymbol(native_function); } -const uint8_t* GetSymbolSecondary(Dart_NativeFunction native_function) { - return g_natives_secondary->GetSymbol(native_function); -} - } // namespace void DartUI::InitForGlobal() { @@ -97,21 +85,13 @@ void DartUI::InitForGlobal() { #if defined(OS_FUCHSIA) SceneHost::RegisterNatives(g_natives); #endif - - // Secondary isolates do not provide UI-related APIs. - g_natives_secondary = new tonic::DartLibraryNatives(); - DartRuntimeHooks::RegisterNatives(g_natives_secondary); - IsolateNameServerNatives::RegisterNatives(g_natives_secondary); } } -void DartUI::InitForIsolate(bool is_root_isolate) { +void DartUI::InitForIsolate() { FML_DCHECK(g_natives); - auto get_native_function = - is_root_isolate ? GetNativeFunction : GetNativeFunctionSecondary; - auto get_symbol = is_root_isolate ? GetSymbol : GetSymbolSecondary; - Dart_Handle result = Dart_SetNativeResolver( - Dart_LookupLibrary(ToDart("dart:ui")), get_native_function, get_symbol); + Dart_Handle result = Dart_SetNativeResolver(Dart_LookupLibrary( + ToDart("dart:ui")), GetNativeFunction, GetSymbol); if (Dart_IsError(result)) { Dart_PropagateError(result); } diff --git a/lib/ui/dart_ui.h b/lib/ui/dart_ui.h index fd3fabfd95a66..3cfbc9ac4696a 100644 --- a/lib/ui/dart_ui.h +++ b/lib/ui/dart_ui.h @@ -12,7 +12,7 @@ namespace flutter { class DartUI { public: static void InitForGlobal(); - static void InitForIsolate(bool is_root_isolate); + static void InitForIsolate(); private: FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartUI); diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 3e78de7473e38..9e7ca8add1eba 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -264,7 +264,7 @@ bool DartIsolate::LoadLibraries() { DartIO::InitForIsolate(disable_http_); - DartUI::InitForIsolate(IsRootIsolate()); + DartUI::InitForIsolate(); const bool is_service_isolate = Dart_IsServiceIsolate(isolate()); From 0dcc5d946707a4aca4cc4d8fd093221e28f13143 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 29 Apr 2020 22:32:57 -0700 Subject: [PATCH 2/5] Confirm it is root isolate that makes UI native calls. --- lib/ui/compositing/scene_builder.cc | 1 + lib/ui/compositing/scene_host.cc | 1 + lib/ui/painting/canvas.cc | 1 + lib/ui/painting/codec.cc | 1 + lib/ui/painting/color_filter.cc | 2 ++ lib/ui/painting/gradient.cc | 1 + lib/ui/painting/image_filter.cc | 1 + lib/ui/painting/path.cc | 2 ++ lib/ui/painting/path_measure.cc | 2 ++ lib/ui/painting/picture_recorder.cc | 1 + lib/ui/painting/vertices.cc | 2 ++ lib/ui/semantics/semantics_update.cc | 1 + lib/ui/semantics/semantics_update_builder.cc | 2 ++ lib/ui/text/font_collection.cc | 1 + lib/ui/text/paragraph.cc | 16 ++++++++++++++++ lib/ui/text/paragraph_builder.cc | 1 + lib/ui/ui_dart_state.cc | 11 ++++++++++- lib/ui/ui_dart_state.h | 7 ++++++- lib/ui/window/window.cc | 11 +++++++++++ runtime/dart_isolate.cc | 4 ++-- runtime/dart_isolate.h | 4 ---- third_party/tonic/dart_binding_macros.h | 1 + 22 files changed, 66 insertions(+), 8 deletions(-) diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 7e307e3174c5f..fd74af99ced8d 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -37,6 +37,7 @@ namespace flutter { static void SceneBuilder_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&SceneBuilder::create, args); } diff --git a/lib/ui/compositing/scene_host.cc b/lib/ui/compositing/scene_host.cc index 8eb0ff53c6bb1..549c80362db18 100644 --- a/lib/ui/compositing/scene_host.cc +++ b/lib/ui/compositing/scene_host.cc @@ -47,6 +47,7 @@ using SceneHostBindings = std::unordered_map ConvertImageInfo( } static void InstantiateImageCodec(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle callback_handle = Dart_GetNativeArgument(args, 1); if (!Dart_IsClosure(callback_handle)) { Dart_SetReturnValue(args, tonic::ToDart("Callback must be a function")); diff --git a/lib/ui/painting/color_filter.cc b/lib/ui/painting/color_filter.cc index 8d8dbc60ce9b9..886cd4fcf4e9c 100644 --- a/lib/ui/painting/color_filter.cc +++ b/lib/ui/painting/color_filter.cc @@ -4,6 +4,7 @@ #include "flutter/lib/ui/painting/color_filter.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/dart_args.h" #include "third_party/tonic/dart_binding_macros.h" @@ -12,6 +13,7 @@ namespace flutter { static void ColorFilter_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&ColorFilter::Create, args); } diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index c46df8f67bbcd..fb91691ec86ff 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -17,6 +17,7 @@ typedef CanvasGradient Gradient; // Because the C++ name doesn't match the Dart name. static void Gradient_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&CanvasGradient::Create, args); } diff --git a/lib/ui/painting/image_filter.cc b/lib/ui/painting/image_filter.cc index 742f6dfff0c62..8800186e4af1a 100644 --- a/lib/ui/painting/image_filter.cc +++ b/lib/ui/painting/image_filter.cc @@ -16,6 +16,7 @@ namespace flutter { static void ImageFilter_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&ImageFilter::Create, args); } diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index 0c053c558d332..a66d92e2b8b4e 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -8,6 +8,7 @@ #include #include "flutter/lib/ui/painting/matrix.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/dart_args.h" #include "third_party/tonic/dart_binding_macros.h" @@ -20,6 +21,7 @@ namespace flutter { typedef CanvasPath Path; static void Path_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&CanvasPath::CreateNew, args); } diff --git a/lib/ui/painting/path_measure.cc b/lib/ui/painting/path_measure.cc index 2bc35cab4479c..fc88b5a681418 100644 --- a/lib/ui/painting/path_measure.cc +++ b/lib/ui/painting/path_measure.cc @@ -8,6 +8,7 @@ #include #include "flutter/lib/ui/painting/matrix.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/dart_args.h" #include "third_party/tonic/dart_binding_macros.h" @@ -20,6 +21,7 @@ namespace flutter { typedef CanvasPathMeasure PathMeasure; static void PathMeasure_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&CanvasPathMeasure::Create, args); } diff --git a/lib/ui/painting/picture_recorder.cc b/lib/ui/painting/picture_recorder.cc index 56d3297a1abe9..521731bfbbfa8 100644 --- a/lib/ui/painting/picture_recorder.cc +++ b/lib/ui/painting/picture_recorder.cc @@ -14,6 +14,7 @@ namespace flutter { static void PictureRecorder_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&PictureRecorder::Create, args); } diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index d9ae98c2fc57b..b395ecf715a01 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "flutter/lib/ui/painting/vertices.h" +#include "flutter/lib/ui/ui_dart_state.h" #include @@ -27,6 +28,7 @@ void DecodeInts(const tonic::Int32List& ints, T* out) { } // namespace static void Vertices_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&Vertices::Create, args); } diff --git a/lib/ui/semantics/semantics_update.cc b/lib/ui/semantics/semantics_update.cc index c4ef22e34f7be..97e1694d01b0b 100644 --- a/lib/ui/semantics/semantics_update.cc +++ b/lib/ui/semantics/semantics_update.cc @@ -7,6 +7,7 @@ #include #include "flutter/lib/ui/painting/matrix.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/dart_args.h" #include "third_party/tonic/dart_binding_macros.h" diff --git a/lib/ui/semantics/semantics_update_builder.cc b/lib/ui/semantics/semantics_update_builder.cc index ca4573a2d5a08..9b25923f66dd4 100644 --- a/lib/ui/semantics/semantics_update_builder.cc +++ b/lib/ui/semantics/semantics_update_builder.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "flutter/lib/ui/semantics/semantics_update_builder.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "third_party/skia/include/core/SkScalar.h" #include "third_party/tonic/converter/dart_converter.h" @@ -13,6 +14,7 @@ namespace flutter { static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&SemanticsUpdateBuilder::create, args); } diff --git a/lib/ui/text/font_collection.cc b/lib/ui/text/font_collection.cc index 170f30c864f11..0f8d9d447ec84 100644 --- a/lib/ui/text/font_collection.cc +++ b/lib/ui/text/font_collection.cc @@ -39,6 +39,7 @@ void LoadFontFromList(tonic::Uint8List& font_data, } void _LoadFontFromList(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); tonic::DartCallStatic(LoadFontFromList, args); } diff --git a/lib/ui/text/paragraph.cc b/lib/ui/text/paragraph.cc index 92800db2ebd67..4441ce05babb9 100644 --- a/lib/ui/text/paragraph.cc +++ b/lib/ui/text/paragraph.cc @@ -52,42 +52,52 @@ size_t Paragraph::GetAllocationSize() { } double Paragraph::width() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMaxWidth(); } double Paragraph::height() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetHeight(); } double Paragraph::longestLine() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetLongestLine(); } double Paragraph::minIntrinsicWidth() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMinIntrinsicWidth(); } double Paragraph::maxIntrinsicWidth() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMaxIntrinsicWidth(); } double Paragraph::alphabeticBaseline() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetAlphabeticBaseline(); } double Paragraph::ideographicBaseline() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetIdeographicBaseline(); } bool Paragraph::didExceedMaxLines() { + UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->DidExceedMaxLines(); } void Paragraph::layout(double width) { + UIDartState::ThrowIfUIOperationsProhited(); m_paragraph->Layout(width); } void Paragraph::paint(Canvas* canvas, double x, double y) { + UIDartState::ThrowIfUIOperationsProhited(); SkCanvas* sk_canvas = canvas->canvas(); if (!sk_canvas) return; @@ -118,6 +128,7 @@ tonic::Float32List Paragraph::getRectsForRange(unsigned start, unsigned end, unsigned boxHeightStyle, unsigned boxWidthStyle) { + UIDartState::ThrowIfUIOperationsProhited(); std::vector boxes = m_paragraph->GetRectsForRange( start, end, static_cast(boxHeightStyle), static_cast(boxWidthStyle)); @@ -125,12 +136,14 @@ tonic::Float32List Paragraph::getRectsForRange(unsigned start, } tonic::Float32List Paragraph::getRectsForPlaceholders() { + UIDartState::ThrowIfUIOperationsProhited(); std::vector boxes = m_paragraph->GetRectsForPlaceholders(); return EncodeTextBoxes(boxes); } Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); txt::Paragraph::PositionWithAffinity pos = m_paragraph->GetGlyphPositionAtCoordinate(dx, dy); @@ -140,6 +153,7 @@ Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { } Dart_Handle Paragraph::getWordBoundary(unsigned offset) { + UIDartState::ThrowIfUIOperationsProhited(); txt::Paragraph::Range point = m_paragraph->GetWordBoundary(offset); Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); Dart_ListSetAt(result, 0, ToDart(point.start)); @@ -148,6 +162,7 @@ Dart_Handle Paragraph::getWordBoundary(unsigned offset) { } Dart_Handle Paragraph::getLineBoundary(unsigned offset) { + UIDartState::ThrowIfUIOperationsProhited(); std::vector metrics = m_paragraph->GetLineMetrics(); int line_start = -1; int line_end = -1; @@ -165,6 +180,7 @@ Dart_Handle Paragraph::getLineBoundary(unsigned offset) { } tonic::Float64List Paragraph::computeLineMetrics() { + UIDartState::ThrowIfUIOperationsProhited(); std::vector metrics = m_paragraph->GetLineMetrics(); // Layout: diff --git a/lib/ui/text/paragraph_builder.cc b/lib/ui/text/paragraph_builder.cc index 0b6eea6e0abfd..0b18207a06e50 100644 --- a/lib/ui/text/paragraph_builder.cc +++ b/lib/ui/text/paragraph_builder.cc @@ -130,6 +130,7 @@ const int sForceStrutHeightMask = 1 << sForceStrutHeightIndex; } // namespace static void ParagraphBuilder_constructor(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); DartCallConstructor(&ParagraphBuilder::create, args); } diff --git a/lib/ui/ui_dart_state.cc b/lib/ui/ui_dart_state.cc index fa2ae24beef91..f2c7c0051f44a 100644 --- a/lib/ui/ui_dart_state.cc +++ b/lib/ui/ui_dart_state.cc @@ -25,7 +25,8 @@ UIDartState::UIDartState( std::string advisory_script_entrypoint, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, - std::shared_ptr isolate_name_server) + std::shared_ptr isolate_name_server, + bool is_root_isolate) : task_runners_(std::move(task_runners)), add_callback_(std::move(add_callback)), remove_callback_(std::move(remove_callback)), @@ -36,6 +37,7 @@ UIDartState::UIDartState( advisory_script_uri_(std::move(advisory_script_uri)), advisory_script_entrypoint_(std::move(advisory_script_entrypoint)), logger_prefix_(std::move(logger_prefix)), + is_root_isolate_(is_root_isolate), unhandled_exception_callback_(unhandled_exception_callback), isolate_name_server_(std::move(isolate_name_server)) { AddOrRemoveTaskObserver(true /* add */); @@ -62,6 +64,13 @@ void UIDartState::DidSetIsolate() { SetDebugName(debug_name.str()); } +void UIDartState::ThrowIfUIOperationsProhited() { + if (!UIDartState::Current()->IsRootIsolate()) { + Dart_ThrowException( + tonic::ToDart("UI actions are only available on root isolate.")); + } +} + void UIDartState::SetDebugName(const std::string debug_name) { debug_name_ = debug_name; if (window_) diff --git a/lib/ui/ui_dart_state.h b/lib/ui/ui_dart_state.h index 2d81b6d3ebc5a..f49d7e29d63fa 100644 --- a/lib/ui/ui_dart_state.h +++ b/lib/ui/ui_dart_state.h @@ -34,6 +34,9 @@ class UIDartState : public tonic::DartState { static UIDartState* Current(); Dart_Port main_port() const { return main_port_; } + // Root isolate of the VM application + bool IsRootIsolate() const { return is_root_isolate_; } + static void ThrowIfUIOperationsProhited(); void SetDebugName(const std::string name); @@ -89,7 +92,8 @@ class UIDartState : public tonic::DartState { std::string advisory_script_entrypoint, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, - std::shared_ptr isolate_name_server); + std::shared_ptr isolate_name_server, + bool is_root_isolate_); ~UIDartState() override; @@ -113,6 +117,7 @@ class UIDartState : public tonic::DartState { const std::string advisory_script_entrypoint_; const std::string logger_prefix_; Dart_Port main_port_ = ILLEGAL_PORT; + const bool is_root_isolate_; std::string debug_name_; std::unique_ptr window_; tonic::DartMicrotaskQueue microtask_queue_; diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index 4d75fba13c090..7798265178b92 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -18,16 +18,19 @@ namespace flutter { namespace { void DefaultRouteName(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); std::string routeName = UIDartState::Current()->window()->client()->DefaultRouteName(); Dart_SetReturnValue(args, tonic::StdStringToDart(routeName)); } void ScheduleFrame(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); UIDartState::Current()->window()->client()->ScheduleFrame(); } void Render(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle exception = nullptr; Scene* scene = tonic::DartConverter::FromArguments(args, 1, exception); @@ -39,6 +42,7 @@ void Render(Dart_NativeArguments args) { } void UpdateSemantics(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle exception = nullptr; SemanticsUpdate* update = tonic::DartConverter::FromArguments(args, 1, exception); @@ -50,6 +54,7 @@ void UpdateSemantics(Dart_NativeArguments args) { } void SetIsolateDebugName(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle exception = nullptr; const std::string name = tonic::DartConverter::FromArguments(args, 1, exception); @@ -61,12 +66,15 @@ void SetIsolateDebugName(Dart_NativeArguments args) { } void SetNeedsReportTimings(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle exception = nullptr; bool value = tonic::DartConverter::FromArguments(args, 1, exception); UIDartState::Current()->window()->client()->SetNeedsReportTimings(value); } void ReportUnhandledException(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); + Dart_Handle exception = nullptr; auto error_name = @@ -143,6 +151,8 @@ void _RespondToPlatformMessage(Dart_NativeArguments args) { } void GetPersistentIsolateData(Dart_NativeArguments args) { + UIDartState::ThrowIfUIOperationsProhited(); + auto persistent_isolate_data = UIDartState::Current()->window()->client()->GetPersistentIsolateData(); @@ -270,6 +280,7 @@ void Window::UpdateSemanticsEnabled(bool enabled) { if (!dart_state) return; tonic::DartState::Scope scope(dart_state); + UIDartState::ThrowIfUIOperationsProhited(); tonic::LogIfError(tonic::DartInvokeField( library_.value(), "_updateSemanticsEnabled", {tonic::ToDart(enabled)})); diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 9e7ca8add1eba..d23b38e752b3e 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -136,8 +136,8 @@ DartIsolate::DartIsolate(const Settings& settings, advisory_script_entrypoint, settings.log_tag, settings.unhandled_exception_callback, - DartVMRef::GetIsolateNameServer()), - is_root_isolate_(is_root_isolate), + DartVMRef::GetIsolateNameServer(), + is_root_isolate), disable_http_(settings.disable_http) { phase_ = Phase::Uninitialized; } diff --git a/runtime/dart_isolate.h b/runtime/dart_isolate.h index 4a045d38d422c..7f59aa7dc28d0 100644 --- a/runtime/dart_isolate.h +++ b/runtime/dart_isolate.h @@ -381,9 +381,6 @@ class DartIsolate : public UIDartState { /// fml::RefPtr GetMessageHandlingTaskRunner() const; - // Root isolate of the VM application - bool IsRootIsolate() const { return is_root_isolate_; } - private: class AutoFireClosure { public: @@ -401,7 +398,6 @@ class DartIsolate : public UIDartState { std::vector> kernel_buffers_; std::vector> shutdown_callbacks_; fml::RefPtr message_handling_task_runner_; - const bool is_root_isolate_; const bool disable_http_; DartIsolate(const Settings& settings, diff --git a/third_party/tonic/dart_binding_macros.h b/third_party/tonic/dart_binding_macros.h index a54c6d2b1a708..eb97e60fecf97 100644 --- a/third_party/tonic/dart_binding_macros.h +++ b/third_party/tonic/dart_binding_macros.h @@ -9,6 +9,7 @@ #define DART_NATIVE_CALLBACK(CLASS, METHOD) \ static void CLASS##_##METHOD(Dart_NativeArguments args) { \ + UIDartState::ThrowIfUIOperationsProhited(); \ tonic::DartCall(&CLASS::METHOD, args); \ } From da0bc8b5c559e4ac5cd338c5a2d10729539570c0 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 30 Apr 2020 07:00:09 -0700 Subject: [PATCH 3/5] Fix format, UIDartState reference from Fuchsia source --- lib/ui/compositing/scene_host.cc | 2 +- lib/ui/dart_ui.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ui/compositing/scene_host.cc b/lib/ui/compositing/scene_host.cc index 549c80362db18..f3bd61eed0b37 100644 --- a/lib/ui/compositing/scene_host.cc +++ b/lib/ui/compositing/scene_host.cc @@ -47,7 +47,7 @@ using SceneHostBindings = std::unordered_map Date: Thu, 30 Apr 2020 08:18:51 -0700 Subject: [PATCH 4/5] No UI isolate check for fuchsia calls --- shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc | 2 +- .../fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc | 2 +- third_party/tonic/dart_binding_macros.h | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc b/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc index 7869eb81b2057..e2d4fafd387bb 100644 --- a/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc +++ b/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc @@ -163,7 +163,7 @@ void Handle::ScheduleCallback(tonic::DartPersistentValue callback, DART_REGISTER_NATIVE_STATIC(CLASS, METHOD), FOR_EACH_STATIC_BINDING(DART_NATIVE_CALLBACK_STATIC) -FOR_EACH_BINDING(DART_NATIVE_CALLBACK) +FOR_EACH_BINDING(DART_NATIVE_NO_UI_CHECK_CALLBACK) void Handle::RegisterNatives(tonic::DartLibraryNatives* natives) { natives->Register({FOR_EACH_STATIC_BINDING(DART_REGISTER_NATIVE_STATIC_) diff --git a/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc b/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc index 79327f5952780..96d4d3180867c 100644 --- a/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc +++ b/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc @@ -26,7 +26,7 @@ IMPLEMENT_WRAPPERTYPEINFO(zircon, HandleWaiter); #define FOR_EACH_BINDING(V) V(HandleWaiter, Cancel) -FOR_EACH_BINDING(DART_NATIVE_CALLBACK) +FOR_EACH_BINDING(DART_NATIVE_NO_UI_CHECK_CALLBACK) void HandleWaiter::RegisterNatives(tonic::DartLibraryNatives* natives) { natives->Register({FOR_EACH_BINDING(DART_REGISTER_NATIVE)}); diff --git a/third_party/tonic/dart_binding_macros.h b/third_party/tonic/dart_binding_macros.h index eb97e60fecf97..825ac97e4682e 100644 --- a/third_party/tonic/dart_binding_macros.h +++ b/third_party/tonic/dart_binding_macros.h @@ -7,6 +7,11 @@ #include "tonic/dart_args.h" +#define DART_NATIVE_NO_UI_CHECK_CALLBACK(CLASS, METHOD) \ + static void CLASS##_##METHOD(Dart_NativeArguments args) { \ + tonic::DartCall(&CLASS::METHOD, args); \ + } + #define DART_NATIVE_CALLBACK(CLASS, METHOD) \ static void CLASS##_##METHOD(Dart_NativeArguments args) { \ UIDartState::ThrowIfUIOperationsProhited(); \ From 2860be342149845b192a3495f4f9ec9151dafbfc Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 30 Apr 2020 14:36:14 -0700 Subject: [PATCH 5/5] Fix typo. Remove redundant runtime calls --- lib/ui/compositing/scene_builder.cc | 2 +- lib/ui/compositing/scene_host.cc | 2 +- lib/ui/painting/canvas.cc | 2 +- lib/ui/painting/codec.cc | 2 +- lib/ui/painting/color_filter.cc | 2 +- lib/ui/painting/gradient.cc | 2 +- lib/ui/painting/image_filter.cc | 2 +- lib/ui/painting/path.cc | 2 +- lib/ui/painting/path_measure.cc | 2 +- lib/ui/painting/picture_recorder.cc | 2 +- lib/ui/painting/vertices.cc | 2 +- lib/ui/semantics/semantics_update_builder.cc | 2 +- lib/ui/text/font_collection.cc | 2 +- lib/ui/text/paragraph.cc | 16 ---------------- lib/ui/text/paragraph_builder.cc | 2 +- lib/ui/ui_dart_state.cc | 2 +- lib/ui/ui_dart_state.h | 2 +- lib/ui/window/window.cc | 18 +++++++++--------- third_party/tonic/dart_binding_macros.h | 2 +- 19 files changed, 26 insertions(+), 42 deletions(-) diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index fd74af99ced8d..ed189283ab4a7 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -37,7 +37,7 @@ namespace flutter { static void SceneBuilder_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&SceneBuilder::create, args); } diff --git a/lib/ui/compositing/scene_host.cc b/lib/ui/compositing/scene_host.cc index f3bd61eed0b37..cfe4e0bf8dd7c 100644 --- a/lib/ui/compositing/scene_host.cc +++ b/lib/ui/compositing/scene_host.cc @@ -47,7 +47,7 @@ using SceneHostBindings = std::unordered_map ConvertImageInfo( } static void InstantiateImageCodec(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle callback_handle = Dart_GetNativeArgument(args, 1); if (!Dart_IsClosure(callback_handle)) { Dart_SetReturnValue(args, tonic::ToDart("Callback must be a function")); diff --git a/lib/ui/painting/color_filter.cc b/lib/ui/painting/color_filter.cc index 886cd4fcf4e9c..296f07e3a32ca 100644 --- a/lib/ui/painting/color_filter.cc +++ b/lib/ui/painting/color_filter.cc @@ -13,7 +13,7 @@ namespace flutter { static void ColorFilter_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&ColorFilter::Create, args); } diff --git a/lib/ui/painting/gradient.cc b/lib/ui/painting/gradient.cc index fb91691ec86ff..e242258e4ddb7 100644 --- a/lib/ui/painting/gradient.cc +++ b/lib/ui/painting/gradient.cc @@ -17,7 +17,7 @@ typedef CanvasGradient Gradient; // Because the C++ name doesn't match the Dart name. static void Gradient_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&CanvasGradient::Create, args); } diff --git a/lib/ui/painting/image_filter.cc b/lib/ui/painting/image_filter.cc index 8800186e4af1a..75b883cb48c04 100644 --- a/lib/ui/painting/image_filter.cc +++ b/lib/ui/painting/image_filter.cc @@ -16,7 +16,7 @@ namespace flutter { static void ImageFilter_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&ImageFilter::Create, args); } diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index a66d92e2b8b4e..7667b53c87bec 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -21,7 +21,7 @@ namespace flutter { typedef CanvasPath Path; static void Path_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&CanvasPath::CreateNew, args); } diff --git a/lib/ui/painting/path_measure.cc b/lib/ui/painting/path_measure.cc index fc88b5a681418..da8c1659ecd35 100644 --- a/lib/ui/painting/path_measure.cc +++ b/lib/ui/painting/path_measure.cc @@ -21,7 +21,7 @@ namespace flutter { typedef CanvasPathMeasure PathMeasure; static void PathMeasure_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&CanvasPathMeasure::Create, args); } diff --git a/lib/ui/painting/picture_recorder.cc b/lib/ui/painting/picture_recorder.cc index 521731bfbbfa8..d86c1c0fd556f 100644 --- a/lib/ui/painting/picture_recorder.cc +++ b/lib/ui/painting/picture_recorder.cc @@ -14,7 +14,7 @@ namespace flutter { static void PictureRecorder_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&PictureRecorder::Create, args); } diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index b395ecf715a01..41425e849631f 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -28,7 +28,7 @@ void DecodeInts(const tonic::Int32List& ints, T* out) { } // namespace static void Vertices_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&Vertices::Create, args); } diff --git a/lib/ui/semantics/semantics_update_builder.cc b/lib/ui/semantics/semantics_update_builder.cc index 9b25923f66dd4..3d4b333f0f008 100644 --- a/lib/ui/semantics/semantics_update_builder.cc +++ b/lib/ui/semantics/semantics_update_builder.cc @@ -14,7 +14,7 @@ namespace flutter { static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&SemanticsUpdateBuilder::create, args); } diff --git a/lib/ui/text/font_collection.cc b/lib/ui/text/font_collection.cc index 0f8d9d447ec84..8d1070852c391 100644 --- a/lib/ui/text/font_collection.cc +++ b/lib/ui/text/font_collection.cc @@ -39,7 +39,7 @@ void LoadFontFromList(tonic::Uint8List& font_data, } void _LoadFontFromList(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); tonic::DartCallStatic(LoadFontFromList, args); } diff --git a/lib/ui/text/paragraph.cc b/lib/ui/text/paragraph.cc index 4441ce05babb9..92800db2ebd67 100644 --- a/lib/ui/text/paragraph.cc +++ b/lib/ui/text/paragraph.cc @@ -52,52 +52,42 @@ size_t Paragraph::GetAllocationSize() { } double Paragraph::width() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMaxWidth(); } double Paragraph::height() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetHeight(); } double Paragraph::longestLine() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetLongestLine(); } double Paragraph::minIntrinsicWidth() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMinIntrinsicWidth(); } double Paragraph::maxIntrinsicWidth() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetMaxIntrinsicWidth(); } double Paragraph::alphabeticBaseline() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetAlphabeticBaseline(); } double Paragraph::ideographicBaseline() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->GetIdeographicBaseline(); } bool Paragraph::didExceedMaxLines() { - UIDartState::ThrowIfUIOperationsProhited(); return m_paragraph->DidExceedMaxLines(); } void Paragraph::layout(double width) { - UIDartState::ThrowIfUIOperationsProhited(); m_paragraph->Layout(width); } void Paragraph::paint(Canvas* canvas, double x, double y) { - UIDartState::ThrowIfUIOperationsProhited(); SkCanvas* sk_canvas = canvas->canvas(); if (!sk_canvas) return; @@ -128,7 +118,6 @@ tonic::Float32List Paragraph::getRectsForRange(unsigned start, unsigned end, unsigned boxHeightStyle, unsigned boxWidthStyle) { - UIDartState::ThrowIfUIOperationsProhited(); std::vector boxes = m_paragraph->GetRectsForRange( start, end, static_cast(boxHeightStyle), static_cast(boxWidthStyle)); @@ -136,14 +125,12 @@ tonic::Float32List Paragraph::getRectsForRange(unsigned start, } tonic::Float32List Paragraph::getRectsForPlaceholders() { - UIDartState::ThrowIfUIOperationsProhited(); std::vector boxes = m_paragraph->GetRectsForPlaceholders(); return EncodeTextBoxes(boxes); } Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { - UIDartState::ThrowIfUIOperationsProhited(); Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); txt::Paragraph::PositionWithAffinity pos = m_paragraph->GetGlyphPositionAtCoordinate(dx, dy); @@ -153,7 +140,6 @@ Dart_Handle Paragraph::getPositionForOffset(double dx, double dy) { } Dart_Handle Paragraph::getWordBoundary(unsigned offset) { - UIDartState::ThrowIfUIOperationsProhited(); txt::Paragraph::Range point = m_paragraph->GetWordBoundary(offset); Dart_Handle result = Dart_NewListOf(Dart_CoreType_Int, 2); Dart_ListSetAt(result, 0, ToDart(point.start)); @@ -162,7 +148,6 @@ Dart_Handle Paragraph::getWordBoundary(unsigned offset) { } Dart_Handle Paragraph::getLineBoundary(unsigned offset) { - UIDartState::ThrowIfUIOperationsProhited(); std::vector metrics = m_paragraph->GetLineMetrics(); int line_start = -1; int line_end = -1; @@ -180,7 +165,6 @@ Dart_Handle Paragraph::getLineBoundary(unsigned offset) { } tonic::Float64List Paragraph::computeLineMetrics() { - UIDartState::ThrowIfUIOperationsProhited(); std::vector metrics = m_paragraph->GetLineMetrics(); // Layout: diff --git a/lib/ui/text/paragraph_builder.cc b/lib/ui/text/paragraph_builder.cc index 0b18207a06e50..aeeb8a0b4ad8e 100644 --- a/lib/ui/text/paragraph_builder.cc +++ b/lib/ui/text/paragraph_builder.cc @@ -130,7 +130,7 @@ const int sForceStrutHeightMask = 1 << sForceStrutHeightIndex; } // namespace static void ParagraphBuilder_constructor(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); DartCallConstructor(&ParagraphBuilder::create, args); } diff --git a/lib/ui/ui_dart_state.cc b/lib/ui/ui_dart_state.cc index f2c7c0051f44a..4d04a30d404c2 100644 --- a/lib/ui/ui_dart_state.cc +++ b/lib/ui/ui_dart_state.cc @@ -64,7 +64,7 @@ void UIDartState::DidSetIsolate() { SetDebugName(debug_name.str()); } -void UIDartState::ThrowIfUIOperationsProhited() { +void UIDartState::ThrowIfUIOperationsProhibited() { if (!UIDartState::Current()->IsRootIsolate()) { Dart_ThrowException( tonic::ToDart("UI actions are only available on root isolate.")); diff --git a/lib/ui/ui_dart_state.h b/lib/ui/ui_dart_state.h index f49d7e29d63fa..2fdedc8094963 100644 --- a/lib/ui/ui_dart_state.h +++ b/lib/ui/ui_dart_state.h @@ -36,7 +36,7 @@ class UIDartState : public tonic::DartState { Dart_Port main_port() const { return main_port_; } // Root isolate of the VM application bool IsRootIsolate() const { return is_root_isolate_; } - static void ThrowIfUIOperationsProhited(); + static void ThrowIfUIOperationsProhibited(); void SetDebugName(const std::string name); diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index 7798265178b92..8e44378a6f3fa 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -18,19 +18,19 @@ namespace flutter { namespace { void DefaultRouteName(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); std::string routeName = UIDartState::Current()->window()->client()->DefaultRouteName(); Dart_SetReturnValue(args, tonic::StdStringToDart(routeName)); } void ScheduleFrame(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); UIDartState::Current()->window()->client()->ScheduleFrame(); } void Render(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle exception = nullptr; Scene* scene = tonic::DartConverter::FromArguments(args, 1, exception); @@ -42,7 +42,7 @@ void Render(Dart_NativeArguments args) { } void UpdateSemantics(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle exception = nullptr; SemanticsUpdate* update = tonic::DartConverter::FromArguments(args, 1, exception); @@ -54,7 +54,7 @@ void UpdateSemantics(Dart_NativeArguments args) { } void SetIsolateDebugName(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle exception = nullptr; const std::string name = tonic::DartConverter::FromArguments(args, 1, exception); @@ -66,14 +66,14 @@ void SetIsolateDebugName(Dart_NativeArguments args) { } void SetNeedsReportTimings(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle exception = nullptr; bool value = tonic::DartConverter::FromArguments(args, 1, exception); UIDartState::Current()->window()->client()->SetNeedsReportTimings(value); } void ReportUnhandledException(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); Dart_Handle exception = nullptr; @@ -151,7 +151,7 @@ void _RespondToPlatformMessage(Dart_NativeArguments args) { } void GetPersistentIsolateData(Dart_NativeArguments args) { - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); auto persistent_isolate_data = UIDartState::Current()->window()->client()->GetPersistentIsolateData(); @@ -280,7 +280,7 @@ void Window::UpdateSemanticsEnabled(bool enabled) { if (!dart_state) return; tonic::DartState::Scope scope(dart_state); - UIDartState::ThrowIfUIOperationsProhited(); + UIDartState::ThrowIfUIOperationsProhibited(); tonic::LogIfError(tonic::DartInvokeField( library_.value(), "_updateSemanticsEnabled", {tonic::ToDart(enabled)})); diff --git a/third_party/tonic/dart_binding_macros.h b/third_party/tonic/dart_binding_macros.h index 825ac97e4682e..f1a2ad6e9beb9 100644 --- a/third_party/tonic/dart_binding_macros.h +++ b/third_party/tonic/dart_binding_macros.h @@ -14,7 +14,7 @@ #define DART_NATIVE_CALLBACK(CLASS, METHOD) \ static void CLASS##_##METHOD(Dart_NativeArguments args) { \ - UIDartState::ThrowIfUIOperationsProhited(); \ + UIDartState::ThrowIfUIOperationsProhibited(); \ tonic::DartCall(&CLASS::METHOD, args); \ }