diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 2a14f6afbd..095c4965bc 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -350,17 +350,17 @@ bool DartIsolate::LoadLoadingUnit( loading_unit_id, dart_snapshot->GetDataMapping(), dart_snapshot->GetInstructionsMapping()); if (tonic::LogIfError(result)) { - LoadLoadingUnitFailure(loading_unit_id, Dart_GetError(result), - /*transient*/ true); + LoadLoadingUnitError(loading_unit_id, Dart_GetError(result), + /*transient*/ true); return false; } loading_unit_snapshots_.insert(dart_snapshot); return true; } -void DartIsolate::LoadLoadingUnitFailure(intptr_t loading_unit_id, - const std::string error_message, - bool transient) { +void DartIsolate::LoadLoadingUnitError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) { tonic::DartState::Scope scope(this); Dart_Handle result = Dart_DeferredLoadCompleteError( loading_unit_id, error_message.c_str(), transient); diff --git a/engine/src/flutter/runtime/dart_isolate.h b/engine/src/flutter/runtime/dart_isolate.h index a45d138fa4..457d7edc1e 100644 --- a/engine/src/flutter/runtime/dart_isolate.h +++ b/engine/src/flutter/runtime/dart_isolate.h @@ -390,9 +390,9 @@ class DartIsolate : public UIDartState { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions); - void LoadLoadingUnitFailure(intptr_t loading_unit_id, - const std::string error_message, - bool transient); + void LoadLoadingUnitError(intptr_t loading_unit_id, + const std::string error_message, + bool transient); private: friend class IsolateConfiguration; diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index 04216f5606..6e512f17f6 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -424,6 +424,14 @@ void RuntimeController::LoadDartDeferredLibrary( std::move(snapshot_instructions)); } +void RuntimeController::LoadDartDeferredLibraryError( + intptr_t loading_unit_id, + const std::string error_message, + bool transient) { + root_isolate_.lock()->LoadLoadingUnitError(loading_unit_id, error_message, + transient); +} + void RuntimeController::RequestDartDeferredLibrary(intptr_t loading_unit_id) { return client_.RequestDartDeferredLibrary(loading_unit_id); } diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 5418d065d5..5bca3a4c9d 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -510,6 +510,32 @@ class RuntimeController : public PlatformConfigurationClient { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions); + //-------------------------------------------------------------------------- + /// @brief Indicates to the dart VM that the request to load a deferred + /// library with the specified loading unit id has failed. + /// + /// The dart future returned by the initiating loadLibrary() call + /// will complete with an error. + /// + /// @param[in] loading_unit_id The unique id of the deferred library's + /// loading unit, as passed in by + /// RequestDartDeferredLibrary. + /// + /// @param[in] error_message The error message that will appear in the + /// dart Future. + /// + /// @param[in] transient A transient error is a failure due to + /// temporary conditions such as no network. + /// Transient errors allow the dart VM to + /// re-request the same deferred library and + /// and loading_unit_id again. Non-transient + /// errors are permanent and attempts to + /// re-request the library will instantly + /// complete with an error. + virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient); + // |PlatformConfigurationClient| void RequestDartDeferredLibrary(intptr_t loading_unit_id) override; diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 7ca7ae9e28..2a90326bc5 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -520,6 +520,18 @@ void Engine::LoadDartDeferredLibrary( runtime_controller_->LoadDartDeferredLibrary( loading_unit_id, std::move(snapshot_data), std::move(snapshot_instructions)); + } else { + LoadDartDeferredLibraryError(loading_unit_id, "No running root isolate.", + true); + } +} + +void Engine::LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) { + if (runtime_controller_->IsRootIsolateRunning()) { + runtime_controller_->LoadDartDeferredLibraryError(loading_unit_id, + error_message, transient); } } diff --git a/engine/src/flutter/shell/common/engine.h b/engine/src/flutter/shell/common/engine.h index 03e73c6ea3..85b7ece2c6 100644 --- a/engine/src/flutter/shell/common/engine.h +++ b/engine/src/flutter/shell/common/engine.h @@ -825,6 +825,32 @@ class Engine final : public RuntimeDelegate, std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions); + //-------------------------------------------------------------------------- + /// @brief Indicates to the dart VM that the request to load a deferred + /// library with the specified loading unit id has failed. + /// + /// The dart future returned by the initiating loadLibrary() call + /// will complete with an error. + /// + /// @param[in] loading_unit_id The unique id of the deferred library's + /// loading unit, as passed in by + /// RequestDartDeferredLibrary. + /// + /// @param[in] error_message The error message that will appear in the + /// dart Future. + /// + /// @param[in] transient A transient error is a failure due to + /// temporary conditions such as no network. + /// Transient errors allow the dart VM to + /// re-request the same deferred library and + /// and loading_unit_id again. Non-transient + /// errors are permanent and attempts to + /// re-request the library will instantly + /// complete with an error. + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient); + private: Engine::Delegate& delegate_; const Settings settings_; diff --git a/engine/src/flutter/shell/common/engine_unittests.cc b/engine/src/flutter/shell/common/engine_unittests.cc index dbf9382d60..92e1ab47f9 100644 --- a/engine/src/flutter/shell/common/engine_unittests.cc +++ b/engine/src/flutter/shell/common/engine_unittests.cc @@ -65,6 +65,8 @@ class MockRuntimeController : public RuntimeController { : RuntimeController(client, p_task_runners) {} MOCK_METHOD0(IsRootIsolateRunning, bool()); MOCK_METHOD1(DispatchPlatformMessage, bool(fml::RefPtr)); + MOCK_METHOD3(LoadDartDeferredLibraryError, + void(intptr_t, const std::string, bool)); }; fml::RefPtr MakePlatformMessage( @@ -237,4 +239,30 @@ TEST_F(EngineTest, DispatchPlatformMessageInitialRouteIgnored) { }); } +TEST_F(EngineTest, PassesLoadDartDeferredLibraryErrorToRuntime) { + PostUITaskSync([this] { + intptr_t error_id = 123; + const std::string error_message = "error message"; + MockRuntimeDelegate client; + auto mock_runtime_controller = + std::make_unique(client, task_runners_); + EXPECT_CALL(*mock_runtime_controller, IsRootIsolateRunning()) + .WillRepeatedly(::testing::Return(true)); + EXPECT_CALL(*mock_runtime_controller, + LoadDartDeferredLibraryError(error_id, error_message, true)) + .Times(1); + auto engine = std::make_unique( + /*delegate=*/delegate_, + /*dispatcher_maker=*/dispatcher_maker_, + /*image_decoder_task_runner=*/image_decoder_task_runner_, + /*task_runners=*/task_runners_, + /*settings=*/settings_, + /*animator=*/std::move(animator_), + /*io_manager=*/io_manager_, + /*runtime_controller=*/std::move(mock_runtime_controller)); + + engine->LoadDartDeferredLibraryError(error_id, error_message, true); + }); +} + } // namespace flutter diff --git a/engine/src/flutter/shell/common/platform_view.cc b/engine/src/flutter/shell/common/platform_view.cc index 9981202f02..4205e9853e 100644 --- a/engine/src/flutter/shell/common/platform_view.cc +++ b/engine/src/flutter/shell/common/platform_view.cc @@ -166,6 +166,10 @@ void PlatformView::LoadDartDeferredLibrary( std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) {} +void PlatformView::LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) {} + void PlatformView::UpdateAssetManager( std::shared_ptr asset_manager) {} diff --git a/engine/src/flutter/shell/common/platform_view.h b/engine/src/flutter/shell/common/platform_view.h index 33104bc171..56e3f6af37 100644 --- a/engine/src/flutter/shell/common/platform_view.h +++ b/engine/src/flutter/shell/common/platform_view.h @@ -247,6 +247,32 @@ class PlatformView { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) = 0; + //-------------------------------------------------------------------------- + /// @brief Indicates to the dart VM that the request to load a deferred + /// library with the specified loading unit id has failed. + /// + /// The dart future returned by the initiating loadLibrary() + /// call will complete with an error. + /// + /// @param[in] loading_unit_id The unique id of the deferred library's + /// loading unit, as passed in by + /// RequestDartDeferredLibrary. + /// + /// @param[in] error_message The error message that will appear in the + /// dart Future. + /// + /// @param[in] transient A transient error is a failure due to + /// temporary conditions such as no network. + /// Transient errors allow the dart VM to + /// re-request the same deferred library and + /// and loading_unit_id again. Non-transient + /// errors are permanent and attempts to + /// re-request the library will instantly + /// complete with an error. + virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) = 0; + // TODO(garyq): Implement a proper asset_resolver replacement instead of // overwriting the entire asset manager. //-------------------------------------------------------------------------- @@ -667,6 +693,33 @@ class PlatformView { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions); + //-------------------------------------------------------------------------- + /// @brief Indicates to the dart VM that the request to load a deferred + /// library with the specified loading unit id has failed. + /// + /// The dart future returned by the initiating loadLibrary() call + /// will complete with an error. + /// + /// @param[in] loading_unit_id The unique id of the deferred library's + /// loading unit, as passed in by + /// RequestDartDeferredLibrary. + /// + /// @param[in] error_message The error message that will appear in the + /// dart Future. + /// + /// @param[in] transient A transient error is a failure due to + /// temporary conditions such as no network. + /// Transient errors allow the dart VM to + /// re-request the same deferred library and + /// and loading_unit_id again. Non-transient + /// errors are permanent and attempts to + /// re-request the library will instantly + /// complete with an error. + /// + virtual void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient); + // TODO(garyq): Implement a proper asset_resolver replacement instead of // overwriting the entire asset manager. //-------------------------------------------------------------------------- diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 2a23ee783a..5ec02060f5 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -1193,6 +1193,13 @@ void Shell::LoadDartDeferredLibrary( std::move(snapshot_instructions)); } +void Shell::LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) { + engine_->LoadDartDeferredLibraryError(loading_unit_id, error_message, + transient); +} + void Shell::UpdateAssetManager(std::shared_ptr asset_manager) { engine_->UpdateAssetManager(std::move(asset_manager)); } diff --git a/engine/src/flutter/shell/common/shell.h b/engine/src/flutter/shell/common/shell.h index ee9821f12c..6ff3a0407b 100644 --- a/engine/src/flutter/shell/common/shell.h +++ b/engine/src/flutter/shell/common/shell.h @@ -513,6 +513,10 @@ class Shell final : public PlatformView::Delegate, std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) override; + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) override; + // |PlatformView::Delegate| void UpdateAssetManager(std::shared_ptr asset_manager) override; diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index 2d13e567b8..33bf0b4fc3 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -353,6 +353,15 @@ void PlatformViewAndroid::LoadDartDeferredLibrary( std::move(snapshot_instructions)); } +// |PlatformView| +void PlatformViewAndroid::LoadDartDeferredLibraryError( + intptr_t loading_unit_id, + const std::string error_message, + bool transient) { + delegate_.LoadDartDeferredLibraryError(loading_unit_id, error_message, + transient); +} + // |PlatformView| void PlatformViewAndroid::UpdateAssetManager( std::shared_ptr asset_manager) { diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.h b/engine/src/flutter/shell/platform/android/platform_view_android.h index 87ff5bcd91..1963120336 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.h +++ b/engine/src/flutter/shell/platform/android/platform_view_android.h @@ -99,6 +99,10 @@ class PlatformViewAndroid final : public PlatformView { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) override; + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) override; + // |PlatformView| void UpdateAssetManager(std::shared_ptr asset_manager) override; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm index ed0e554490..96fb359b96 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm @@ -38,6 +38,9 @@ class MockDelegate : public PlatformView::Delegate { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) override { } + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) override {} void UpdateAssetManager(std::shared_ptr asset_manager) override {} }; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index ee21383d2f..877320c4f6 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -108,6 +108,9 @@ class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::De std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) override { } + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) override {} void UpdateAssetManager(std::shared_ptr asset_manager) override {} }; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 677f4eac35..ee56a49a93 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -91,6 +91,9 @@ class MockDelegate : public PlatformView::Delegate { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) override { } + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) override {} void UpdateAssetManager(std::shared_ptr asset_manager) override {} }; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc index 9e05013045..3222450c04 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -110,6 +110,10 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate { std::unique_ptr snapshot_data, std::unique_ptr snapshot_instructions) {} // |flutter::PlatformView::Delegate| + void LoadDartDeferredLibraryError(intptr_t loading_unit_id, + const std::string error_message, + bool transient) {} + // |flutter::PlatformView::Delegate| void UpdateAssetManager( std::shared_ptr asset_manager) {}