mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
decode local file URLs before suggesting them in save panel. b=166694 sr=pinkerton
This commit is contained in:
parent
b1155fa9e0
commit
9f720a6356
@ -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
|
||||
|
@ -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<nsIURL> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user