Changeset 236767 in webkit
- Timestamp:
- Oct 2, 2018, 3:34:09 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
platform/mac/WebCoreNSURLExtras.mm (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r236765 r236767 1 2018-10-02 Alex Christensen <achristensen@webkit.org> 2 3 Prepare WebCoreNSURLExtras for ARC 4 https://bugs.webkit.org/show_bug.cgi?id=190219 5 6 Reviewed by Tim Horton. 7 8 ARC doesn't like the explicit sending of -release. 9 Use RetainPtr instead. 10 11 * platform/mac/WebCoreNSURLExtras.mm: 12 (WebCore::collectRangesThatNeedMapping): 13 (WebCore::collectRangesThatNeedEncoding): 14 (WebCore::collectRangesThatNeedDecoding): 15 (WebCore::applyHostNameFunctionToMailToURLString): 16 (WebCore::applyHostNameFunctionToURLString): 17 (WebCore::mapHostNames): 18 (WebCore::stringByTrimmingWhitespace): 19 (WebCore::URLWithUserTypedString): 20 (WebCore::userVisibleString): 21 (WebCore::rangeOfURLScheme): 22 (WebCore::looksLikeAbsoluteURL): 23 (WebCore::retain): Deleted. 24 1 25 2018-10-02 Basuke Suzuki <Basuke.Suzuki@sony.com> 2 26 -
trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm
r236703 r236767 45 45 #define URL_BYTES_BUFFER_LENGTH 2048 46 46 47 typedef void (* StringRangeApplierFunction)(NSString * string, NSRange range, void *context);47 typedef void (* StringRangeApplierFunction)(NSString *, NSRange, RetainPtr<NSMutableArray>&); 48 48 49 49 static uint32_t IDNScriptWhiteList[(USCRIPT_CODE_LIMIT + 31) / 32]; … … 632 632 } 633 633 634 static void collectRangesThatNeedMapping(NSString *string, NSRange range, void *context, BOOL encode)634 static void collectRangesThatNeedMapping(NSString *string, NSRange range, RetainPtr<NSMutableArray>& array, BOOL encode) 635 635 { 636 636 // Generally, we want to optimize for the case where there is one host name that does not need mapping. … … 642 642 return; 643 643 644 __strong NSMutableArray **array = (__strong NSMutableArray **)context; 645 if (!*array) 646 *array = [[NSMutableArray alloc] init]; 647 644 if (!array) 645 array = adoptNS([NSMutableArray new]); 646 648 647 if (!error) 649 [*array addObject:[NSValue valueWithRange:range]]; 650 } 651 652 static void collectRangesThatNeedEncoding(NSString *string, NSRange range, void *context) 653 { 654 return collectRangesThatNeedMapping(string, range, context, YES); 655 } 656 657 static void collectRangesThatNeedDecoding(NSString *string, NSRange range, void *context) 658 { 659 return collectRangesThatNeedMapping(string, range, context, NO); 660 } 661 662 static inline NSCharacterSet *retain(NSCharacterSet *charset) 663 { 664 CFRetain(charset); 665 return charset; 666 } 667 668 static void applyHostNameFunctionToMailToURLString(NSString *string, StringRangeApplierFunction f, void *context) 648 [array addObject:[NSValue valueWithRange:range]]; 649 } 650 651 static void collectRangesThatNeedEncoding(NSString *string, NSRange range, RetainPtr<NSMutableArray>& array) 652 { 653 return collectRangesThatNeedMapping(string, range, array, YES); 654 } 655 656 static void collectRangesThatNeedDecoding(NSString *string, NSRange range, RetainPtr<NSMutableArray>& array) 657 { 658 return collectRangesThatNeedMapping(string, range, array, NO); 659 } 660 661 static void applyHostNameFunctionToMailToURLString(NSString *string, StringRangeApplierFunction f, RetainPtr<NSMutableArray>& array) 669 662 { 670 663 // In a mailto: URL, host names come after a '@' character and end with a '>' or ',' or '?' character. … … 672 665 // When we find a '?' character, we are past the part of the URL that contains host names. 673 666 674 static N SCharacterSet *hostNameOrStringStartCharacters = retain([NSCharacterSet characterSetWithCharactersInString:@"\"@?"]);675 static N SCharacterSet *hostNameEndCharacters = retain([NSCharacterSet characterSetWithCharactersInString:@">,?"]);676 static N SCharacterSet *quotedStringCharacters = retain([NSCharacterSet characterSetWithCharactersInString:@"\"\\"]);667 static NeverDestroyed<RetainPtr<NSCharacterSet>> hostNameOrStringStartCharacters = [NSCharacterSet characterSetWithCharactersInString:@"\"@?"]; 668 static NeverDestroyed<RetainPtr<NSCharacterSet>> hostNameEndCharacters = [NSCharacterSet characterSetWithCharactersInString:@">,?"]; 669 static NeverDestroyed<RetainPtr<NSCharacterSet>> quotedStringCharacters = [NSCharacterSet characterSetWithCharactersInString:@"\"\\"]; 677 670 678 671 unsigned stringLength = [string length]; … … 681 674 while (1) { 682 675 // Find start of host name or of quoted string. 683 NSRange hostNameOrStringStart = [string rangeOfCharacterFromSet:hostNameOrStringStartCharacters options:0 range:remaining];676 NSRange hostNameOrStringStart = [string rangeOfCharacterFromSet:hostNameOrStringStartCharacters.get().get() options:0 range:remaining]; 684 677 if (hostNameOrStringStart.location == NSNotFound) 685 678 return; … … 695 688 // Find end of host name. 696 689 unsigned hostNameStart = remaining.location; 697 NSRange hostNameEnd = [string rangeOfCharacterFromSet:hostNameEndCharacters options:0 range:remaining];690 NSRange hostNameEnd = [string rangeOfCharacterFromSet:hostNameEndCharacters.get().get() options:0 range:remaining]; 698 691 BOOL done; 699 692 if (hostNameEnd.location == NSNotFound) { … … 707 700 708 701 // Process host name range. 709 f(string, NSMakeRange(hostNameStart, hostNameEnd.location - hostNameStart), context);702 f(string, NSMakeRange(hostNameStart, hostNameEnd.location - hostNameStart), array); 710 703 711 704 if (done) … … 715 708 ASSERT(c == '"'); 716 709 while (1) { 717 NSRange escapedCharacterOrStringEnd = [string rangeOfCharacterFromSet:quotedStringCharacters options:0 range:remaining];710 NSRange escapedCharacterOrStringEnd = [string rangeOfCharacterFromSet:quotedStringCharacters.get().get() options:0 range:remaining]; 718 711 if (escapedCharacterOrStringEnd.location == NSNotFound) 719 712 return; … … 739 732 } 740 733 741 static void applyHostNameFunctionToURLString(NSString *string, StringRangeApplierFunction f, void *context)734 static void applyHostNameFunctionToURLString(NSString *string, StringRangeApplierFunction f, RetainPtr<NSMutableArray>& array) 742 735 { 743 736 // Find hostnames. Too bad we can't use any real URL-parsing code to do this, … … 748 741 749 742 if (protocolIs(string, "mailto")) { 750 applyHostNameFunctionToMailToURLString(string, f, context);743 applyHostNameFunctionToMailToURLString(string, f, array); 751 744 return; 752 745 } … … 761 754 762 755 // Check that all characters before the :// are valid scheme characters. 763 static N SCharacterSet *nonSchemeCharacters = retain([[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-."] invertedSet]);764 if ([string rangeOfCharacterFromSet:nonSchemeCharacters options:0 range:NSMakeRange(0, separatorRange.location)].location != NSNotFound)756 static NeverDestroyed<RetainPtr<NSCharacterSet>> nonSchemeCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-."] invertedSet]; 757 if ([string rangeOfCharacterFromSet:nonSchemeCharacters.get().get() options:0 range:NSMakeRange(0, separatorRange.location)].location != NSNotFound) 765 758 return; 766 759 767 760 unsigned stringLength = [string length]; 768 761 769 static N SCharacterSet *hostTerminators = retain([NSCharacterSet characterSetWithCharactersInString:@":/?#"]);762 static NeverDestroyed<RetainPtr<NSCharacterSet>> hostTerminators = [NSCharacterSet characterSetWithCharactersInString:@":/?#"]; 770 763 771 764 // Start after the separator. … … 773 766 774 767 // Find terminating character. 775 NSRange hostNameTerminator = [string rangeOfCharacterFromSet:hostTerminators options:0 range:NSMakeRange(authorityStart, stringLength - authorityStart)];768 NSRange hostNameTerminator = [string rangeOfCharacterFromSet:hostTerminators.get().get() options:0 range:NSMakeRange(authorityStart, stringLength - authorityStart)]; 776 769 unsigned hostNameEnd = hostNameTerminator.location == NSNotFound ? stringLength : hostNameTerminator.location; 777 770 … … 780 773 unsigned hostNameStart = userInfoTerminator.location == NSNotFound ? authorityStart : NSMaxRange(userInfoTerminator); 781 774 782 f(string, NSMakeRange(hostNameStart, hostNameEnd - hostNameStart), context);783 } 784 785 static NSString *mapHostNames(NSString *string, BOOL encode)775 return f(string, NSMakeRange(hostNameStart, hostNameEnd - hostNameStart), array); 776 } 777 778 static RetainPtr<NSString> mapHostNames(NSString *string, BOOL encode) 786 779 { 787 780 // Generally, we want to optimize for the case where there is one host name that does not need mapping. … … 791 784 792 785 // Make a list of ranges that actually need mapping. 793 NSMutableArray *hostNameRanges = nil;786 RetainPtr<NSMutableArray> hostNameRanges; 794 787 StringRangeApplierFunction f = encode ? collectRangesThatNeedEncoding : collectRangesThatNeedDecoding; 795 applyHostNameFunctionToURLString(string, f, &hostNameRanges);788 applyHostNameFunctionToURLString(string, f, hostNameRanges); 796 789 if (!hostNameRanges) 797 790 return string; 798 791 799 if (![hostNameRanges count]) { 800 [hostNameRanges release]; 801 return nil; 802 } 792 if (![hostNameRanges count]) 793 return nil; 803 794 804 795 // Do the mapping. 805 NSMutableString *mutableCopy = [string mutableCopy];796 auto mutableCopy = adoptNS([string mutableCopy]); 806 797 unsigned i = [hostNameRanges count]; 807 798 while (i--) { … … 810 801 [mutableCopy replaceCharactersInRange:hostNameRange withString:mappedHostName]; 811 802 } 812 [hostNameRanges release]; 813 return [mutableCopy autorelease]; 814 } 815 816 static NSString *stringByTrimmingWhitespace(NSString *string) 817 { 818 NSMutableString *trimmed = [[string mutableCopy] autorelease]; 819 CFStringTrimWhitespace((__bridge CFMutableStringRef)trimmed); 803 return mutableCopy; 804 } 805 806 static RetainPtr<NSString> stringByTrimmingWhitespace(NSString *string) 807 { 808 auto trimmed = adoptNS([string mutableCopy]); 809 CFStringTrimWhitespace((__bridge CFMutableStringRef)trimmed.get()); 820 810 return trimmed; 821 811 } … … 913 903 return nil; 914 904 915 string = mapHostNames(stringByTrimmingWhitespace(string), YES);916 if (! string)905 auto mappedString = mapHostNames(stringByTrimmingWhitespace(string).get(), YES); 906 if (!mappedString) 917 907 return nil; 918 908 919 909 // Let's check whether the URL is bogus. 920 URL url { URL { nsURL }, string};910 URL url { URL { nsURL }, mappedString.get() }; 921 911 if (!url.createCFURL()) 922 912 return nil; … … 924 914 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=186057 925 915 // We should be able to use url.createCFURL instead of using directly CFURL parsing routines. 926 NSData *data = dataWithUserTypedString( string);916 NSData *data = dataWithUserTypedString(mappedString.get()); 927 917 if (!data) 928 918 return [NSURL URLWithString:@""]; … … 1159 1149 1160 1150 // Check string to see if it can be converted to display using UTF-8 1161 NSString *result = [NSString stringWithUTF8String:after.data()];1151 RetainPtr<NSString> result = [NSString stringWithUTF8String:after.data()]; 1162 1152 if (!result) { 1163 1153 // Could not convert to UTF-8. … … 1186 1176 if (mayNeedHostNameDecoding) { 1187 1177 // FIXME: Is it good to ignore the failure of mapHostNames and keep result intact? 1188 NSString *mappedResult = mapHostNames(result, NO);1178 auto mappedResult = mapHostNames(result.get(), NO); 1189 1179 if (mappedResult) 1190 1180 result = mappedResult; … … 1192 1182 1193 1183 result = [result precomposedStringWithCanonicalMapping]; 1194 return CFBridgingRelease(createStringWithEscapedUnsafeCharacters((__bridge CFStringRef)result ));1184 return CFBridgingRelease(createStringWithEscapedUnsafeCharacters((__bridge CFStringRef)result.get())); 1195 1185 } 1196 1186 … … 1239 1229 if (colon.location != NSNotFound && colon.location > 0) { 1240 1230 NSRange scheme = {0, colon.location}; 1241 static NSCharacterSet *InverseSchemeCharacterSet = nil; 1242 if (!InverseSchemeCharacterSet) { 1243 /* 1244 This stuff is very expensive. 10-15 msec on a 2x1.2GHz. If not cached it swamps 1245 everything else when adding items to the autocomplete DB. Makes me wonder if we 1246 even need to enforce the character set here. 1247 */ 1248 NSString *acceptableCharacters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; 1249 InverseSchemeCharacterSet = [[[NSCharacterSet characterSetWithCharactersInString:acceptableCharacters] invertedSet] retain]; 1250 } 1251 NSRange illegals = [string rangeOfCharacterFromSet:InverseSchemeCharacterSet options:0 range:scheme]; 1231 /* 1232 This stuff is very expensive. 10-15 msec on a 2x1.2GHz. If not cached it swamps 1233 everything else when adding items to the autocomplete DB. Makes me wonder if we 1234 even need to enforce the character set here. 1235 */ 1236 NSString *acceptableCharacters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; 1237 static NeverDestroyed<RetainPtr<NSCharacterSet>> InverseSchemeCharacterSet([[NSCharacterSet characterSetWithCharactersInString:acceptableCharacters] invertedSet]); 1238 NSRange illegals = [string rangeOfCharacterFromSet:InverseSchemeCharacterSet.get().get() options:0 range:scheme]; 1252 1239 if (illegals.location == NSNotFound) 1253 1240 return scheme; … … 1259 1246 { 1260 1247 // Trim whitespace because _web_URLWithString allows whitespace. 1261 return rangeOfURLScheme(stringByTrimmingWhitespace(string) ).location != NSNotFound;1248 return rangeOfURLScheme(stringByTrimmingWhitespace(string).get()).location != NSNotFound; 1262 1249 } 1263 1250
Note:
See TracChangeset
for help on using the changeset viewer.