diff --git a/engine/src/flutter/runtime/BUILD.gn b/engine/src/flutter/runtime/BUILD.gn index 1ed968a4d62..80e5c372a40 100644 --- a/engine/src/flutter/runtime/BUILD.gn +++ b/engine/src/flutter/runtime/BUILD.gn @@ -107,6 +107,7 @@ source_set("runtime") { ":test_font", "$dart_src/runtime:dart_api", "$dart_src/runtime/bin:dart_io_api", + "$dart_src/runtime/bin:native_assets_api", "//flutter/assets", "//flutter/common", "//flutter/flow", diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 9d063bedbe3..3dc8403506f 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -25,6 +25,7 @@ #include "fml/message_loop_task_queues.h" #include "fml/task_source.h" #include "fml/time/time_point.h" +#include "third_party/dart/runtime/include/bin/native_assets_api.h" #include "third_party/dart/runtime/include/dart_api.h" #include "third_party/dart/runtime/include/dart_tools_api.h" #include "third_party/tonic/converter/dart_converter.h" @@ -1165,6 +1166,27 @@ bool DartIsolate::DartIsolateInitializeCallback(void** child_callback_data, return true; } +static void* NativeAssetsDlopenRelative(const char* path, char** error) { + auto* isolate_group_data = + static_cast*>( + Dart_CurrentIsolateGroupData()); + const std::string& script_uri = (*isolate_group_data)->GetAdvisoryScriptURI(); + return dart::bin::NativeAssets::DlopenRelative(path, script_uri.data(), + error); +} + +static void InitDartFFIForIsolateGroup() { + NativeAssetsApi native_assets; + memset(&native_assets, 0, sizeof(native_assets)); + native_assets.dlopen_absolute = &dart::bin::NativeAssets::DlopenAbsolute; + native_assets.dlopen_relative = &NativeAssetsDlopenRelative; + native_assets.dlopen_system = &dart::bin::NativeAssets::DlopenSystem; + native_assets.dlopen_executable = &dart::bin::NativeAssets::DlopenExecutable; + native_assets.dlopen_process = &dart::bin::NativeAssets::DlopenProcess; + native_assets.dlsym = &dart::bin::NativeAssets::Dlsym; + Dart_InitializeNativeAssetsResolver(&native_assets); +}; + Dart_Isolate DartIsolate::CreateDartIsolateGroup( std::unique_ptr> isolate_group_data, std::unique_ptr> isolate_data, @@ -1191,6 +1213,8 @@ Dart_Isolate DartIsolate::CreateDartIsolateGroup( isolate_data.release(); // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks) + InitDartFFIForIsolateGroup(); + success = InitializeIsolate(embedder_isolate, isolate, error); } if (!success) {