Mercurial > dwindows
comparison ios/dw.m @ 2786:3934ac8b394c
iOS: Make dw_file_browse() grant access to security scoped resources.
At some point revoke access, so we don't leak kernel resources... so
maintain a list of URLs and when the list gets too long revoke access.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 13 Jul 2022 04:51:09 +0000 |
parents | af9dc4c2c0df |
children | 56312f9c1d6c |
comparison
equal
deleted
inserted
replaced
2785:220d63da2183 | 2786:3934ac8b394c |
---|---|
565 void *user = NULL; | 565 void *user = NULL; |
566 id item = nil; | 566 id item = nil; |
567 | 567 |
568 if([object isKindOfClass:[UITableView class]] && event) | 568 if([object isKindOfClass:[UITableView class]] && event) |
569 { | 569 { |
570 | |
571 if([event isKindOfClass:[NSPointerArray class]]) | 570 if([event isKindOfClass:[NSPointerArray class]]) |
572 { | 571 { |
573 /* The NSPointerArray count will be 2 for Containers */ | 572 /* The NSPointerArray count will be 2 for Containers */ |
574 text = [event pointerAtIndex:0]; | 573 text = [event pointerAtIndex:0]; |
575 user = [event pointerAtIndex:1]; | 574 user = [event pointerAtIndex:1]; |
1090 -(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls; | 1089 -(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls; |
1091 -(void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller; | 1090 -(void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller; |
1092 -(void)setDialog:(DWDialog *)newdialog; | 1091 -(void)setDialog:(DWDialog *)newdialog; |
1093 @end | 1092 @end |
1094 | 1093 |
1094 #define _DW_URL_LIMIT 10 | |
1095 static NSMutableArray *_dw_URLs = nil; | |
1096 | |
1095 @implementation DWDocumentPickerDelegate | 1097 @implementation DWDocumentPickerDelegate |
1096 -(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls | 1098 -(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls |
1097 { | 1099 { |
1098 NSURL *url = [urls firstObject]; | 1100 NSURL *url = [urls firstObject]; |
1099 char *file = NULL; | 1101 char *file = NULL; |
1100 | 1102 |
1101 if(url) | 1103 if(url) |
1102 { | 1104 { |
1103 const char *tmp = [url fileSystemRepresentation]; | 1105 const char *tmp = [url fileSystemRepresentation]; |
1104 | 1106 |
1105 if(tmp) | 1107 if(tmp && [url startAccessingSecurityScopedResource]) |
1108 { | |
1109 /* We need to allow access to the returned URLs on iOS 13 | |
1110 * but we have no way of knowing when it is no longer needed... | |
1111 * since the C API we are connected to does not have that information. | |
1112 * So maintain a list of URLs, and when the list exceeds the limit... | |
1113 * revoke access to the oldest URL. | |
1114 */ | |
1115 if(!_dw_URLs) | |
1116 _dw_URLs = [[[NSMutableArray alloc] init] retain]; | |
1117 if(_dw_URLs) | |
1118 { | |
1119 if([_dw_URLs count] >= _DW_URL_LIMIT) | |
1120 { | |
1121 NSURL *oldurl = [_dw_URLs firstObject]; | |
1122 [oldurl stopAccessingSecurityScopedResource]; | |
1123 [_dw_URLs removeObject:oldurl]; | |
1124 } | |
1125 [_dw_URLs addObject:url]; | |
1126 } | |
1106 file = strdup(tmp); | 1127 file = strdup(tmp); |
1128 } | |
1107 } | 1129 } |
1108 dw_dialog_dismiss(dialog, file); | 1130 dw_dialog_dismiss(dialog, file); |
1109 } | 1131 } |
1110 -(void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller | 1132 -(void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller |
1111 { | 1133 { |