diff --git a/engine/src/flutter/lib/ui/hooks.dart b/engine/src/flutter/lib/ui/hooks.dart index 0a06d3ccd4..91cdfdb615 100644 --- a/engine/src/flutter/lib/ui/hooks.dart +++ b/engine/src/flutter/lib/ui/hooks.dart @@ -4,6 +4,14 @@ part of dart_ui; +String _decodeUTF8(ByteData message) { + return message != null ? UTF8.decoder.convert(message.buffer.asUint8List()) : null; +} + +dynamic _decodeJSON(String message) { + return message != null ? JSON.decode(message) : null; +} + void _updateWindowMetrics(double devicePixelRatio, double width, double height, @@ -32,19 +40,25 @@ void _updateSemanticsEnabled(bool enabled) { window.onSemanticsEnabledChanged(); } -void _pushRoute(String route) { - assert(window._defaultRouteName == null); - window._defaultRouteName = route; - // TODO(abarth): If we ever start calling _pushRoute other than before main, - // we should add a change notification callback. -} - -void _popRoute() { - if (window.onPopRoute != null) - window.onPopRoute(); +void _handleNavigationMessage(ByteData data) { + if (window._defaultRouteName != null) + return; + try { + final dynamic message = _decodeJSON(_decodeUTF8(data)); + final dynamic method = message['method']; + if (method != 'pushRoute') + return; + final dynamic args = message['args']; + window._defaultRouteName = args[0]; + } catch (e) { + // We ignore any exception and just let the message be dispatched as usual. + } } void _dispatchPlatformMessage(String name, ByteData data, int responseId) { + if (name == 'flutter/navigation') + _handleNavigationMessage(data); + if (window.onPlatformMessage != null) { window.onPlatformMessage(name, data, (ByteData responseData) { window._respondToPlatformMessage(responseId, responseData); @@ -69,11 +83,6 @@ void _beginFrame(int microseconds) { window.onBeginFrame(new Duration(microseconds: microseconds)); } -void _onAppLifecycleStateChanged(int state) { - if (window.onAppLifecycleStateChanged != null) - window.onAppLifecycleStateChanged(AppLifecycleState.values[state]); -} - // If this value changes, update the encoding code in the following files: // // * pointer_data.cc diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index ad45562019..972dd152f5 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -16,9 +16,6 @@ typedef void PointerDataPacketCallback(PointerDataPacket packet); /// Signature for [Window.onSemanticsAction]. typedef void SemanticsActionCallback(int id, SemanticsAction action); -/// Signature for [Window.onAppLifecycleStateChanged]. -typedef void AppLifecycleStateCallback(AppLifecycleState state); - /// Signature for responses to platform messages. /// /// Used as a parameter to [Window.sendPlatformMessage] and @@ -148,10 +145,6 @@ class Window { /// A callback that is invoked whenever [locale] changes value. VoidCallback onLocaleChanged; - /// A callback that is invoked when there is a transition in the application's - /// lifecycle (such as pausing or resuming). - AppLifecycleStateCallback onAppLifecycleStateChanged; - /// A callback that is invoked to notify the application that it is an /// appropriate time to provide a scene using the [SceneBuilder] API and the /// [render] method. When possible, this is driven by the hardware VSync @@ -167,11 +160,6 @@ class Window { String get defaultRouteName => _defaultRouteName; String _defaultRouteName; - /// A callback that is invoked when the operating system requests that the - /// application goes "back" one step in its history. For example, on Android - /// this is invoked in response to the "back" button. - VoidCallback onPopRoute; - /// Requests that, at the next appropriate opportunity, the [onBeginFrame] /// callback be invoked. void scheduleFrame() native "Window_scheduleFrame"; diff --git a/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index 7e1795f0fd..f674c009a7 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/lib/ui/window/window.cc @@ -157,26 +157,6 @@ void Window::UpdateSemanticsEnabled(bool enabled) { {ToDart(enabled)}); } -void Window::PushRoute(const std::string& route) { - tonic::DartState* dart_state = library_.dart_state().get(); - if (!dart_state) - return; - tonic::DartState::Scope scope(dart_state); - - DartInvokeField(library_.value(), "_pushRoute", { - StdStringToDart(route), - }); -} - -void Window::PopRoute() { - tonic::DartState* dart_state = library_.dart_state().get(); - if (!dart_state) - return; - tonic::DartState::Scope scope(dart_state); - - DartInvokeField(library_.value(), "_popRoute", {}); -} - void Window::DispatchPlatformMessage(ftl::RefPtr message) { tonic::DartState* dart_state = library_.dart_state().get(); if (!dart_state) @@ -235,16 +215,6 @@ void Window::BeginFrame(ftl::TimePoint frameTime) { }); } -void Window::OnAppLifecycleStateChanged(sky::AppLifecycleState state) { - tonic::DartState* dart_state = library_.dart_state().get(); - if (!dart_state) - return; - tonic::DartState::Scope scope(dart_state); - - DartInvokeField(library_.value(), "_onAppLifecycleStateChanged", - {ToDart(static_cast(state))}); -} - void Window::CompletePlatformMessageResponse(int response_id, std::vector data) { if (!response_id) diff --git a/engine/src/flutter/lib/ui/window/window.h b/engine/src/flutter/lib/ui/window/window.h index 3c61619095..1bb97f797d 100644 --- a/engine/src/flutter/lib/ui/window/window.h +++ b/engine/src/flutter/lib/ui/window/window.h @@ -49,11 +49,6 @@ class Window { void DispatchSemanticsAction(int32_t id, SemanticsAction action); void BeginFrame(ftl::TimePoint frameTime); - void PushRoute(const std::string& route); - void PopRoute(); - - void OnAppLifecycleStateChanged(sky::AppLifecycleState state); - void CompletePlatformMessageResponse(int response_id, std::vector data); diff --git a/engine/src/flutter/runtime/dart_vm_entry_points.txt b/engine/src/flutter/runtime/dart_vm_entry_points.txt index 26a733b244..0500cd4145 100644 --- a/engine/src/flutter/runtime/dart_vm_entry_points.txt +++ b/engine/src/flutter/runtime/dart_vm_entry_points.txt @@ -10,9 +10,6 @@ dart:ui,::,_getGetBaseURLClosure dart:ui,::,_getMainClosure dart:ui,::,_getPrintClosure dart:ui,::,_getScheduleMicrotaskClosure -dart:ui,::,_onAppLifecycleStateChanged -dart:ui,::,_popRoute -dart:ui,::,_pushRoute dart:ui,::,_setupHooks dart:ui,::,_updateLocale dart:ui,::,_updateSemanticsEnabled diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index 47ca2f660f..2d82c5b203 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -76,14 +76,6 @@ void RuntimeController::SetSemanticsEnabled(bool enabled) { GetWindow()->UpdateSemanticsEnabled(semantics_enabled_); } -void RuntimeController::PushRoute(const std::string& route) { - GetWindow()->PushRoute(route); -} - -void RuntimeController::PopRoute() { - GetWindow()->PopRoute(); -} - void RuntimeController::BeginFrame(ftl::TimePoint frame_time) { GetWindow()->BeginFrame(frame_time); } @@ -132,11 +124,6 @@ void RuntimeController::DidCreateSecondaryIsolate(Dart_Isolate isolate) { client_->DidCreateSecondaryIsolate(isolate); } -void RuntimeController::OnAppLifecycleStateChanged( - sky::AppLifecycleState state) { - GetWindow()->OnAppLifecycleStateChanged(state); -} - Dart_Port RuntimeController::GetMainPort() { if (!dart_controller_) { return ILLEGAL_PORT; diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 445aaad2b7..7cc78cd973 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -34,8 +34,6 @@ class RuntimeController : public WindowClient, public IsolateClient { void SetLocale(const std::string& language_code, const std::string& country_code); void SetSemanticsEnabled(bool enabled); - void PushRoute(const std::string& route); - void PopRoute(); void BeginFrame(ftl::TimePoint frame_time); @@ -43,8 +41,6 @@ class RuntimeController : public WindowClient, public IsolateClient { void DispatchPointerDataPacket(const PointerDataPacket& packet); void DispatchSemanticsAction(int32_t id, SemanticsAction action); - void OnAppLifecycleStateChanged(sky::AppLifecycleState state); - Dart_Port GetMainPort(); std::string GetIsolateName(); diff --git a/engine/src/flutter/shell/common/BUILD.gn b/engine/src/flutter/shell/common/BUILD.gn index cee06445e7..4fd34c1ef5 100644 --- a/engine/src/flutter/shell/common/BUILD.gn +++ b/engine/src/flutter/shell/common/BUILD.gn @@ -69,6 +69,7 @@ source_set("common") { "//mojo/public/interfaces/application", "//mojo/services/vsync/interfaces", "//third_party/libjpeg", + "//third_party/rapidjson", ":generate_embedder_diagnostic_server_resources_cc", ] } diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 472b0c63a1..c2ef12d716 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -24,13 +24,17 @@ #include "lib/ftl/files/path.h" #include "lib/ftl/functional/make_copyable.h" #include "mojo/public/cpp/application/connect.h" +#include "third_party/rapidjson/rapidjson/document.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPictureRecorder.h" namespace shell { namespace { -constexpr char kAssetPluginChannel[] = "flutter/assets"; +constexpr char kAssetChannel[] = "flutter/assets"; +constexpr char kLifecycleChannel[] = "flutter/lifecycle"; +constexpr char kNavigationChannel[] = "flutter/navigation"; +constexpr char kLocalizationChannel[] = "flutter/localization"; bool PathExists(const std::string& path) { return access(path.c_str(), R_OK) == 0; @@ -127,18 +131,85 @@ void Engine::OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) { runtime_->SetViewportMetrics(viewport_metrics_); } -void Engine::OnLocaleChanged(const mojo::String& language_code, - const mojo::String& country_code) { - language_code_ = language_code; - country_code_ = country_code; - if (runtime_) - runtime_->SetLocale(language_code_, country_code_); -} - void Engine::DispatchPlatformMessage( ftl::RefPtr message) { - if (runtime_) + if (message->channel() == kLifecycleChannel) { + if (HandleLifecyclePlatformMessage(message.get())) + return; + } else if (message->channel() == kLocalizationChannel) { + if (HandleLocalizationPlatformMessage(std::move(message))) + return; + } + + if (runtime_) { runtime_->DispatchPlatformMessage(std::move(message)); + return; + } + + // If there's no runtime_, we need to buffer some navigation messages. + if (message->channel() == kNavigationChannel) + HandleNavigationPlatformMessage(std::move(message)); +} + +bool Engine::HandleLifecyclePlatformMessage(blink::PlatformMessage* message) { + const auto& data = message->data(); + std::string state(reinterpret_cast(data.data()), data.size()); + if (state == "AppLifecycleState.paused") { + activity_running_ = false; + StopAnimator(); + } else if (state == "AppLifecycleState.resumed") { + activity_running_ = true; + StartAnimatorIfPossible(); + } + return false; +} + +bool Engine::HandleNavigationPlatformMessage( + ftl::RefPtr message) { + FTL_DCHECK(!runtime_); + const auto& data = message->data(); + + rapidjson::Document document; + document.Parse(reinterpret_cast(data.data()), data.size()); + if (document.HasParseError() || !document.IsObject()) + return false; + auto root = document.GetObject(); + auto method = root.FindMember("method"); + if (method == root.MemberEnd() || method->value != "pushRoute") + return false; + + pending_push_route_message_ = std::move(message); + return true; +} + +bool Engine::HandleLocalizationPlatformMessage( + ftl::RefPtr message) { + const auto& data = message->data(); + + rapidjson::Document document; + document.Parse(reinterpret_cast(data.data()), data.size()); + if (document.HasParseError() || !document.IsObject()) + return false; + auto root = document.GetObject(); + auto method = root.FindMember("method"); + if (method == root.MemberEnd() || method->value != "setLocale") + return false; + + auto args = root.FindMember("args"); + if (args == root.MemberEnd() || !args->value.IsArray()) + return false; + + const auto& language = args->value[0]; + const auto& country = args->value[1]; + + if (!language.IsString() || !country.IsString()) + return false; + + language_code_ = language.GetString(); + country_code_ = country.GetString(); + if (runtime_) + runtime_->SetLocale(language_code_, country_code_); + return true; } void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet) { @@ -206,8 +277,8 @@ void Engine::ConfigureRuntime(const std::string& script_uri) { runtime_->SetViewportMetrics(viewport_metrics_); runtime_->SetLocale(language_code_, country_code_); runtime_->SetSemanticsEnabled(semantics_enabled_); - if (!initial_route_.empty()) - runtime_->PushRoute(initial_route_); + if (pending_push_route_message_) + runtime_->DispatchPlatformMessage(std::move(pending_push_route_message_)); } void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) { @@ -247,35 +318,6 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri, RunFromSnapshotStream(script_uri, std::move(pipe.consumer_handle)); } -void Engine::PushRoute(const mojo::String& route) { - if (runtime_) - runtime_->PushRoute(route); - else - initial_route_ = route; -} - -void Engine::PopRoute() { - if (runtime_) - runtime_->PopRoute(); -} - -void Engine::OnAppLifecycleStateChanged(sky::AppLifecycleState state) { - switch (state) { - case sky::AppLifecycleState::PAUSED: - activity_running_ = false; - StopAnimator(); - break; - - case sky::AppLifecycleState::RESUMED: - activity_running_ = true; - StartAnimatorIfPossible(); - break; - } - - if (runtime_) - runtime_->OnAppLifecycleStateChanged(state); -} - void Engine::DidCreateMainIsolate(Dart_Isolate isolate) { if (asset_store_) blink::AssetFontSelector::Install(asset_store_); @@ -322,7 +364,7 @@ void Engine::UpdateSemantics(std::vector update) { void Engine::HandlePlatformMessage( ftl::RefPtr message) { - if (message->channel() == kAssetPluginChannel) { + if (message->channel() == kAssetChannel) { HandleAssetPlatformMessage(std::move(message)); return; } diff --git a/engine/src/flutter/shell/common/engine.h b/engine/src/flutter/shell/common/engine.h index ab78cab12e..90f4050be5 100644 --- a/engine/src/flutter/shell/common/engine.h +++ b/engine/src/flutter/shell/common/engine.h @@ -64,9 +64,6 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate { private: // SkyEngine implementation: void OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) override; - void OnLocaleChanged(const mojo::String& language_code, - const mojo::String& country_code) override; - void RunFromFile(const mojo::String& main, const mojo::String& packages, const mojo::String& bundle) override; @@ -76,9 +73,6 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate { void RunFromBundleAndSnapshot(const mojo::String& script_uri, const mojo::String& bundle_path, const mojo::String& snapshot_path) override; - void PushRoute(const mojo::String& route) override; - void PopRoute() override; - void OnAppLifecycleStateChanged(sky::AppLifecycleState state) override; // RuntimeDelegate methods: void ScheduleFrame() override; @@ -98,6 +92,12 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate { void ConfigureAssetBundle(const std::string& path); void ConfigureRuntime(const std::string& script_uri); + bool HandleLifecyclePlatformMessage(blink::PlatformMessage* message); + bool HandleNavigationPlatformMessage( + ftl::RefPtr message); + bool HandleLocalizationPlatformMessage( + ftl::RefPtr message); + void HandleAssetPlatformMessage(ftl::RefPtr message); ftl::WeakPtr platform_view_; @@ -108,7 +108,7 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate { std::unique_ptr snapshot_drainer_; - std::string initial_route_; + ftl::RefPtr pending_push_route_message_; sky::ViewportMetricsPtr viewport_metrics_; std::string language_code_; std::string country_code_; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index c0c70ac1d0..216d9baec0 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -30,6 +30,7 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -42,8 +43,6 @@ import org.chromium.mojo.system.MessagePipeHandle; import org.chromium.mojo.system.MojoException; import org.chromium.mojo.system.Pair; import org.chromium.mojo.system.impl.CoreImpl; -import org.chromium.mojom.mojo.ServiceProvider; -import org.chromium.mojom.sky.AppLifecycleState; import org.chromium.mojom.sky.SkyEngine; import org.chromium.mojom.sky.ViewportMetrics; @@ -185,35 +184,57 @@ public class FlutterView extends SurfaceView return super.onKeyDown(keyCode, event); } - SkyEngine getEngine() { - return mSkyEngine; - } - public void addActivityLifecycleListener(ActivityLifecycleListener listener) { mActivityLifecycleListeners.add(listener); } public void onPause() { - mSkyEngine.onAppLifecycleStateChanged(AppLifecycleState.PAUSED); + sendPlatformMessage("flutter/lifecycle", "AppLifecycleState.paused", null); } public void onPostResume() { for (ActivityLifecycleListener listener : mActivityLifecycleListeners) listener.onPostResume(); - mSkyEngine.onAppLifecycleStateChanged(AppLifecycleState.RESUMED); + sendPlatformMessage("flutter/lifecycle", "AppLifecycleState.resumed", null); } public void pushRoute(String route) { - mSkyEngine.pushRoute(route); + try { + final JSONArray args = new JSONArray(); + args.put(0, route); + final JSONObject message = new JSONObject(); + message.put("method", "pushRoute"); + message.put("args", args); + sendPlatformMessage("flutter/navigation", message.toString(), null); + } catch (JSONException e) { + Log.e(TAG, "Unexpected JSONException pushing route", e); + } } public void popRoute() { - mSkyEngine.popRoute(); + try { + final JSONObject message = new JSONObject(); + message.put("method", "popRoute"); + message.put("args", new JSONArray()); + sendPlatformMessage("flutter/navigation", message.toString(), null); + } catch (JSONException e) { + Log.e(TAG, "Unexpected JSONException pushing route", e); + } } private void setLocale(Locale locale) { - mSkyEngine.onLocaleChanged(locale.getLanguage(), locale.getCountry()); + try { + final JSONArray args = new JSONArray(); + args.put(0, locale.getLanguage()); + args.put(1, locale.getCountry()); + final JSONObject message = new JSONObject(); + message.put("method", "setLocale"); + message.put("args", args); + sendPlatformMessage("flutter/localization", message.toString(), null); + } catch (JSONException e) { + Log.e(TAG, "Unexpected JSONException pushing route", e); + } } @Override diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 0b4ab8b598..72fb737d45 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -42,7 +42,8 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { void CompleteWithError() override { Complete(std::vector()); } private: - explicit PlatformMessageResponseDarwin(PlatformMessageResponseCallback callback) + explicit PlatformMessageResponseDarwin( + PlatformMessageResponseCallback callback) : callback_(callback, base::scoped_policy::RETAIN) {} base::mac::ScopedBlock callback_; @@ -50,7 +51,8 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { } // namespace -@interface FlutterViewController () +@interface FlutterViewController () @end void FlutterInit(int argc, const char* argv[]) { @@ -118,7 +120,6 @@ void FlutterInit(int argc, const char* argv[]) { _platformPlugin.reset([[FlutterPlatformPlugin alloc] init]); [self addMessageListener:_platformPlugin.get()]; - _textInputPlugin.reset([[FlutterTextInputPlugin alloc] init]); _textInputPlugin.get().textInputDelegate = self; [self addMessageListener:_textInputPlugin.get()]; @@ -219,17 +220,13 @@ void FlutterInit(int argc, const char* argv[]) { #pragma mark - Application lifecycle notifications - (void)applicationBecameActive:(NSNotification*)notification { - auto& engine = _platformView->engineProxy(); - if (engine) { - engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::RESUMED); - } + [self sendString:@"AppLifecycleState.resumed" + withMessageName:@"flutter/lifecycle"]; } - (void)applicationWillResignActive:(NSNotification*)notification { - auto& engine = _platformView->engineProxy(); - if (engine) { - engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::PAUSED); - } + [self sendString:@"AppLifecycleState.paused" + withMessageName:@"flutter/lifecycle"]; } #pragma mark - Touch event handling @@ -367,10 +364,11 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( #pragma mark - Text input delegate - (void)updateEditingClient:(int)client withState:(NSDictionary*)state { - [self sendJSON:@{ - @"method": @"TextInputClient.updateEditingState", - @"args": @[@(client), state], - } withMessageName:@"flutter/textinputclient"]; + NSDictionary* message = @{ + @"method" : @"TextInputClient.updateEditingState", + @"args" : @[ @(client), state ], + }; + [self sendJSON:message withMessageName:@"flutter/textinputclient"]; } #pragma mark - Orientation updates @@ -380,8 +378,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary* info = notification.userInfo; - NSNumber* update = - info[@(shell::kOrientationUpdateNotificationKey)]; + NSNumber* update = info[@(shell::kOrientationUpdateNotificationKey)]; if (update == nil) { return; @@ -424,8 +421,10 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( NSLocale* currentLocale = [NSLocale currentLocale]; NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode]; NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; - _platformView->engineProxy()->OnLocaleChanged(languageCode.UTF8String, - countryCode.UTF8String); + NSDictionary* message = + @{ @"method" : @"setLocale", + @"args" : @[ languageCode, countryCode ] }; + [self sendJSON:message withMessageName:@"flutter/localization"]; } #pragma mark - Surface creation and teardown updates @@ -471,8 +470,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary* info = notification.userInfo; - NSNumber* update = - info[@(shell::kOverlayStyleUpdateNotificationKey)]; + NSNumber* update = info[@(shell::kOverlayStyleUpdateNotificationKey)]; if (update == nil) { return; @@ -494,9 +492,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( NSAssert(channel, @"The channel must not be null"); _platformView->DispatchPlatformMessage( ftl::MakeRefCounted( - channel.UTF8String, - shell::GetVectorFromNSString(message), - nullptr)); + channel.UTF8String, shell::GetVectorFromNSString(message), nullptr)); } - (void)sendString:(NSString*)message @@ -507,20 +503,19 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( NSAssert(callback, @"The callback must not be null"); _platformView->DispatchPlatformMessage( ftl::MakeRefCounted( - channel.UTF8String, - shell::GetVectorFromNSString(message), + channel.UTF8String, shell::GetVectorFromNSString(message), ftl::MakeRefCounted(callback))); } - (void)sendJSON:(NSDictionary*)message withMessageName:(NSString*)channel { - NSData* data = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil]; + NSData* data = + [NSJSONSerialization dataWithJSONObject:message options:0 error:nil]; if (!data) return; const uint8_t* bytes = static_cast(data.bytes); _platformView->DispatchPlatformMessage( ftl::MakeRefCounted( - channel.UTF8String, - std::vector(bytes, bytes + data.length), + channel.UTF8String, std::vector(bytes, bytes + data.length), nullptr)); } @@ -528,16 +523,16 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( NSAssert(listener, @"The listener must not be null"); NSString* channel = listener.messageName; NSAssert(channel, @"The channel must not be null"); - _platformView->platform_message_router().SetMessageListener(channel.UTF8String, - listener); + _platformView->platform_message_router().SetMessageListener( + channel.UTF8String, listener); } - (void)removeMessageListener:(NSObject*)listener { NSAssert(listener, @"The listener must not be null"); NSString* channel = listener.messageName; NSAssert(channel, @"The channel must not be null"); - _platformView->platform_message_router().SetMessageListener(channel.UTF8String, - nil); + _platformView->platform_message_router().SetMessageListener( + channel.UTF8String, nil); } - (void)addAsyncMessageListener: