|
26 | 26 |
|
27 | 27 | static const char* kApplicationKernelSnapshotFileName = "kernel_blob.bin"; |
28 | 28 |
|
29 | | -// TODO(mehmetf): Announce this since it is breaking change then enable it. |
30 | | -// static NSString* DomainNetworkPolicy(NSDictionary* appTransportSecurity) { |
31 | | -// if (appTransportSecurity == nil) { |
32 | | -// return @""; |
33 | | -// } |
34 | | -// // |
35 | | -// https://developer.apple.com/documentation/bundleresources/information_property_list/nsapptransportsecurity/nsexceptiondomains |
36 | | -// NSDictionary* exceptionDomains = [appTransportSecurity objectForKey:@"NSExceptionDomains"]; |
37 | | -// if (exceptionDomains == nil) { |
38 | | -// return @""; |
39 | | -// } |
40 | | -// NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init]; |
41 | | -// for (NSString* domain in exceptionDomains) { |
42 | | -// NSDictionary* domainConfiguration = [exceptionDomains objectForKey:domain]; |
43 | | -// BOOL includesSubDomains = |
44 | | -// [[domainConfiguration objectForKey:@"NSIncludesSubdomains"] boolValue]; |
45 | | -// BOOL allowsCleartextCommunication = |
46 | | -// [[domainConfiguration objectForKey:@"NSExceptionAllowsInsecureHTTPLoads"] boolValue]; |
47 | | -// [networkConfigArray addObject:[NSArray arrayWithObjects:domain, includesSubDomains, |
48 | | -// allowsCleartextCommunication, nil]]; |
49 | | -// } |
50 | | -// NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray |
51 | | -// options:0 |
52 | | -// error:NULL]; |
53 | | -// return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; |
54 | | -// } |
55 | | - |
56 | | -// TODO(mehmetf): Announce this since it is breaking change then enable it. |
57 | | -// static bool AllowsArbitraryLoads(NSDictionary* appTransportSecurity) { |
58 | | -// if (appTransportSecurity != nil) { |
59 | | -// return [[appTransportSecurity objectForKey:@"NSAllowsArbitraryLoads"] boolValue]; |
60 | | -// } else { |
61 | | -// return false; |
62 | | -// } |
63 | | -// } |
64 | | - |
65 | 29 | static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { |
66 | 30 | auto command_line = flutter::CommandLineFromNSProcessInfo(); |
67 | 31 |
|
|
168 | 132 | } |
169 | 133 | } |
170 | 134 |
|
171 | | - // TODO(mehmetf): Announce this since it is breaking change then enable it. |
172 | 135 | // Domain network configuration |
173 | | - // NSDictionary* appTransportSecurity = |
174 | | - // [mainBundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; |
175 | | - // settings.may_insecurely_connect_to_all_domains = AllowsArbitraryLoads(appTransportSecurity); |
176 | | - // settings.domain_network_policy = DomainNetworkPolicy(appTransportSecurity).UTF8String; |
| 136 | + NSDictionary* appTransportSecurity = |
| 137 | + [mainBundle objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; |
| 138 | + settings.may_insecurely_connect_to_all_domains = |
| 139 | + [FlutterDartProject allowsArbitraryLoads:appTransportSecurity]; |
| 140 | + settings.domain_network_policy = |
| 141 | + [FlutterDartProject domainNetworkPolicy:appTransportSecurity].UTF8String; |
| 142 | + |
| 143 | + // TODO(mehmetf): We need to announce this change since it is breaking. |
| 144 | + // Remove these two lines after we announce and we know which release this is |
| 145 | + // going to be part of. |
| 146 | + settings.may_insecurely_connect_to_all_domains = true; |
| 147 | + settings.domain_network_policy = ""; |
177 | 148 |
|
178 | 149 | #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG |
179 | 150 | // There are no ownership concerns here as all mappings are owned by the |
@@ -262,6 +233,34 @@ + (NSString*)flutterAssetsName:(NSBundle*)bundle { |
262 | 233 | return flutterAssetsName; |
263 | 234 | } |
264 | 235 |
|
| 236 | ++ (NSString*)domainNetworkPolicy:(NSDictionary*)appTransportSecurity { |
| 237 | + // https://developer.apple.com/documentation/bundleresources/information_property_list/nsapptransportsecurity/nsexceptiondomains |
| 238 | + NSDictionary* exceptionDomains = [appTransportSecurity objectForKey:@"NSExceptionDomains"]; |
| 239 | + if (exceptionDomains == nil) { |
| 240 | + return @""; |
| 241 | + } |
| 242 | + NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init]; |
| 243 | + for (NSString* domain in exceptionDomains) { |
| 244 | + NSDictionary* domainConfiguration = [exceptionDomains objectForKey:domain]; |
| 245 | + // Default value is false. |
| 246 | + bool includesSubDomains = |
| 247 | + [[domainConfiguration objectForKey:@"NSIncludesSubdomains"] boolValue]; |
| 248 | + bool allowsCleartextCommunication = |
| 249 | + [[domainConfiguration objectForKey:@"NSExceptionAllowsInsecureHTTPLoads"] boolValue]; |
| 250 | + [networkConfigArray addObject:@[ |
| 251 | + domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO |
| 252 | + ]]; |
| 253 | + } |
| 254 | + NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray |
| 255 | + options:0 |
| 256 | + error:NULL]; |
| 257 | + return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; |
| 258 | +} |
| 259 | + |
| 260 | ++ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity { |
| 261 | + return [[appTransportSecurity objectForKey:@"NSAllowsArbitraryLoads"] boolValue]; |
| 262 | +} |
| 263 | + |
265 | 264 | + (NSString*)lookupKeyForAsset:(NSString*)asset { |
266 | 265 | return [self lookupKeyForAsset:asset fromBundle:nil]; |
267 | 266 | } |
|
0 commit comments