From f648cce30f5621df5abe9577beb6692887973c58 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 2 Oct 2024 11:31:49 -0700 Subject: [PATCH 01/31] iOS: Migrate FlutterEngine to ARC Migrates `FlutterEnging` from manual reference counting to ARC. Migrates properties from `retain` to strong and `assign` to `weak` (where referencing an Obj-C object). No semantic changes, therefore no changes to tests. Issue: https://github.com/flutter/flutter/issues/137801 --- shell/platform/darwin/ios/BUILD.gn | 4 +- .../ios/framework/Source/FlutterEngine.mm | 92 +++++++------------ .../framework/Source/FlutterPlatformPlugin.h | 2 +- .../framework/Source/FlutterPlatformPlugin.mm | 2 +- .../Source/FlutterPlatformPluginTest.mm | 53 ++--------- 5 files changed, 48 insertions(+), 105 deletions(-) diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index 6bd0397b26b9f..5e197c315828e 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -70,7 +70,9 @@ source_set("flutter_framework_source_arc") { "framework/Source/FlutterDartVMServicePublisher.mm", "framework/Source/FlutterEmbedderKeyResponder.h", "framework/Source/FlutterEmbedderKeyResponder.mm", + "framework/Source/FlutterEngine.mm", "framework/Source/FlutterEngineGroup.mm", + "framework/Source/FlutterEngine_Internal.h", "framework/Source/FlutterHeadlessDartRunner.mm", "framework/Source/FlutterKeyPrimaryResponder.h", "framework/Source/FlutterKeySecondaryResponder.h", @@ -186,8 +188,6 @@ source_set("flutter_framework_source") { # iOS embedder is migrating to ARC. # New files are highly encouraged to be in ARC. # To add new files in ARC, add them to the `flutter_framework_source_arc` target. - "framework/Source/FlutterEngine.mm", - "framework/Source/FlutterEngine_Internal.h", "framework/Source/FlutterViewController.mm", "framework/Source/FlutterViewController_Internal.h", "platform_view_ios.h", diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 713d4fd0e288f..473a669f52dac 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -42,6 +42,8 @@ #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/shell/profiling/sampling_profiler.h" +FLUTTER_ASSERT_ARC + /// Inheriting ThreadConfigurer and use iOS platform thread API to configure the thread priorities /// Using iOS platform thread API to configure thread priority static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig& config) { @@ -88,7 +90,7 @@ static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig& confi static constexpr int kNumProfilerSamplesPerSec = 5; @interface FlutterEngineRegistrar : NSObject -@property(nonatomic, assign) FlutterEngine* flutterEngine; +@property(nonatomic, weak) FlutterEngine* flutterEngine; - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine*)flutterEngine; @end @@ -104,7 +106,7 @@ @interface FlutterEngine () flutterViewControllerWillDeallocObserver; +@property(nonatomic, strong) id flutterViewControllerWillDeallocObserver; #pragma mark - Embedder API properties @@ -118,7 +120,6 @@ @implementation FlutterEngine { std::shared_ptr _threadHost; std::unique_ptr _shell; NSString* _labelPrefix; - std::unique_ptr> _weakFactory; fml::WeakNSObject _viewController; fml::scoped_nsobject _publisher; @@ -191,12 +192,10 @@ - (instancetype)initWithName:(NSString*)labelPrefix _allowHeadlessExecution = allowHeadlessExecution; _labelPrefix = [labelPrefix copy]; - _weakFactory = std::make_unique>(self); - if (project == nil) { _dartProject.reset([[FlutterDartProject alloc] init]); } else { - _dartProject.reset([project retain]); + _dartProject.reset(project); } _enableEmbedderAPI = _dartProject.get().settings.enable_embedder_api; @@ -212,7 +211,6 @@ - (instancetype)initWithName:(NSString*)labelPrefix @"Xcode.\n\nTo launch in debug mode in iOS 14+, run flutter run from Flutter tools, run " @"from an IDE with a Flutter IDE plugin or run the iOS project from Xcode.\nAlternatively " @"profile and release mode apps can be launched from the home screen."); - [self release]; return nil; } @@ -292,35 +290,20 @@ - (void)dealloc { object:self userInfo:nil]; - // It will be destroyed and invalidate its weak pointers - // before any other members are destroyed. - _weakFactory.reset(); - /// nil out weak references. [_registrars enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineRegistrar* registrar, BOOL* stop) { registrar.flutterEngine = nil; }]; - [_labelPrefix release]; - [_initialRoute release]; - [_pluginPublications release]; - [_registrars release]; _binaryMessenger.parent = nil; _textureRegistry.parent = nil; - [_binaryMessenger release]; - [_textureRegistry release]; - _textureRegistry = nil; - [_isolateId release]; NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; if (_flutterViewControllerWillDeallocObserver) { [center removeObserver:_flutterViewControllerWillDeallocObserver]; - [_flutterViewControllerWillDeallocObserver release]; } [center removeObserver:self]; - - [super dealloc]; } - (flutter::Shell&)shell { @@ -328,10 +311,6 @@ - (void)dealloc { return *_shell; } -- (fml::WeakNSObject)getWeakNSObject { - return _weakFactory->GetWeakNSObject(); -} - - (void)updateViewportMetrics:(flutter::ViewportMetrics)viewportMetrics { if (!self.platformView) { return; @@ -432,7 +411,7 @@ - (void)setViewController:(FlutterViewController*)viewController { _textInputPlugin.get().viewController = viewController; if (viewController) { - __block FlutterEngine* blockSelf = self; + __weak __block FlutterEngine* blockSelf = self; self.flutterViewControllerWillDeallocObserver = [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc object:viewController @@ -455,9 +434,8 @@ - (void)setFlutterViewControllerWillDeallocObserver:(id)observer { if (_flutterViewControllerWillDeallocObserver) { [[NSNotificationCenter defaultCenter] removeObserver:_flutterViewControllerWillDeallocObserver]; - [_flutterViewControllerWillDeallocObserver release]; } - _flutterViewControllerWillDeallocObserver = [observer retain]; + _flutterViewControllerWillDeallocObserver = observer; } } @@ -571,9 +549,15 @@ - (void)resetChannels { - (void)startProfiler { FML_DCHECK(!_threadHost->name_prefix.empty()); _profiler_metrics = std::make_shared(); + __weak FlutterEngine* weakSelf = self; _profiler = std::make_shared( _threadHost->name_prefix.c_str(), _threadHost->profiler_thread->GetTaskRunner(), - [self]() { return self->_profiler_metrics->GenerateSample(); }, kNumProfilerSamplesPerSec); + [weakSelf]() { + FlutterEngine* strongSelf = weakSelf; + return strongSelf ? strongSelf->_profiler_metrics->GenerateSample() + : flutter::ProfileSample{}; + }, + kNumProfilerSamplesPerSec); _profiler->Start(); } @@ -583,11 +567,11 @@ - (void)startProfiler { - (void)setUpChannels { // This will be invoked once the shell is done setting up and the isolate ID // for the UI isolate is available. - fml::WeakNSObject weakSelf = [self getWeakNSObject]; + __weak FlutterEngine* weakSelf = self; [_binaryMessenger setMessageHandlerOnChannel:@"flutter/isolate" binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) { if (weakSelf) { - weakSelf.get().isolateId = + weakSelf.isolateId = [[FlutterStringCodec sharedInstance] decode:message]; } }]; @@ -605,7 +589,6 @@ - (void)setUpChannels { if ([_initialRoute length] > 0) { // Flutter isn't ready to receive this method call yet but the channel buffer will cache this. [_navigationChannel invokeMethod:@"setInitialRoute" arguments:_initialRoute]; - [_initialRoute release]; _initialRoute = nil; } @@ -673,7 +656,7 @@ - (void)setUpChannels { [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; _undoManagerPlugin.reset(undoManagerPlugin); - _platformPlugin.reset([[FlutterPlatformPlugin alloc] initWithEngine:[self getWeakNSObject]]); + _platformPlugin.reset([[FlutterPlatformPlugin alloc] initWithEngine:self]); _restorationPlugin.reset([[FlutterRestorationPlugin alloc] initWithChannel:_restorationChannel.get() @@ -687,15 +670,15 @@ - (void)setUpChannels { [_screenshotChannel.get() setMethodCallHandler:^(FlutterMethodCall* _Nonnull call, FlutterResult _Nonnull result) { - if (!(weakSelf.get() && weakSelf.get()->_shell && weakSelf.get()->_shell->IsSetup())) { + FlutterEngine* strongSelf = weakSelf; + if (!(strongSelf && strongSelf->_shell && strongSelf->_shell->IsSetup())) { return result([FlutterError errorWithCode:@"invalid_state" message:@"Requesting screenshot while engine is not running." details:nil]); } flutter::Rasterizer::Screenshot screenshot = - [weakSelf.get() screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData - base64Encode:NO]; + [weakSelf screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData base64Encode:NO]; if (!screenshot.data) { return result([FlutterError errorWithCode:@"failure" message:@"Unable to get screenshot." @@ -718,11 +701,11 @@ - (void)maybeSetupPlatformViewChannels { [platformPlugin handleMethodCall:call result:result]; }]; - fml::WeakNSObject weakSelf = [self getWeakNSObject]; + __weak FlutterEngine* weakSelf = self; [_platformViewsChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { if (weakSelf) { - weakSelf.get().platformViewsController->OnMethodCall(call, result); + weakSelf.platformViewsController->OnMethodCall(call, result); } }]; @@ -862,16 +845,17 @@ - (BOOL)createShell:(NSString*)entrypoint _threadHost = std::make_shared(); *_threadHost = MakeThreadHost(threadLabel, settings); - // Lambda captures by pointers to ObjC objects are fine here because the - // create call is synchronous. + __weak FlutterEngine* weakSelf = self; flutter::Shell::CreateCallback on_create_platform_view = - [self](flutter::Shell& shell) { - [self recreatePlatformViewController]; - self->_platformViewsController->SetTaskRunner( + [weakSelf](flutter::Shell& shell) { + FlutterEngine* strongSelf = weakSelf; + [strongSelf recreatePlatformViewController]; + strongSelf->_platformViewsController->SetTaskRunner( shell.GetTaskRunners().GetPlatformTaskRunner()); return std::make_unique( - shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners(), - shell.GetConcurrentWorkerTaskRunner(), shell.GetIsGpuDisabledSyncSwitch()); + shell, strongSelf->_renderingApi, strongSelf->_platformViewsController, + shell.GetTaskRunners(), shell.GetConcurrentWorkerTaskRunner(), + shell.GetIsGpuDisabledSyncSwitch()); }; flutter::Shell::CreateCallback on_create_rasterizer = @@ -1244,8 +1228,7 @@ - (void)setBinaryMessenger:(FlutterBinaryMessengerRelay*)binaryMessenger { // Discard the previous messenger and keep the new one. if (binaryMessenger != _binaryMessenger) { _binaryMessenger.parent = nil; - [_binaryMessenger release]; - _binaryMessenger = [binaryMessenger retain]; + _binaryMessenger = binaryMessenger; } } @@ -1350,7 +1333,7 @@ - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package { FlutterEngineRegistrar* result = [[FlutterEngineRegistrar alloc] initWithPlugin:pluginKey flutterEngine:self]; self.registrars[pluginKey] = result; - return [result autorelease]; + return result; } - (BOOL)hasPlugin:(NSString*)pluginKey { @@ -1406,10 +1389,10 @@ - (void)setIsGpuDisabled:(BOOL)value { - (void)onLocaleUpdated:(NSNotification*)notification { // Get and pass the user's preferred locale list to dart:ui. - NSMutableArray* localeData = [[[NSMutableArray alloc] init] autorelease]; + NSMutableArray* localeData = [[NSMutableArray alloc] init]; NSArray* preferredLocales = [NSLocale preferredLanguages]; for (NSString* localeID in preferredLocales) { - NSLocale* locale = [[[NSLocale alloc] initWithLocaleIdentifier:localeID] autorelease]; + NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:localeID]; NSString* languageCode = [locale objectForKey:NSLocaleLanguageCode]; NSString* countryCode = [locale objectForKey:NSLocaleCountryCode]; NSString* scriptCode = [locale objectForKey:NSLocaleScriptCode]; @@ -1489,7 +1472,7 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint result->_profiler_metrics = _profiler_metrics; result->_isGpuDisabled = _isGpuDisabled; [result setUpShell:std::move(shell) withVMServicePublication:NO]; - return [result autorelease]; + return result; } - (const flutter::ThreadHost&)threadHost { @@ -1518,11 +1501,6 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine return self; } -- (void)dealloc { - [_pluginKey release]; - [super dealloc]; -} - - (NSObject*)messenger { return _flutterEngine.binaryMessenger; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h index d3252d27b2ecb..71f79c2ba42e5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h @@ -12,7 +12,7 @@ @interface FlutterPlatformPlugin : NSObject - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; -- (instancetype)initWithEngine:(fml::WeakNSObject)engine NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithEngine:(FlutterEngine*)engine NS_DESIGNATED_INITIALIZER; - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index 283a2731fe884..c8a0dc6fe4219 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -82,7 +82,7 @@ @interface FlutterPlatformPlugin () @implementation FlutterPlatformPlugin -- (instancetype)initWithEngine:(fml::WeakNSObject)engine { +- (instancetype)initWithEngine:(FlutterEngine*)engine { FML_DCHECK(engine) << "engine must be set"; self = [super init]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 38096e9cbf320..b6259e120cced 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -37,15 +37,12 @@ - (void)testSearchWebInvokedWithEscapedTerm { OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); [engine runWithEntrypoint:nil]; XCTestExpectation* invokeExpectation = [self expectationWithDescription:@"Web search launched with escaped search term"]; - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"SearchWeb.invoke" @@ -71,15 +68,12 @@ - (void)testSearchWebInvokedWithNonEscapedTerm { OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); [engine runWithEntrypoint:nil]; XCTestExpectation* invokeExpectation = [self expectationWithDescription:@"Web search launched with non escaped search term"]; - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"SearchWeb.invoke" @@ -103,8 +97,6 @@ - (void)testSearchWebInvokedWithNonEscapedTerm { - (void)testLookUpCallInitiated { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; [engine runWithEntrypoint:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTestExpectation* presentExpectation = [self expectationWithDescription:@"Look Up view controller presented"]; @@ -114,8 +106,7 @@ - (void)testLookUpCallInitiated { bundle:nil]; FlutterViewController* mockEngineViewController = OCMPartialMock(engineViewController); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"LookUp.invoke" @@ -134,8 +125,6 @@ - (void)testLookUpCallInitiated { - (void)testShareScreenInvoked { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; [engine runWithEntrypoint:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTestExpectation* presentExpectation = [self expectationWithDescription:@"Share view controller presented"]; @@ -149,8 +138,7 @@ - (void)testShareScreenInvoked { animated:YES completion:nil]); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"Share.invoke" @@ -169,8 +157,6 @@ - (void)testShareScreenInvoked { - (void)testShareScreenInvokedOnIPad { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; [engine runWithEntrypoint:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTestExpectation* presentExpectation = [self expectationWithDescription:@"Share view controller presented on iPad"]; @@ -187,8 +173,7 @@ - (void)testShareScreenInvokedOnIPad { id mockTraitCollection = OCMClassMock([UITraitCollection class]); OCMStub([mockTraitCollection userInterfaceIdiom]).andReturn(UIUserInterfaceIdiomPad); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"Share.invoke" @@ -207,10 +192,7 @@ - (void)testShareScreenInvokedOnIPad { - (void)testClipboardHasCorrectStrings { [UIPasteboard generalPasteboard].string = nil; FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; XCTestExpectation* setStringExpectation = [self expectationWithDescription:@"setString"]; FlutterResult resultSet = ^(id result) { @@ -246,10 +228,7 @@ - (void)testClipboardHasCorrectStrings { - (void)testClipboardSetDataToNullDoNotCrash { [UIPasteboard generalPasteboard].string = nil; FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; XCTestExpectation* setStringExpectation = [self expectationWithDescription:@"setData"]; FlutterResult resultSet = ^(id result) { @@ -280,10 +259,7 @@ - (void)testPopSystemNavigator { [[UINavigationController alloc] initWithRootViewController:flutterViewController]; UITabBarController* tabBarController = [[UITabBarController alloc] init]; tabBarController.viewControllers = @[ navigationController ]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; id navigationControllerMock = OCMPartialMock(navigationController); OCMStub([navigationControllerMock popViewControllerAnimated:YES]); @@ -303,12 +279,9 @@ - (void)testPopSystemNavigator { - (void)testWhetherDeviceHasLiveTextInputInvokeCorrectly { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTestExpectation* invokeExpectation = [self expectationWithDescription:@"isLiveTextInputAvailableInvoke"]; - FlutterPlatformPlugin* plugin = - [[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakNSObject()]; + FlutterPlatformPlugin* plugin = [[FlutterPlatformPlugin alloc] initWithEngine:engine]; FlutterPlatformPlugin* mockPlugin = OCMPartialMock(plugin); FlutterMethodCall* methodCall = [FlutterMethodCall methodCallWithMethodName:@"LiveText.isLiveTextInputAvailable" @@ -331,8 +304,6 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate { [engine runWithEntrypoint:nil]; FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTAssertFalse(flutterViewController.prefersStatusBarHidden); // Update to hidden. @@ -371,8 +342,6 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate { [engine runWithEntrypoint:nil]; FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTAssertFalse(flutterViewController.prefersStatusBarHidden); // Update to hidden. @@ -420,8 +389,6 @@ - (void)testStatusBarHiddenUpdate { [engine runWithEntrypoint:nil]; FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); // Update to hidden. FlutterPlatformPlugin* plugin = [engine platformPlugin]; @@ -471,8 +438,6 @@ - (void)testStatusBarStyle { [engine runWithEntrypoint:nil]; FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - std::unique_ptr> _weakFactory = - std::make_unique>(engine); XCTAssertFalse(flutterViewController.prefersStatusBarHidden); FlutterPlatformPlugin* plugin = [engine platformPlugin]; From d7af9ab7cea22a5d46d11b94f5922e0234ebe030 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 2 Oct 2024 17:17:07 -0700 Subject: [PATCH 02/31] Migrate _dartProject to property --- .../ios/framework/Source/FlutterEngine.mm | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 473a669f52dac..de034651fd460 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -99,6 +99,8 @@ @interface FlutterEngine () +@property(nonatomic, readonly) FlutterDartProject* dartProject; + // Maintains a dictionary of plugin names that have registered with the engine. Used by // FlutterEngineRegistrar to implement a FlutterPluginRegistrar. @property(nonatomic, readonly) NSMutableDictionary* pluginPublications; @@ -116,7 +118,6 @@ @interface FlutterEngine () _dartProject; std::shared_ptr _threadHost; std::unique_ptr _shell; NSString* _labelPrefix; @@ -192,20 +193,16 @@ - (instancetype)initWithName:(NSString*)labelPrefix _allowHeadlessExecution = allowHeadlessExecution; _labelPrefix = [labelPrefix copy]; - if (project == nil) { - _dartProject.reset([[FlutterDartProject alloc] init]); - } else { - _dartProject.reset(project); - } + _dartProject = project ?: [[FlutterDartProject alloc] init]; - _enableEmbedderAPI = _dartProject.get().settings.enable_embedder_api; + _enableEmbedderAPI = _dartProject.settings.enable_embedder_api; if (_enableEmbedderAPI) { NSLog(@"============== iOS: enable_embedder_api is on =============="); _embedderAPI.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&_embedderAPI); } - if (!EnableTracingIfNecessary([_dartProject.get() settings])) { + if (!EnableTracingIfNecessary(_dartProject.settings)) { NSLog( @"Cannot create a FlutterEngine instance in debug mode without Flutter tooling or " @"Xcode.\n\nTo launch in debug mode in iOS 14+, run flutter run from Flutter tools, run " @@ -737,9 +734,9 @@ - (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil entrypointArgs:(NSArray*)entrypointArgs { // Launch the Dart application with the inferred run configuration. - self.shell.RunEngine([_dartProject.get() runConfigurationForEntrypoint:entrypoint - libraryOrNil:libraryOrNil - entrypointArgs:entrypointArgs]); + self.shell.RunEngine([self.dartProject runConfigurationForEntrypoint:entrypoint + libraryOrNil:libraryOrNil + entrypointArgs:entrypointArgs]); } - (void)setUpShell:(std::unique_ptr)shell @@ -828,7 +825,7 @@ - (BOOL)createShell:(NSString*)entrypoint self.initialRoute = initialRoute; - auto settings = [_dartProject.get() settings]; + auto settings = [self.dartProject settings]; if (initialRoute != nil) { self.initialRoute = initialRoute; } else if (settings.route.empty() == false) { @@ -837,7 +834,7 @@ - (BOOL)createShell:(NSString*)entrypoint FlutterView.forceSoftwareRendering = settings.enable_software_rendering; - auto platformData = [_dartProject.get() defaultPlatformData]; + auto platformData = [self.dartProject defaultPlatformData]; SetEntryPoint(&settings, entrypoint, libraryURI); @@ -1430,12 +1427,12 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint entrypointArgs:(/*nullable*/ NSArray*)entrypointArgs { NSAssert(_shell, @"Spawning from an engine without a shell (possibly not run)."); FlutterEngine* result = [[FlutterEngine alloc] initWithName:_labelPrefix - project:_dartProject.get() + project:self.dartProject allowHeadlessExecution:_allowHeadlessExecution]; flutter::RunConfiguration configuration = - [_dartProject.get() runConfigurationForEntrypoint:entrypoint - libraryOrNil:libraryURI - entrypointArgs:entrypointArgs]; + [self.dartProject runConfigurationForEntrypoint:entrypoint + libraryOrNil:libraryURI + entrypointArgs:entrypointArgs]; fml::WeakPtr platform_view = _shell->GetPlatformView(); FML_DCHECK(platform_view); @@ -1480,7 +1477,7 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint } - (FlutterDartProject*)project { - return _dartProject.get(); + return self.dartProject; } - (BOOL)isUsingImpeller { From 9c8140c7e038f0cc05cb71ec3d3cb305f858db83 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 2 Oct 2024 17:20:05 -0700 Subject: [PATCH 03/31] Migrate _labelPrefix to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index de034651fd460..308b31fc14bba 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -100,6 +100,7 @@ @interface FlutterEngine () @property(nonatomic, readonly) FlutterDartProject* dartProject; +@property(nonatomic, readonly, copy) NSString* labelPrefix; // Maintains a dictionary of plugin names that have registered with the engine. Used by // FlutterEngineRegistrar to implement a FlutterPluginRegistrar. @@ -120,7 +121,6 @@ @interface FlutterEngine () _threadHost; std::unique_ptr _shell; - NSString* _labelPrefix; fml::WeakNSObject _viewController; fml::scoped_nsobject _publisher; @@ -191,8 +191,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix _restorationEnabled = restorationEnabled; _allowHeadlessExecution = allowHeadlessExecution; - _labelPrefix = [labelPrefix copy]; - + _labelPrefix = labelPrefix; _dartProject = project ?: [[FlutterDartProject alloc] init]; _enableEmbedderAPI = _dartProject.settings.enable_embedder_api; @@ -838,7 +837,7 @@ - (BOOL)createShell:(NSString*)entrypoint SetEntryPoint(&settings, entrypoint, libraryURI); - NSString* threadLabel = [FlutterEngine generateThreadLabel:_labelPrefix]; + NSString* threadLabel = [FlutterEngine generateThreadLabel:self.labelPrefix]; _threadHost = std::make_shared(); *_threadHost = MakeThreadHost(threadLabel, settings); @@ -1426,7 +1425,7 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint initialRoute:(/*nullable*/ NSString*)initialRoute entrypointArgs:(/*nullable*/ NSArray*)entrypointArgs { NSAssert(_shell, @"Spawning from an engine without a shell (possibly not run)."); - FlutterEngine* result = [[FlutterEngine alloc] initWithName:_labelPrefix + FlutterEngine* result = [[FlutterEngine alloc] initWithName:self.labelPrefix project:self.dartProject allowHeadlessExecution:_allowHeadlessExecution]; flutter::RunConfiguration configuration = From bfbd8ae4d8995d4faf696e5ed6716f788aefde75 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 13:40:24 -0700 Subject: [PATCH 04/31] Migrate _platformPlugin to a property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 308b31fc14bba..812b39da15078 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -111,6 +111,10 @@ @interface FlutterEngine () flutterViewControllerWillDeallocObserver; +#pragma mark - Channel properties + +@property(nonatomic, strong) FlutterPlatformPlugin* platformPlugin; + #pragma mark - Embedder API properties @property(nonatomic, assign) BOOL enableEmbedderAPI; @@ -131,7 +135,6 @@ @implementation FlutterEngine { std::shared_ptr _profiler; // Channels - fml::scoped_nsobject _platformPlugin; fml::scoped_nsobject _textInputPlugin; fml::scoped_nsobject _undoManagerPlugin; fml::scoped_nsobject _spellCheckPlugin; @@ -466,9 +469,6 @@ - (FlutterViewController*)viewController { return _viewController.get(); } -- (FlutterPlatformPlugin*)platformPlugin { - return _platformPlugin.get(); -} - (std::shared_ptr&)platformViewsController { return _platformViewsController; } @@ -652,7 +652,7 @@ - (void)setUpChannels { [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; _undoManagerPlugin.reset(undoManagerPlugin); - _platformPlugin.reset([[FlutterPlatformPlugin alloc] initWithEngine:self]); + self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; _restorationPlugin.reset([[FlutterRestorationPlugin alloc] initWithChannel:_restorationChannel.get() @@ -692,7 +692,7 @@ - (void)setUpChannels { - (void)maybeSetupPlatformViewChannels { if (_shell && self.shell.IsSetup()) { - FlutterPlatformPlugin* platformPlugin = _platformPlugin.get(); + FlutterPlatformPlugin* platformPlugin = self.platformPlugin; [_platformChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [platformPlugin handleMethodCall:call result:result]; }]; From 6e39593773375356122d53e334cc753cc61b97ba Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 09:49:16 -0700 Subject: [PATCH 05/31] Migrate _textInputPlugin to property --- .../ios/framework/Source/FlutterEngine.mm | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 812b39da15078..46b001e2ba529 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -114,6 +114,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _textInputPlugin; fml::scoped_nsobject _undoManagerPlugin; fml::scoped_nsobject _spellCheckPlugin; fml::scoped_nsobject _restorationPlugin; @@ -407,7 +407,7 @@ - (void)setViewController:(FlutterViewController*)viewController { self.iosPlatformView->SetOwnerViewController(_viewController); [self maybeSetupPlatformViewChannels]; [self updateDisplays]; - _textInputPlugin.get().viewController = viewController; + self.textInputPlugin.viewController = viewController; if (viewController) { __weak __block FlutterEngine* blockSelf = self; @@ -440,7 +440,7 @@ - (void)setFlutterViewControllerWillDeallocObserver:(id)observer { - (void)notifyViewControllerDeallocated { [[self lifecycleChannel] sendMessage:@"AppLifecycleState.detached"]; - _textInputPlugin.get().viewController = nil; + self.textInputPlugin.viewController = nil; if (!_allowHeadlessExecution) { [self destroyContext]; } else if (_shell) { @@ -449,7 +449,7 @@ - (void)notifyViewControllerDeallocated { platform_view->SetOwnerViewController({}); } } - [_textInputPlugin.get() resetViewResponder]; + [self.textInputPlugin resetViewResponder]; _viewController.reset(); } @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterTextInputPlugin*)textInputPlugin { - return _textInputPlugin.get(); -} - (FlutterUndoManagerPlugin*)undoManagerPlugin { return _undoManagerPlugin.get(); } @@ -643,10 +640,9 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMessageCodec sharedInstance]]); - FlutterTextInputPlugin* textInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:self]; - _textInputPlugin.reset(textInputPlugin); - textInputPlugin.indirectScribbleDelegate = self; - [textInputPlugin setUpIndirectScribbleInteraction:self.viewController]; + self.textInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:self]; + self.textInputPlugin.indirectScribbleDelegate = self; + [self.textInputPlugin setUpIndirectScribbleInteraction:self.viewController]; FlutterUndoManagerPlugin* undoManagerPlugin = [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; @@ -705,7 +701,7 @@ - (void)maybeSetupPlatformViewChannels { } }]; - FlutterTextInputPlugin* textInputPlugin = _textInputPlugin.get(); + FlutterTextInputPlugin* textInputPlugin = self.textInputPlugin; [_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [textInputPlugin handleMethodCall:call result:result]; }]; From 708ef4cff75b17a06e71fa4325a6f1615b37d86b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 14:36:13 -0700 Subject: [PATCH 06/31] Migrate _undoManagerPlugin to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 46b001e2ba529..5492df73d36c0 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -115,6 +115,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _undoManagerPlugin; fml::scoped_nsobject _spellCheckPlugin; fml::scoped_nsobject _restorationPlugin; fml::scoped_nsobject _localizationChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterUndoManagerPlugin*)undoManagerPlugin { - return _undoManagerPlugin.get(); -} - (FlutterRestorationPlugin*)restorationPlugin { return _restorationPlugin.get(); } @@ -644,10 +641,7 @@ - (void)setUpChannels { self.textInputPlugin.indirectScribbleDelegate = self; [self.textInputPlugin setUpIndirectScribbleInteraction:self.viewController]; - FlutterUndoManagerPlugin* undoManagerPlugin = - [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; - _undoManagerPlugin.reset(undoManagerPlugin); - + self.undoManagerPlugin = [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; _restorationPlugin.reset([[FlutterRestorationPlugin alloc] @@ -706,7 +700,7 @@ - (void)maybeSetupPlatformViewChannels { [textInputPlugin handleMethodCall:call result:result]; }]; - FlutterUndoManagerPlugin* undoManagerPlugin = _undoManagerPlugin.get(); + FlutterUndoManagerPlugin* undoManagerPlugin = self.undoManagerPlugin; [_undoManagerChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [undoManagerPlugin handleMethodCall:call result:result]; From 9ede54199756cdd84e2cfe14744a97cea323448e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 14:36:41 -0700 Subject: [PATCH 07/31] Add TODO to use weakSelf --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 5492df73d36c0..e4e602ecfebd4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -682,6 +682,7 @@ - (void)setUpChannels { - (void)maybeSetupPlatformViewChannels { if (_shell && self.shell.IsSetup()) { + // TODO(cbracken): Use weakSelf for these. FlutterPlatformPlugin* platformPlugin = self.platformPlugin; [_platformChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [platformPlugin handleMethodCall:call result:result]; From 4d804786f3eb3072a6354fbeb1ed05e8c1ea67ca Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 14:37:17 -0700 Subject: [PATCH 08/31] Migrate _spellCheckPlugin to property --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index e4e602ecfebd4..9c89cbbc7035b 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -116,6 +116,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _spellCheckPlugin; fml::scoped_nsobject _restorationPlugin; fml::scoped_nsobject _localizationChannel; fml::scoped_nsobject _navigationChannel; @@ -647,7 +647,7 @@ - (void)setUpChannels { _restorationPlugin.reset([[FlutterRestorationPlugin alloc] initWithChannel:_restorationChannel.get() restorationEnabled:_restorationEnabled]); - _spellCheckPlugin.reset([[FlutterSpellCheckPlugin alloc] init]); + self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; _screenshotChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/screenshot" @@ -707,7 +707,7 @@ - (void)maybeSetupPlatformViewChannels { [undoManagerPlugin handleMethodCall:call result:result]; }]; - FlutterSpellCheckPlugin* spellCheckPlugin = _spellCheckPlugin.get(); + FlutterSpellCheckPlugin* spellCheckPlugin = self.spellCheckPlugin; [_spellCheckChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [spellCheckPlugin handleMethodCall:call result:result]; From 8c67e32cd25b224d8636ec8c16fa35fd4203504b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 14:44:03 -0700 Subject: [PATCH 09/31] Migrate _restorationPlugin to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 9c89cbbc7035b..9cea91cd6b22d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -117,6 +117,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _restorationPlugin; fml::scoped_nsobject _localizationChannel; fml::scoped_nsobject _navigationChannel; fml::scoped_nsobject _restorationChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterRestorationPlugin*)restorationPlugin { - return _restorationPlugin.get(); -} - (FlutterMethodChannel*)localizationChannel { return _localizationChannel.get(); } @@ -644,9 +641,9 @@ - (void)setUpChannels { self.undoManagerPlugin = [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; - _restorationPlugin.reset([[FlutterRestorationPlugin alloc] - initWithChannel:_restorationChannel.get() - restorationEnabled:_restorationEnabled]); + self.restorationPlugin = + [[FlutterRestorationPlugin alloc] initWithChannel:_restorationChannel.get() + restorationEnabled:_restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; _screenshotChannel.reset([[FlutterMethodChannel alloc] From 582b8462761099596424fef47c598a79a27e8d00 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:31:57 -0700 Subject: [PATCH 10/31] Migrate _localizationChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 9cea91cd6b22d..372e719b52adf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -118,6 +118,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _localizationChannel; fml::scoped_nsobject _navigationChannel; fml::scoped_nsobject _restorationChannel; fml::scoped_nsobject _platformChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)localizationChannel { - return _localizationChannel.get(); -} - (FlutterMethodChannel*)navigationChannel { return _navigationChannel.get(); } @@ -518,7 +515,7 @@ - (NSURL*)vmServiceUrl { } - (void)resetChannels { - _localizationChannel.reset(); + self.localizationChannel = nil; _navigationChannel.reset(); _restorationChannel.reset(); _platformChannel.reset(); @@ -563,10 +560,10 @@ - (void)setUpChannels { } }]; - _localizationChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/localization" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + self.localizationChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/localization" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; _navigationChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/navigation" From 6d44d059d74beb37d233daca02ac506583b801db Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:33:44 -0700 Subject: [PATCH 11/31] Migrate _navigationChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 372e719b52adf..34f73355828a8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -119,6 +119,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _navigationChannel; fml::scoped_nsobject _restorationChannel; fml::scoped_nsobject _platformChannel; fml::scoped_nsobject _platformViewsChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)navigationChannel { - return _navigationChannel.get(); -} - (FlutterMethodChannel*)restorationChannel { return _restorationChannel.get(); } @@ -516,7 +513,7 @@ - (NSURL*)vmServiceUrl { - (void)resetChannels { self.localizationChannel = nil; - _navigationChannel.reset(); + self.navigationChannel = nil; _restorationChannel.reset(); _platformChannel.reset(); _platformViewsChannel.reset(); @@ -565,14 +562,14 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - _navigationChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/navigation" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + self.navigationChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/navigation" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; if ([_initialRoute length] > 0) { // Flutter isn't ready to receive this method call yet but the channel buffer will cache this. - [_navigationChannel invokeMethod:@"setInitialRoute" arguments:_initialRoute]; + [self.navigationChannel invokeMethod:@"setInitialRoute" arguments:_initialRoute]; _initialRoute = nil; } From cde979275a5fd3a4897f16ba286a4b5a4192f372 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:47:08 -0700 Subject: [PATCH 12/31] Migrate _restorationChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 34f73355828a8..7ea5abf486bfa 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -120,6 +120,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _restorationChannel; fml::scoped_nsobject _platformChannel; fml::scoped_nsobject _platformViewsChannel; fml::scoped_nsobject _textInputChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)restorationChannel { - return _restorationChannel.get(); -} - (FlutterMethodChannel*)platformChannel { return _platformChannel.get(); } @@ -514,7 +511,7 @@ - (NSURL*)vmServiceUrl { - (void)resetChannels { self.localizationChannel = nil; self.navigationChannel = nil; - _restorationChannel.reset(); + self.restorationChannel = nil; _platformChannel.reset(); _platformViewsChannel.reset(); _textInputChannel.reset(); @@ -573,10 +570,10 @@ - (void)setUpChannels { _initialRoute = nil; } - _restorationChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/restoration" - binaryMessenger:self.binaryMessenger - codec:[FlutterStandardMethodCodec sharedInstance]]); + self.restorationChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/restoration" + binaryMessenger:self.binaryMessenger + codec:[FlutterStandardMethodCodec sharedInstance]]; _platformChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/platform" @@ -636,7 +633,7 @@ - (void)setUpChannels { self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; self.restorationPlugin = - [[FlutterRestorationPlugin alloc] initWithChannel:_restorationChannel.get() + [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel restorationEnabled:_restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; From 59a5666eb500ae8ffafe3bef9f4d4e8cd872ea0b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:53:06 -0700 Subject: [PATCH 13/31] Migrate _platformChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 7ea5abf486bfa..9d97d301d3710 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -121,6 +121,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _platformChannel; fml::scoped_nsobject _platformViewsChannel; fml::scoped_nsobject _textInputChannel; fml::scoped_nsobject _undoManagerChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)platformChannel { - return _platformChannel.get(); -} - (FlutterMethodChannel*)textInputChannel { return _textInputChannel.get(); } @@ -512,7 +509,7 @@ - (void)resetChannels { self.localizationChannel = nil; self.navigationChannel = nil; self.restorationChannel = nil; - _platformChannel.reset(); + self.platformChannel = nil; _platformViewsChannel.reset(); _textInputChannel.reset(); _undoManagerChannel.reset(); @@ -575,10 +572,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterStandardMethodCodec sharedInstance]]; - _platformChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/platform" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + self.platformChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/platform" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; _platformViewsChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/platform_views" @@ -632,9 +629,8 @@ - (void)setUpChannels { self.undoManagerPlugin = [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; - self.restorationPlugin = - [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel - restorationEnabled:_restorationEnabled]; + self.restorationPlugin = [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel + restorationEnabled:_restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; _screenshotChannel.reset([[FlutterMethodChannel alloc] @@ -672,7 +668,7 @@ - (void)maybeSetupPlatformViewChannels { if (_shell && self.shell.IsSetup()) { // TODO(cbracken): Use weakSelf for these. FlutterPlatformPlugin* platformPlugin = self.platformPlugin; - [_platformChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + [self.platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [platformPlugin handleMethodCall:call result:result]; }]; @@ -1051,8 +1047,8 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView - (void)flutterTextInputView:(FlutterTextInputView*)textInputView willDismissEditMenuWithTextInputClient:(int)client { - [_platformChannel.get() invokeMethod:@"ContextMenu.onDismissSystemContextMenu" - arguments:@[ @(client) ]]; + [self.platformChannel invokeMethod:@"ContextMenu.onDismissSystemContextMenu" + arguments:@[ @(client) ]]; } #pragma mark - FlutterViewEngineDelegate From 4fb023b60335df232537443362e72323c9001ba0 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:55:49 -0700 Subject: [PATCH 14/31] Migrate _platformViewChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 9d97d301d3710..f5cce3ceb7245 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -122,6 +122,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _platformViewsChannel; fml::scoped_nsobject _textInputChannel; fml::scoped_nsobject _undoManagerChannel; fml::scoped_nsobject _scribbleChannel; @@ -510,7 +510,7 @@ - (void)resetChannels { self.navigationChannel = nil; self.restorationChannel = nil; self.platformChannel = nil; - _platformViewsChannel.reset(); + self.platformViewsChannel = nil; _textInputChannel.reset(); _undoManagerChannel.reset(); _scribbleChannel.reset(); @@ -577,10 +577,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - _platformViewsChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/platform_views" - binaryMessenger:self.binaryMessenger - codec:[FlutterStandardMethodCodec sharedInstance]]); + self.platformViewsChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/platform_views" + binaryMessenger:self.binaryMessenger + codec:[FlutterStandardMethodCodec sharedInstance]]; _textInputChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/textinput" @@ -673,7 +673,7 @@ - (void)maybeSetupPlatformViewChannels { }]; __weak FlutterEngine* weakSelf = self; - [_platformViewsChannel.get() + [self.platformViewsChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { if (weakSelf) { weakSelf.platformViewsController->OnMethodCall(call, result); @@ -1152,7 +1152,7 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView return; } - [_platformViewsChannel.get() invokeMethod:@"viewFocused" arguments:@(platform_view_id)]; + [self.platformViewsChannel invokeMethod:@"viewFocused" arguments:@(platform_view_id)]; }); } From 0cfd5dd06e8f40f27b9fe01214790b4c14142fa3 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 15:58:53 -0700 Subject: [PATCH 15/31] Migrate _textInputChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index f5cce3ceb7245..499f2843140e3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -123,6 +123,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _textInputChannel; fml::scoped_nsobject _undoManagerChannel; fml::scoped_nsobject _scribbleChannel; fml::scoped_nsobject _spellCheckChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)textInputChannel { - return _textInputChannel.get(); -} - (FlutterMethodChannel*)undoManagerChannel { return _undoManagerChannel.get(); } @@ -511,7 +508,7 @@ - (void)resetChannels { self.restorationChannel = nil; self.platformChannel = nil; self.platformViewsChannel = nil; - _textInputChannel.reset(); + self.textInputChannel = nil; _undoManagerChannel.reset(); _scribbleChannel.reset(); _lifecycleChannel.reset(); @@ -582,10 +579,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterStandardMethodCodec sharedInstance]]; - _textInputChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/textinput" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + self.textInputChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/textinput" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; _undoManagerChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/undomanager" @@ -681,7 +678,7 @@ - (void)maybeSetupPlatformViewChannels { }]; FlutterTextInputPlugin* textInputPlugin = self.textInputPlugin; - [_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + [self.textInputChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [textInputPlugin handleMethodCall:call result:result]; }]; @@ -951,23 +948,23 @@ - (void)notifyLowMemory { - (void)flutterTextInputView:(FlutterTextInputView*)textInputView updateEditingClient:(int)client withState:(NSDictionary*)state { - [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingState" - arguments:@[ @(client), state ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.updateEditingState" + arguments:@[ @(client), state ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView updateEditingClient:(int)client withState:(NSDictionary*)state withTag:(NSString*)tag { - [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingStateWithTag" - arguments:@[ @(client), @{tag : state} ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithTag" + arguments:@[ @(client), @{tag : state} ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView updateEditingClient:(int)client withDelta:(NSDictionary*)delta { - [_textInputChannel.get() invokeMethod:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(client), delta ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(client), delta ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -986,8 +983,8 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView stateString = @"FloatingCursorDragState.end"; break; } - [_textInputChannel.get() invokeMethod:@"TextInputClient.updateFloatingCursor" - arguments:@[ @(client), stateString, position ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.updateFloatingCursor" + arguments:@[ @(client), stateString, position ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -1033,16 +1030,16 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView actionString = @"TextInputAction.newline"; break; } - [_textInputChannel.get() invokeMethod:@"TextInputClient.performAction" - arguments:@[ @(client), actionString ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.performAction" + arguments:@[ @(client), actionString ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView showAutocorrectionPromptRectForStart:(NSUInteger)start end:(NSUInteger)end withClient:(int)client { - [_textInputChannel.get() invokeMethod:@"TextInputClient.showAutocorrectionPromptRect" - arguments:@[ @(client), @(start), @(end) ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.showAutocorrectionPromptRect" + arguments:@[ @(client), @(start), @(end) ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -1057,7 +1054,7 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView showToolbar:(i // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]]; } - (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin @@ -1067,7 +1064,7 @@ - (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() + [self.textInputChannel invokeMethod:@"TextInputClient.focusElement" arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ] result:callback]; @@ -1079,7 +1076,7 @@ - (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() + [self.textInputChannel invokeMethod:@"TextInputClient.requestElementsInRect" arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ] result:callback]; @@ -1089,15 +1086,14 @@ - (void)flutterTextInputViewScribbleInteractionBegan:(FlutterTextInputView*)text // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil]; + [self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil]; } - (void)flutterTextInputViewScribbleInteractionFinished:(FlutterTextInputView*)textInputView { // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionFinished" - arguments:nil]; + [self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionFinished" arguments:nil]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -1106,8 +1102,8 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() invokeMethod:@"TextInputClient.insertTextPlaceholder" - arguments:@[ @(client), @(size.width), @(size.height) ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.insertTextPlaceholder" + arguments:@[ @(client), @(size.width), @(size.height) ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -1115,8 +1111,8 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView // TODO(justinmc): Switch from the TextInputClient to Scribble channel when // the framework has finished transitioning to the Scribble channel. // https://github.com/flutter/flutter/pull/115296 - [_textInputChannel.get() invokeMethod:@"TextInputClient.removeTextPlaceholder" - arguments:@[ @(client) ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.removeTextPlaceholder" + arguments:@[ @(client) ]]; } - (void)flutterTextInputView:(FlutterTextInputView*)textInputView @@ -1124,8 +1120,8 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView // When flutter text input view resign first responder, send a message to // framework to ensure the focus state is correct. This is useful when close // keyboard from platform side. - [_textInputChannel.get() invokeMethod:@"TextInputClient.onConnectionClosed" - arguments:@[ @(client) ]]; + [self.textInputChannel invokeMethod:@"TextInputClient.onConnectionClosed" + arguments:@[ @(client) ]]; // Platform view's first responder detection logic: // From 30be2282a33c7cb985af76af6712ff94b2acfc88 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:02:14 -0700 Subject: [PATCH 16/31] Migrate _undoManagerChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 499f2843140e3..558178a09b6c4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -124,6 +124,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _undoManagerChannel; fml::scoped_nsobject _scribbleChannel; fml::scoped_nsobject _spellCheckChannel; fml::scoped_nsobject _lifecycleChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)undoManagerChannel { - return _undoManagerChannel.get(); -} - (FlutterMethodChannel*)scribbleChannel { return _scribbleChannel.get(); } @@ -509,7 +506,7 @@ - (void)resetChannels { self.platformChannel = nil; self.platformViewsChannel = nil; self.textInputChannel = nil; - _undoManagerChannel.reset(); + self.undoManagerChannel = nil; _scribbleChannel.reset(); _lifecycleChannel.reset(); _systemChannel.reset(); @@ -584,10 +581,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - _undoManagerChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/undomanager" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + self.undoManagerChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/undomanager" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; _scribbleChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/scribble" @@ -683,10 +680,9 @@ - (void)maybeSetupPlatformViewChannels { }]; FlutterUndoManagerPlugin* undoManagerPlugin = self.undoManagerPlugin; - [_undoManagerChannel.get() - setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [undoManagerPlugin handleMethodCall:call result:result]; - }]; + [self.undoManagerChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + [undoManagerPlugin handleMethodCall:call result:result]; + }]; FlutterSpellCheckPlugin* spellCheckPlugin = self.spellCheckPlugin; [_spellCheckChannel.get() @@ -1156,7 +1152,7 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView - (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction { NSString* action = (direction == FlutterUndoRedoDirectionUndo) ? @"undo" : @"redo"; - [_undoManagerChannel.get() invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]]; + [self.undoManagerChannel invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]]; } - (UIView*)activeTextInputView { From c87e1fcb92a2a5534f49fefb6f9000f6f17bd93a Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:04:13 -0700 Subject: [PATCH 17/31] Migrate _scribbleChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 558178a09b6c4..d00742fedb65f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -125,6 +125,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _scribbleChannel; fml::scoped_nsobject _spellCheckChannel; fml::scoped_nsobject _lifecycleChannel; fml::scoped_nsobject _systemChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)scribbleChannel { - return _scribbleChannel.get(); -} - (FlutterMethodChannel*)spellCheckChannel { return _spellCheckChannel.get(); } @@ -507,7 +504,7 @@ - (void)resetChannels { self.platformViewsChannel = nil; self.textInputChannel = nil; self.undoManagerChannel = nil; - _scribbleChannel.reset(); + self.scribbleChannel = nil; _lifecycleChannel.reset(); _systemChannel.reset(); _settingsChannel.reset(); @@ -586,10 +583,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - _scribbleChannel.reset([[FlutterMethodChannel alloc] + self.scribbleChannel = [[FlutterMethodChannel alloc] initWithName:@"flutter/scribble" binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]); + codec:[FlutterJSONMethodCodec sharedInstance]]; _spellCheckChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/spellcheck" From 4beaff5875579e51fae23ccafbce12ca2cfeb9f9 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:05:36 -0700 Subject: [PATCH 18/31] Migrate _spellCheckChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index d00742fedb65f..35b192c4c4592 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -126,6 +126,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _spellCheckChannel; fml::scoped_nsobject _lifecycleChannel; fml::scoped_nsobject _systemChannel; fml::scoped_nsobject _settingsChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterMethodChannel*)spellCheckChannel { - return _spellCheckChannel.get(); -} - (FlutterBasicMessageChannel*)lifecycleChannel { return _lifecycleChannel.get(); } @@ -509,7 +506,7 @@ - (void)resetChannels { _systemChannel.reset(); _settingsChannel.reset(); _keyEventChannel.reset(); - _spellCheckChannel.reset(); + self.spellCheckChannel = nil; } - (void)startProfiler { @@ -583,15 +580,15 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - self.scribbleChannel = [[FlutterMethodChannel alloc] - initWithName:@"flutter/scribble" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMethodCodec sharedInstance]]; + self.scribbleChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/scribble" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMethodCodec sharedInstance]]; - _spellCheckChannel.reset([[FlutterMethodChannel alloc] + self.spellCheckChannel = [[FlutterMethodChannel alloc] initWithName:@"flutter/spellcheck" binaryMessenger:self.binaryMessenger - codec:[FlutterStandardMethodCodec sharedInstance]]); + codec:[FlutterStandardMethodCodec sharedInstance]]; _lifecycleChannel.reset([[FlutterBasicMessageChannel alloc] initWithName:@"flutter/lifecycle" @@ -682,8 +679,7 @@ - (void)maybeSetupPlatformViewChannels { }]; FlutterSpellCheckPlugin* spellCheckPlugin = self.spellCheckPlugin; - [_spellCheckChannel.get() - setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + [self.spellCheckChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [spellCheckPlugin handleMethodCall:call result:result]; }]; } From 3ff898c41df94781d170384f5e4d17a42133b04e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:08:14 -0700 Subject: [PATCH 19/31] Migrate _lifecycleChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 35b192c4c4592..f129a987b995a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -127,6 +127,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _lifecycleChannel; fml::scoped_nsobject _systemChannel; fml::scoped_nsobject _settingsChannel; fml::scoped_nsobject _keyEventChannel; @@ -439,7 +439,7 @@ - (void)setFlutterViewControllerWillDeallocObserver:(id)observer { } - (void)notifyViewControllerDeallocated { - [[self lifecycleChannel] sendMessage:@"AppLifecycleState.detached"]; + [self.lifecycleChannel sendMessage:@"AppLifecycleState.detached"]; self.textInputPlugin.viewController = nil; if (!_allowHeadlessExecution) { [self destroyContext]; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterBasicMessageChannel*)lifecycleChannel { - return _lifecycleChannel.get(); -} - (FlutterBasicMessageChannel*)systemChannel { return _systemChannel.get(); } @@ -502,7 +499,7 @@ - (void)resetChannels { self.textInputChannel = nil; self.undoManagerChannel = nil; self.scribbleChannel = nil; - _lifecycleChannel.reset(); + self.lifecycleChannel = nil; _systemChannel.reset(); _settingsChannel.reset(); _keyEventChannel.reset(); @@ -585,15 +582,15 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMethodCodec sharedInstance]]; - self.spellCheckChannel = [[FlutterMethodChannel alloc] - initWithName:@"flutter/spellcheck" - binaryMessenger:self.binaryMessenger - codec:[FlutterStandardMethodCodec sharedInstance]]; + self.spellCheckChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/spellcheck" + binaryMessenger:self.binaryMessenger + codec:[FlutterStandardMethodCodec sharedInstance]]; - _lifecycleChannel.reset([[FlutterBasicMessageChannel alloc] - initWithName:@"flutter/lifecycle" - binaryMessenger:self.binaryMessenger - codec:[FlutterStringCodec sharedInstance]]); + self.lifecycleChannel = + [[FlutterBasicMessageChannel alloc] initWithName:@"flutter/lifecycle" + binaryMessenger:self.binaryMessenger + codec:[FlutterStringCodec sharedInstance]]; _systemChannel.reset([[FlutterBasicMessageChannel alloc] initWithName:@"flutter/system" @@ -680,8 +677,8 @@ - (void)maybeSetupPlatformViewChannels { FlutterSpellCheckPlugin* spellCheckPlugin = self.spellCheckPlugin; [self.spellCheckChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [spellCheckPlugin handleMethodCall:call result:result]; - }]; + [spellCheckPlugin handleMethodCall:call result:result]; + }]; } } From 9cb6ca2ab76cd643d51eb98602ea4238c1b8b774 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:09:51 -0700 Subject: [PATCH 20/31] Migrate _systemChannel to property --- .../ios/framework/Source/FlutterEngine.mm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index f129a987b995a..c1a7c55e74968 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -128,6 +128,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _systemChannel; fml::scoped_nsobject _settingsChannel; fml::scoped_nsobject _keyEventChannel; fml::scoped_nsobject _screenshotChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterBasicMessageChannel*)systemChannel { - return _systemChannel.get(); -} - (FlutterBasicMessageChannel*)settingsChannel { return _settingsChannel.get(); } @@ -500,7 +497,7 @@ - (void)resetChannels { self.undoManagerChannel = nil; self.scribbleChannel = nil; self.lifecycleChannel = nil; - _systemChannel.reset(); + self.systemChannel = nil; _settingsChannel.reset(); _keyEventChannel.reset(); self.spellCheckChannel = nil; @@ -592,10 +589,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterStringCodec sharedInstance]]; - _systemChannel.reset([[FlutterBasicMessageChannel alloc] - initWithName:@"flutter/system" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMessageCodec sharedInstance]]); + self.systemChannel = + [[FlutterBasicMessageChannel alloc] initWithName:@"flutter/system" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMessageCodec sharedInstance]]; _settingsChannel.reset([[FlutterBasicMessageChannel alloc] initWithName:@"flutter/settings" @@ -926,7 +923,7 @@ - (void)notifyLowMemory { if (_shell) { _shell->NotifyLowMemoryWarning(); } - [_systemChannel sendMessage:@{@"type" : @"memoryPressure"}]; + [self.systemChannel sendMessage:@{@"type" : @"memoryPressure"}]; } #pragma mark - Text input delegate From a25f67d0813bebb1c49ddd0f7e07d85890c9985b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:10:48 -0700 Subject: [PATCH 21/31] Migrate _settingsChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index c1a7c55e74968..98940c627d988 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -129,6 +129,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _settingsChannel; fml::scoped_nsobject _keyEventChannel; fml::scoped_nsobject _screenshotChannel; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterBasicMessageChannel*)settingsChannel { - return _settingsChannel.get(); -} - (FlutterBasicMessageChannel*)keyEventChannel { return _keyEventChannel.get(); } @@ -498,7 +495,7 @@ - (void)resetChannels { self.scribbleChannel = nil; self.lifecycleChannel = nil; self.systemChannel = nil; - _settingsChannel.reset(); + self.settingsChannel = nil; _keyEventChannel.reset(); self.spellCheckChannel = nil; } @@ -594,10 +591,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMessageCodec sharedInstance]]; - _settingsChannel.reset([[FlutterBasicMessageChannel alloc] - initWithName:@"flutter/settings" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMessageCodec sharedInstance]]); + self.settingsChannel = + [[FlutterBasicMessageChannel alloc] initWithName:@"flutter/settings" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMessageCodec sharedInstance]]; _keyEventChannel.reset([[FlutterBasicMessageChannel alloc] initWithName:@"flutter/keyevent" From 3bbdc73fd781644bfacfae965b2f1c3acf1dc8bb Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:11:41 -0700 Subject: [PATCH 22/31] Migrate _keyEventChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 98940c627d988..0d20d9f4279fa 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -130,6 +130,7 @@ @interface FlutterEngine () _profiler; // Channels - fml::scoped_nsobject _keyEventChannel; fml::scoped_nsobject _screenshotChannel; int64_t _nextTextureId; @@ -472,9 +472,6 @@ - (FlutterViewController*)viewController { - (std::shared_ptr&)platformViewsController { return _platformViewsController; } -- (FlutterBasicMessageChannel*)keyEventChannel { - return _keyEventChannel.get(); -} - (NSURL*)observatoryUrl { return [_publisher.get() url]; @@ -496,7 +493,7 @@ - (void)resetChannels { self.lifecycleChannel = nil; self.systemChannel = nil; self.settingsChannel = nil; - _keyEventChannel.reset(); + self.keyEventChannel = nil; self.spellCheckChannel = nil; } @@ -596,10 +593,10 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterJSONMessageCodec sharedInstance]]; - _keyEventChannel.reset([[FlutterBasicMessageChannel alloc] - initWithName:@"flutter/keyevent" - binaryMessenger:self.binaryMessenger - codec:[FlutterJSONMessageCodec sharedInstance]]); + self.keyEventChannel = + [[FlutterBasicMessageChannel alloc] initWithName:@"flutter/keyevent" + binaryMessenger:self.binaryMessenger + codec:[FlutterJSONMessageCodec sharedInstance]]; self.textInputPlugin = [[FlutterTextInputPlugin alloc] initWithDelegate:self]; self.textInputPlugin.indirectScribbleDelegate = self; From 67e50cc91e1d299943b5fd7c4164627e1d4dfde2 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:13:57 -0700 Subject: [PATCH 23/31] Migrate _screenshotChannel to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 0d20d9f4279fa..c900afdd60b02 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -131,6 +131,7 @@ @interface FlutterEngine () _profiler_metrics; std::shared_ptr _profiler; - // Channels - fml::scoped_nsobject _screenshotChannel; - int64_t _nextTextureId; BOOL _allowHeadlessExecution; @@ -609,12 +607,12 @@ - (void)setUpChannels { restorationEnabled:_restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; - _screenshotChannel.reset([[FlutterMethodChannel alloc] - initWithName:@"flutter/screenshot" - binaryMessenger:self.binaryMessenger - codec:[FlutterStandardMethodCodec sharedInstance]]); + self.screenshotChannel = + [[FlutterMethodChannel alloc] initWithName:@"flutter/screenshot" + binaryMessenger:self.binaryMessenger + codec:[FlutterStandardMethodCodec sharedInstance]]; - [_screenshotChannel.get() + [self.screenshotChannel setMethodCallHandler:^(FlutterMethodCall* _Nonnull call, FlutterResult _Nonnull result) { FlutterEngine* strongSelf = weakSelf; if (!(strongSelf && strongSelf->_shell && strongSelf->_shell->IsSetup())) { From f93f2384f7a89a761edfe98baa30d5a0db83ac0d Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:16:36 -0700 Subject: [PATCH 24/31] Migrate _publisher to property --- .../darwin/ios/framework/Source/FlutterEngine.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index c900afdd60b02..1030bade16ae3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -110,6 +110,7 @@ @interface FlutterEngine () flutterViewControllerWillDeallocObserver; +@property(nonatomic, strong) FlutterDartVMServicePublisher* publisher; #pragma mark - Channel properties @@ -145,7 +146,6 @@ @implementation FlutterEngine { std::unique_ptr _shell; fml::WeakNSObject _viewController; - fml::scoped_nsobject _publisher; std::shared_ptr _platformViewsController; flutter::IOSRenderingAPI _renderingApi; @@ -472,11 +472,11 @@ - (FlutterViewController*)viewController { } - (NSURL*)observatoryUrl { - return [_publisher.get() url]; + return [self.publisher url]; } - (NSURL*)vmServiceUrl { - return [_publisher.get() url]; + return [self.publisher url]; } - (void)resetChannels { @@ -691,8 +691,8 @@ - (void)setUpShell:(std::unique_ptr)shell [self setUpChannels]; [self onLocaleUpdated:nil]; [self updateDisplays]; - _publisher.reset([[FlutterDartVMServicePublisher alloc] - initWithEnableVMServicePublication:doesVMServicePublication]); + self.publisher = [[FlutterDartVMServicePublisher alloc] + initWithEnableVMServicePublication:doesVMServicePublication]; [self maybeSetupPlatformViewChannels]; _shell->SetGpuAvailability(_isGpuDisabled ? flutter::GpuAvailability::kUnavailable : flutter::GpuAvailability::kAvailable); From dab23663055676dc5e2c9331734c953ced8744d2 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:23:40 -0700 Subject: [PATCH 25/31] Migrate _nextTextureId, _allowHeadlessExecution, _restorationEnabled to properties --- .../ios/framework/Source/FlutterEngine.mm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 1030bade16ae3..bf6039252cfe4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -99,8 +99,13 @@ @interface FlutterEngine () + +#pragma mark - Properties + @property(nonatomic, readonly) FlutterDartProject* dartProject; @property(nonatomic, readonly, copy) NSString* labelPrefix; +@property(nonatomic, readonly, assign) BOOL allowHeadlessExecution; +@property(nonatomic, readonly, assign) BOOL restorationEnabled; // Maintains a dictionary of plugin names that have registered with the engine. Used by // FlutterEngineRegistrar to implement a FlutterPluginRegistrar. @@ -111,6 +116,7 @@ @interface FlutterEngine () flutterViewControllerWillDeallocObserver; @property(nonatomic, strong) FlutterDartVMServicePublisher* publisher; +@property(nonatomic, assign) int64_t nextTextureId; #pragma mark - Channel properties @@ -139,6 +145,7 @@ @interface FlutterEngine () _profiler_metrics; std::shared_ptr _profiler; - int64_t _nextTextureId; - - BOOL _allowHeadlessExecution; - BOOL _restorationEnabled; FlutterBinaryMessengerRelay* _binaryMessenger; FlutterTextureRegistryRelay* _textureRegistry; std::unique_ptr _connections; @@ -439,7 +442,7 @@ - (void)setFlutterViewControllerWillDeallocObserver:(id)observer { - (void)notifyViewControllerDeallocated { [self.lifecycleChannel sendMessage:@"AppLifecycleState.detached"]; self.textInputPlugin.viewController = nil; - if (!_allowHeadlessExecution) { + if (!self.allowHeadlessExecution) { [self destroyContext]; } else if (_shell) { flutter::PlatformViewIOS* platform_view = [self iosPlatformView]; @@ -604,7 +607,7 @@ - (void)setUpChannels { self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; self.restorationPlugin = [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel - restorationEnabled:_restorationEnabled]; + restorationEnabled:self.restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; self.screenshotChannel = @@ -1242,7 +1245,7 @@ - (void)cleanUpConnection:(FlutterBinaryMessengerConnection)connection { #pragma mark - FlutterTextureRegistry - (int64_t)registerTexture:(NSObject*)texture { - int64_t textureId = _nextTextureId++; + int64_t textureId = self.nextTextureId++; self.iosPlatformView->RegisterExternalTexture(textureId, texture); return textureId; } @@ -1373,7 +1376,7 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint NSAssert(_shell, @"Spawning from an engine without a shell (possibly not run)."); FlutterEngine* result = [[FlutterEngine alloc] initWithName:self.labelPrefix project:self.dartProject - allowHeadlessExecution:_allowHeadlessExecution]; + allowHeadlessExecution:self.allowHeadlessExecution]; flutter::RunConfiguration configuration = [self.dartProject runConfigurationForEntrypoint:entrypoint libraryOrNil:libraryURI From 1542c3f2c7b89bb859bcc9ff538ab75ee62b218f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:32:07 -0700 Subject: [PATCH 26/31] Add TODO to migrate _viewController --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index bf6039252cfe4..ee869a06da716 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -152,6 +152,8 @@ @implementation FlutterEngine { std::shared_ptr _threadHost; std::unique_ptr _shell; + // TODO(cbracken): https://github.com/flutter/flutter/issues/155943 + // Migrate to @property(nonatomic, weak). fml::WeakNSObject _viewController; std::shared_ptr _platformViewsController; From f676742f5c284061fb384fd988d98ed983462786 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 16:34:28 -0700 Subject: [PATCH 27/31] format --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index ee869a06da716..8353c555e6e43 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -608,8 +608,9 @@ - (void)setUpChannels { self.undoManagerPlugin = [[FlutterUndoManagerPlugin alloc] initWithDelegate:self]; self.platformPlugin = [[FlutterPlatformPlugin alloc] initWithEngine:self]; - self.restorationPlugin = [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel - restorationEnabled:self.restorationEnabled]; + self.restorationPlugin = + [[FlutterRestorationPlugin alloc] initWithChannel:self.restorationChannel + restorationEnabled:self.restorationEnabled]; self.spellCheckPlugin = [[FlutterSpellCheckPlugin alloc] init]; self.screenshotChannel = From 66923ddc415110da6a38e386a2e10ab5a5c5cbe9 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 17:01:16 -0700 Subject: [PATCH 28/31] Use weakSelf for handleMethodCall on plugins --- .../darwin/ios/framework/Source/FlutterEngine.mm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 8353c555e6e43..41a24d29dca70 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -646,13 +646,12 @@ - (void)setUpChannels { - (void)maybeSetupPlatformViewChannels { if (_shell && self.shell.IsSetup()) { - // TODO(cbracken): Use weakSelf for these. - FlutterPlatformPlugin* platformPlugin = self.platformPlugin; + __weak FlutterEngine* weakSelf = self; + [self.platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [platformPlugin handleMethodCall:call result:result]; + [weakSelf.platformPlugin handleMethodCall:call result:result]; }]; - __weak FlutterEngine* weakSelf = self; [self.platformViewsChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { if (weakSelf) { @@ -660,19 +659,16 @@ - (void)maybeSetupPlatformViewChannels { } }]; - FlutterTextInputPlugin* textInputPlugin = self.textInputPlugin; [self.textInputChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [textInputPlugin handleMethodCall:call result:result]; + [weakSelf.textInputPlugin handleMethodCall:call result:result]; }]; - FlutterUndoManagerPlugin* undoManagerPlugin = self.undoManagerPlugin; [self.undoManagerChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [undoManagerPlugin handleMethodCall:call result:result]; + [weakSelf.undoManagerPlugin handleMethodCall:call result:result]; }]; - FlutterSpellCheckPlugin* spellCheckPlugin = self.spellCheckPlugin; [self.spellCheckChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { - [spellCheckPlugin handleMethodCall:call result:result]; + [weakSelf.spellCheckPlugin handleMethodCall:call result:result]; }]; } } From 0ac6fa1b0da7f890c87fefcb7d0fa7a177157d40 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 3 Oct 2024 21:37:06 -0700 Subject: [PATCH 29/31] copy labelPrefix --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 41a24d29dca70..e10506fa66da8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -197,7 +197,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix _restorationEnabled = restorationEnabled; _allowHeadlessExecution = allowHeadlessExecution; - _labelPrefix = labelPrefix; + _labelPrefix = [labelPrefix copy]; _dartProject = project ?: [[FlutterDartProject alloc] init]; _enableEmbedderAPI = _dartProject.settings.enable_embedder_api; From ac5e0c2feec000e21d78fed6d27a99197946f9bc Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 4 Oct 2024 07:15:00 -0700 Subject: [PATCH 30/31] Review feedback --- .../ios/framework/Source/FlutterEngine.mm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index e10506fa66da8..085f0cff542cc 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -292,7 +292,9 @@ - (void)dealloc { object:self userInfo:nil]; - /// nil out weak references. + // nil out weak references. + // TODO(cbracken): https://github.com/flutter/flutter/issues/156222 + // Ensure that FlutterEngineRegistrar is using weak pointers, then eliminate this code. [_registrars enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineRegistrar* registrar, BOOL* stop) { registrar.flutterEngine = nil; @@ -413,13 +415,13 @@ - (void)setViewController:(FlutterViewController*)viewController { self.textInputPlugin.viewController = viewController; if (viewController) { - __weak __block FlutterEngine* blockSelf = self; + __weak __block FlutterEngine* weakSelf = self; self.flutterViewControllerWillDeallocObserver = [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc object:viewController queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* note) { - [blockSelf notifyViewControllerDeallocated]; + [weakSelf notifyViewControllerDeallocated]; }]; } else { self.flutterViewControllerWillDeallocObserver = nil; @@ -477,11 +479,11 @@ - (FlutterViewController*)viewController { } - (NSURL*)observatoryUrl { - return [self.publisher url]; + return self.publisher.url; } - (NSURL*)vmServiceUrl { - return [self.publisher url]; + return self.publisher.url; } - (void)resetChannels { @@ -628,7 +630,7 @@ - (void)setUpChannels { details:nil]); } flutter::Rasterizer::Screenshot screenshot = - [weakSelf screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData base64Encode:NO]; + [strongSelf screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData base64Encode:NO]; if (!screenshot.data) { return result([FlutterError errorWithCode:@"failure" message:@"Unable to get screenshot." @@ -794,6 +796,9 @@ - (BOOL)createShell:(NSString*)entrypoint flutter::Shell::CreateCallback on_create_platform_view = [weakSelf](flutter::Shell& shell) { FlutterEngine* strongSelf = weakSelf; + if (!strongSelf) { + return std::unique_ptr(); + } [strongSelf recreatePlatformViewController]; strongSelf->_platformViewsController->SetTaskRunner( shell.GetTaskRunners().GetPlatformTaskRunner()); From d93d56e7092eb53ac4efeeab5360f06c3ed5114d Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 4 Oct 2024 07:16:09 -0700 Subject: [PATCH 31/31] Reformat --- .../ios/framework/Source/FlutterEngine.mm | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 085f0cff542cc..bcbb3575a0c51 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -620,30 +620,30 @@ - (void)setUpChannels { binaryMessenger:self.binaryMessenger codec:[FlutterStandardMethodCodec sharedInstance]]; - [self.screenshotChannel - setMethodCallHandler:^(FlutterMethodCall* _Nonnull call, FlutterResult _Nonnull result) { - FlutterEngine* strongSelf = weakSelf; - if (!(strongSelf && strongSelf->_shell && strongSelf->_shell->IsSetup())) { - return result([FlutterError - errorWithCode:@"invalid_state" - message:@"Requesting screenshot while engine is not running." - details:nil]); - } - flutter::Rasterizer::Screenshot screenshot = - [strongSelf screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData base64Encode:NO]; - if (!screenshot.data) { - return result([FlutterError errorWithCode:@"failure" - message:@"Unable to get screenshot." - details:nil]); - } - // TODO(gaaclarke): Find way to eliminate this data copy. - NSData* data = [NSData dataWithBytes:screenshot.data->writable_data() - length:screenshot.data->size()]; - NSString* format = [NSString stringWithUTF8String:screenshot.format.c_str()]; - NSNumber* width = @(screenshot.frame_size.fWidth); - NSNumber* height = @(screenshot.frame_size.fHeight); - return result(@[ width, height, format ?: [NSNull null], data ]); - }]; + [self.screenshotChannel setMethodCallHandler:^(FlutterMethodCall* _Nonnull call, + FlutterResult _Nonnull result) { + FlutterEngine* strongSelf = weakSelf; + if (!(strongSelf && strongSelf->_shell && strongSelf->_shell->IsSetup())) { + return result([FlutterError + errorWithCode:@"invalid_state" + message:@"Requesting screenshot while engine is not running." + details:nil]); + } + flutter::Rasterizer::Screenshot screenshot = + [strongSelf screenshot:flutter::Rasterizer::ScreenshotType::SurfaceData base64Encode:NO]; + if (!screenshot.data) { + return result([FlutterError errorWithCode:@"failure" + message:@"Unable to get screenshot." + details:nil]); + } + // TODO(gaaclarke): Find way to eliminate this data copy. + NSData* data = [NSData dataWithBytes:screenshot.data->writable_data() + length:screenshot.data->size()]; + NSString* format = [NSString stringWithUTF8String:screenshot.format.c_str()]; + NSNumber* width = @(screenshot.frame_size.fWidth); + NSNumber* height = @(screenshot.frame_size.fHeight); + return result(@[ width, height, format ?: [NSNull null], data ]); + }]; } - (void)maybeSetupPlatformViewChannels {