Skip to content

Commit

Permalink
Migrate FlutterDartProject and FlutterPluginAppLifeCycleDelegate to A…
Browse files Browse the repository at this point in the history
…RC (#52719)

- Migrate `FlutterDartProject` and `FlutterPluginAppLifeCycleDelegate` from MRC to ARC.  
- Swap a few dictionary `objectForKey:` to subscripting.
- Header cleanup.
- Cleanup build DEPS.

Part of flutter/flutter#137801.
  • Loading branch information
jmagman committed May 13, 2024
1 parent 9d6d464 commit aeff9b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_HEADERS_FLUTTERDARTPROJECT_H_

#import <Foundation/Foundation.h>
#import <TargetConditionals.h>

#import "FlutterMacros.h"

Expand Down
11 changes: 3 additions & 8 deletions shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ source_set("flutter_framework_source_arc") {
"framework/Source/FlutterCallbackCache_Internal.h",
"framework/Source/FlutterChannelKeyResponder.h",
"framework/Source/FlutterChannelKeyResponder.mm",
"framework/Source/FlutterDartProject.mm",
"framework/Source/FlutterDartProject_Internal.h",
"framework/Source/FlutterDartVMServicePublisher.h",
"framework/Source/FlutterDartVMServicePublisher.mm",
"framework/Source/FlutterEmbedderKeyResponder.h",
Expand All @@ -78,6 +80,7 @@ source_set("flutter_framework_source_arc") {
"framework/Source/FlutterPlatformViews.mm",
"framework/Source/FlutterPlatformViews_Internal.h",
"framework/Source/FlutterPlatformViews_Internal.mm",
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
"framework/Source/FlutterRestorationPlugin.h",
"framework/Source/FlutterRestorationPlugin.mm",
"framework/Source/FlutterSpellCheckPlugin.h",
Expand Down Expand Up @@ -162,15 +165,12 @@ source_set("flutter_framework_source") {
# 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/FlutterAppDelegate.mm",
"framework/Source/FlutterDartProject.mm",
"framework/Source/FlutterDartProject_Internal.h",
"framework/Source/FlutterEngine.mm",
"framework/Source/FlutterEngineGroup.mm",
"framework/Source/FlutterEngine_Internal.h",
"framework/Source/FlutterHeadlessDartRunner.mm",
"framework/Source/FlutterPlatformPlugin.h",
"framework/Source/FlutterPlatformPlugin.mm",
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
"framework/Source/FlutterSemanticsScrollView.h",
"framework/Source/FlutterSemanticsScrollView.mm",
"framework/Source/FlutterViewController.mm",
Expand All @@ -195,19 +195,14 @@ source_set("flutter_framework_source") {
}

deps += [
":ios_gpu_configuration",
"//flutter/common",
"//flutter/flow",
"//flutter/fml",
"//flutter/runtime",
"//flutter/runtime:libdart",
"//flutter/shell/common",
"//flutter/shell/platform/common:common_cpp_input",
"//flutter/shell/platform/darwin/common",
"//flutter/shell/platform/darwin/common:framework_common",
"//flutter/shell/platform/embedder:embedder_as_internal_library",
"//flutter/shell/profiling:profiling",
"//flutter/skia",
"//flutter/third_party/spring_animation",
]

Expand Down
34 changes: 12 additions & 22 deletions shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"

#include <syslog.h>

#import <Metal/Metal.h>
#include <sstream>
#include <string>
#import <UIKit/UIKit.h>

#include <syslog.h>

#include "flutter/common/constants.h"
#include "flutter/common/task_runners.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/switches.h"
#import "flutter/shell/platform/darwin/common/command_line.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"

FLUTTER_ASSERT_NOT_ARC
FLUTTER_ASSERT_ARC

extern "C" {
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
Expand All @@ -47,7 +39,6 @@ static BOOL DoesHardwareSupportWideGamut() {
// A9/A10 on iOS 10+
result = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v2];
}
[device release];
});
return result;
}
Expand All @@ -62,7 +53,7 @@ static BOOL DoesHardwareSupportWideGamut() {
// 4. Settings from the main NSBundle and default values.

NSBundle* mainBundle = FLTGetApplicationBundle();
NSBundle* engineBundle = [NSBundle bundleForClass:[FlutterViewController class]];
NSBundle* engineBundle = [NSBundle bundleForClass:[FlutterDartProject class]];

bool hasExplicitBundle = bundle != nil;
if (bundle == nil) {
Expand Down Expand Up @@ -369,30 +360,29 @@ + (NSString*)flutterAssetsName:(NSBundle*)bundle {

+ (NSString*)domainNetworkPolicy:(NSDictionary*)appTransportSecurity {
// https://developer.apple.com/documentation/bundleresources/information_property_list/nsapptransportsecurity/nsexceptiondomains
NSDictionary* exceptionDomains = [appTransportSecurity objectForKey:@"NSExceptionDomains"];
NSDictionary* exceptionDomains = appTransportSecurity[@"NSExceptionDomains"];
if (exceptionDomains == nil) {
return @"";
}
NSMutableArray* networkConfigArray = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init];
for (NSString* domain in exceptionDomains) {
NSDictionary* domainConfiguration = [exceptionDomains objectForKey:domain];
NSDictionary* domainConfiguration = exceptionDomains[domain];
// Default value is false.
bool includesSubDomains =
[[domainConfiguration objectForKey:@"NSIncludesSubdomains"] boolValue];
bool includesSubDomains = [domainConfiguration[@"NSIncludesSubdomains"] boolValue];
bool allowsCleartextCommunication =
[[domainConfiguration objectForKey:@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
[domainConfiguration[@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
[networkConfigArray addObject:@[
domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO
]];
}
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray
options:0
error:NULL];
return [[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

+ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity {
return [[appTransportSecurity objectForKey:@"NSAllowsArbitraryLoads"] boolValue];
return [appTransportSecurity[@"NSAllowsArbitraryLoads"] boolValue];
}

+ (NSString*)lookupKeyForAsset:(NSString*)asset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "flutter/fml/logging.h"
#include "flutter/fml/paths.h"
#include "flutter/lib/ui/plugins/callback_cache.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h"

FLUTTER_ASSERT_ARC

static const char* kCallbackCacheSubDir = "Library/Caches/";

static const SEL kSelectorsHandledByPlugins[] = {
Expand Down Expand Up @@ -43,7 +44,7 @@ - (void)addObserverFor:(NSString*)name selector:(SEL)selector {
dispatch_block_t unsubscribe = ^{
[[NSNotificationCenter defaultCenter] removeObserver:blockSelf name:name object:nil];
};
[_notificationUnsubscribers addObject:[[unsubscribe copy] autorelease]];
[_notificationUnsubscribers addObject:[unsubscribe copy]];
}

- (instancetype)init {
Expand All @@ -63,7 +64,7 @@ - (instancetype)init {
[self addObserverFor:UIApplicationWillTerminateNotification
selector:@selector(handleWillTerminate:)];
#endif
_delegates = [[NSPointerArray weakObjectsPointerArray] retain];
_delegates = [NSPointerArray weakObjectsPointerArray];
_debugBackgroundTask = UIBackgroundTaskInvalid;
}
return self;
Expand All @@ -73,9 +74,6 @@ - (void)dealloc {
for (dispatch_block_t unsubscribe in _notificationUnsubscribers) {
unsubscribe();
}
[_notificationUnsubscribers release];
[_delegates release];
[super dealloc];
}

static BOOL IsPowerOfTwo(NSUInteger x) {
Expand Down

0 comments on commit aeff9b1

Please sign in to comment.