diff --git a/mozilla/camino/src/browser/BrowserWindowController.mm b/mozilla/camino/src/browser/BrowserWindowController.mm index f9d9a3bb587..ee89367787e 100644 --- a/mozilla/camino/src/browser/BrowserWindowController.mm +++ b/mozilla/camino/src/browser/BrowserWindowController.mm @@ -1657,70 +1657,19 @@ enum BWCOpenDest { } } - -// // - transformFormatString:domain:search // // Replaces all occurances of %d in |inFormat| with |inDomain| and all occurances of -// %s with |inSearch|. This is easy on jaguar and beyond, but not as easy on 10.1. Both -// implementations are presented here. -// +// %s with |inSearch|. - (void) transformFormatString:(NSMutableString*)inFormat domain:(NSString*)inDomain search:(NSString*)inSearch { - if ([NSMutableString instancesRespondToSelector: - @selector(replaceOccurrencesOfString:withString:options:range:)]) { - - // If we're on Mac OS X >= 10.2... - - // Replace any occurence of %d with the current domain - [inFormat replaceOccurrencesOfString:@"%d" withString:inDomain options:NSBackwardsSearch - range:NSMakeRange(0, [inFormat length])]; - - // Replace any occurence of %s with the contents of the search text field - [inFormat replaceOccurrencesOfString:@"%s" withString:inSearch options:NSBackwardsSearch - range:NSMakeRange(0, [inFormat length])]; - } - else { - - // If we're not on Mac OS X 10.2, do the string replacement manually - - NSRange notFoundRange = NSMakeRange(NSNotFound, 0); - - // Keep finding %d's and replacing them with the domain - NSRange domainEscapeRange = [inFormat rangeOfString:@"%d" options:NSBackwardsSearch]; - - while (NSEqualRanges(domainEscapeRange, notFoundRange) == NO) { - [inFormat replaceCharactersInRange:domainEscapeRange withString:inDomain]; - - // Get the next %d found. A domain can't contain a %d string, - // so don't worry about that - domainEscapeRange = [inFormat rangeOfString:@"%d" options:NSBackwardsSearch]; - } - - // Replace any occurence of %s with the contents of the search text field - NSMutableArray *formatLocations = [[NSMutableArray alloc] init]; - NSScanner *formatScanner = [NSScanner scannerWithString:inFormat]; - NSString *tempString = nil; - - // Find the locations of all %s and store them in an NSMutableArray - const int kStringConverterLen = 2; // strlen("%s") - [formatScanner scanUpToString:@"%s" intoString:nil]; - while ([formatScanner scanString:@"%s" intoString:&tempString]) { - [formatLocations addObject:[NSNumber numberWithUnsignedInt:([formatScanner scanLocation] - kStringConverterLen)]]; - - [formatScanner scanUpToString:@"%s" intoString:nil]; - } - - // Replace all %s in the string, starting at the end first to so we don't disrupt the - // ranges we've computed - NSRange formatRange; - for (int i = [formatLocations count] - 1; i >= 0; i--) { - formatRange = NSMakeRange([[formatLocations objectAtIndex:i] unsignedIntValue], 2); - [inFormat replaceCharactersInRange:formatRange withString:inSearch]; - } - - [formatLocations release]; - } + // Replace any occurence of %d with the current domain + [inFormat replaceOccurrencesOfString:@"%d" withString:inDomain options:NSBackwardsSearch + range:NSMakeRange(0, [inFormat length])]; + + // Replace any occurence of %s with the contents of the search text field + [inFormat replaceOccurrencesOfString:@"%s" withString:inSearch options:NSBackwardsSearch + range:NSMakeRange(0, [inFormat length])]; } - (IBAction)sendURL:(id)aSender diff --git a/mozilla/camino/src/download/SaveHeaderSniffer.mm b/mozilla/camino/src/download/SaveHeaderSniffer.mm index 0ccd21ddec9..cd976d1a944 100644 --- a/mozilla/camino/src/download/SaveHeaderSniffer.mm +++ b/mozilla/camino/src/download/SaveHeaderSniffer.mm @@ -169,15 +169,6 @@ nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI) // Are we an HTML document? If so, we will want to append an accessory view to // the save dialog to provide the user with the option of doing a complete // save vs. a single file save. -#if 0 - // The MOZILLA_1_0_BRANCH source Chimera is currently based on can't handle saving an XML - // document other than as source so only offer the format popup if it's a text/html content. - // Leaving this code here #ifdef'd out for when we get to a more recent - // version of the Mozilla source tree. - PRBool isHTML = (mDocument && mContentType.Equals("text/html") || - mContentType.Equals("text/html") || - mContentType.Equals("application/xhtml+xml")); -#endif PRBool isHTML = (mDocument && mContentType.Equals("text/html")); // Next find out the directory that we should start in. @@ -241,11 +232,11 @@ nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI) if (defaultFileName.IsEmpty()) { nsCOMPtr url(do_QueryInterface(origURI)); - if (url) - { + if (url) { nsCAutoString urlFileName; url->GetFileName(urlFileName); // (2) For file URLs, use the file name. - CopyUTF8toUTF16(urlFileName, defaultFileName); + NSString* unescapedString = [NSString unescapedURLString:[NSString stringWithUTF8String:urlFileName.get()]]; + CopyUTF8toUTF16([unescapedString UTF8String], defaultFileName); } } diff --git a/mozilla/camino/src/extensions/NSString+Utils.h b/mozilla/camino/src/extensions/NSString+Utils.h index 64456e6a730..06edb0b8a3c 100644 --- a/mozilla/camino/src/extensions/NSString+Utils.h +++ b/mozilla/camino/src/extensions/NSString+Utils.h @@ -53,6 +53,7 @@ typedef enum + (id)ellipsisString; + (id)escapedURLString:(NSString *)unescapedString; ++ (NSString*)unescapedURLString:(NSString*)escapedString; + (id)stringWithPRUnichars:(const PRUnichar*)inString; + (id)stringWith_nsAString:(const nsAString&)inString; - (void)assignTo_nsAString:(nsAString&)ioString; diff --git a/mozilla/camino/src/extensions/NSString+Utils.mm b/mozilla/camino/src/extensions/NSString+Utils.mm index e866840307f..b7863cce7a8 100644 --- a/mozilla/camino/src/extensions/NSString+Utils.mm +++ b/mozilla/camino/src/extensions/NSString+Utils.mm @@ -66,6 +66,12 @@ return [escapedString autorelease]; } ++ (NSString*)unescapedURLString:(NSString*)escapedString +{ + NSString *unescapedString = (NSString *)CFURLCreateStringByReplacingPercentEscapes(NULL, (CFStringRef)escapedString, CFSTR("")); + return [unescapedString autorelease]; +} + + (id)stringWithPRUnichars:(const PRUnichar*)inString { if (inString)