diff --git a/mozilla/camino/Camino.xcode/project.pbxproj b/mozilla/camino/Camino.xcode/project.pbxproj index 9e43fee314a..2f7434e3efb 100644 --- a/mozilla/camino/Camino.xcode/project.pbxproj +++ b/mozilla/camino/Camino.xcode/project.pbxproj @@ -3614,6 +3614,7 @@ 3FFFEC1F081C3F0B00843C07, 3FBDC7DB08252CF300D7F8E0, 3FBDC7DC08252CF300D7F8E0, + 3FE4ECEA082C2D89003BF39E, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -7478,6 +7479,7 @@ 3FFFEC21081C3F0B00843C07, 3FBDC7DD08252CF300D7F8E0, 3FBDC7DE08252CF300D7F8E0, + 3FE4ECEB082C2D89003BF39E, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -10429,6 +10431,27 @@ settings = { }; }; + 3FE4ECE9082C2D89003BF39E = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + name = "NSURL+Utils.m"; + path = "src/extensions/NSURL+Utils.m"; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 3FE4ECEA082C2D89003BF39E = { + fileRef = 3FE4ECE9082C2D89003BF39E; + isa = PBXBuildFile; + settings = { + }; + }; + 3FE4ECEB082C2D89003BF39E = { + fileRef = 3FE4ECE9082C2D89003BF39E; + isa = PBXBuildFile; + settings = { + }; + }; 3FE5B9FC068A090F0001CECD = { isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; @@ -14851,6 +14874,7 @@ 3FF08EFD06E7CF86001C9B19, 3FF08EFE06E7CF86001C9B19, 3FF08EFF06E7CF86001C9B19, + 3FE4ECE9082C2D89003BF39E, ); isa = PBXGroup; name = Source; diff --git a/mozilla/camino/src/application/MainController.h b/mozilla/camino/src/application/MainController.h index 1c9812116c6..1f37dd740bf 100644 --- a/mozilla/camino/src/application/MainController.h +++ b/mozilla/camino/src/application/MainController.h @@ -200,10 +200,6 @@ typedef enum EBookmarkOpenBehavior // prompts the user to reset the cache, then does it - (IBAction)emptyCache:(id)sender; -// open different URL file types -+(NSString*)urlStringFromWebloc:(NSString*)inFile; -+(NSString*)urlStringFromIEURLFile:(NSString*)inFile; - // OS feature checks + (BOOL)supportsSpotlight; + (BOOL)supportsBonjour; diff --git a/mozilla/camino/src/application/MainController.mm b/mozilla/camino/src/application/MainController.mm index ef087f080b5..527f692107b 100644 --- a/mozilla/camino/src/application/MainController.mm +++ b/mozilla/camino/src/application/MainController.mm @@ -44,6 +44,7 @@ #import "NSString+Utils.h" #import "NSResponder+Utils.h" #import "NSMenu+Utils.h" +#import "NSURL+Utils.h" #import "ChimeraUIConstants.h" #import "MainController.h" @@ -505,16 +506,12 @@ Otherwise, we return the URL we originally got. Right now this supports .url and +(NSURL*) decodeLocalFileURL:(NSURL*)url { NSString *urlPathString = [url path]; - if ([[urlPathString pathExtension] isEqualToString:@"url"]) { - NSString *decodedURL = [MainController urlStringFromIEURLFile:urlPathString]; - if (decodedURL) - url = [NSURL URLWithString:decodedURL]; - } - else if ([[urlPathString pathExtension] isEqualToString:@"webloc"]) { - NSString *decodedURL = [MainController urlStringFromWebloc:urlPathString]; - if (decodedURL) - url = [NSURL URLWithString:decodedURL]; - } + + if ([[urlPathString pathExtension] isEqualToString:@"url"]) + url = [NSURL urlFromIEURLFile:urlPathString]; + else if ([[urlPathString pathExtension] isEqualToString:@"webloc"]) + url = [NSURL urlFromWebloc:urlPathString]; + return url; } @@ -1675,55 +1672,4 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil]; } -// Reads the URL from a .webloc . Returns nil on failure. -+(NSString*)urlStringFromWebloc:(NSString*)inFile -{ - FSRef ref; - FSSpec spec; - NSString *ret = nil; - - if (inFile && !FSPathMakeRef((UInt8 *)[inFile fileSystemRepresentation], &ref, NULL) && !FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec, NULL)) { - short resRef; - - resRef = FSpOpenResFile(&spec, fsRdPerm); - - if (resRef != -1) { // Has resouce fork. - Handle urlResHandle; - - if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource with ID 256. - long size; - - size = GetMaxResourceSize(urlResHandle); - ret = [NSString stringWithCString:(char *)*urlResHandle length:size]; - } - - CloseResFile(resRef); - } - } - - return ret; -} - -// Reads the URL from a .url . Returns nil on failure. -+(NSString*)urlStringFromIEURLFile:(NSString*)inFile -{ - NSString *ret = nil; - - // Is this really an IE .url file? (Is this too strict?) - if (inFile) { - NSArray *contents = [[NSString stringWithContentsOfFile:inFile] componentsSeparatedByString:@"\r\n"]; - unsigned idx = [contents indexOfObject:@"[InternetShortcut]"]; - - if (idx != NSNotFound) { - NSString *urlline = [contents objectAtIndex:idx + 1]; - - if ([urlline hasPrefix:@"URL="]) { - ret = [urlline substringFromIndex:4]; - } - } - } - - return ret; -} - @end diff --git a/mozilla/camino/src/browser/BrowserTabView.mm b/mozilla/camino/src/browser/BrowserTabView.mm index 0c657c6da9e..b90c161ab33 100644 --- a/mozilla/camino/src/browser/BrowserTabView.mm +++ b/mozilla/camino/src/browser/BrowserTabView.mm @@ -431,40 +431,8 @@ } } return YES; - } // check for NSFilenamesPboardType next so we always handle multiple filenames when we should - else if ([pasteBoardTypes containsObject:NSFilenamesPboardType]) { - NSArray *files = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType]; - for (unsigned int i = 0; i < [files count]; i++) { - NSString *file = [files objectAtIndex:i]; - NSString *ext = [file pathExtension]; - NSString *urlString = nil; - - // Check whether the file is a .webloc, a .url, or some other kind of file. - if ([ext isEqualToString:@"webloc"]) // Webloc file - urlString = [MainController urlStringFromWebloc:file]; - else if ([ext isEqualToString:@"url"]) // IE URL file - urlString = [MainController urlStringFromIEURLFile:file]; - - // Use the filename if not a .webloc or .url file, or if either of the - // functions returns nil. - if (!urlString) - urlString = file; - - if (i == 0) { - // if we're over the content area, just load the first one - if (overContentArea) - return [self handleDropOnTab:overTabViewItem overContent:YES withURL:urlString]; - // otherwise load the first in the tab, and keep going - [self handleDropOnTab:overTabViewItem overContent:NO withURL:urlString]; - } - else { - // for subsequent items, make new tabs - [self handleDropOnTab:nil overContent:NO withURL:urlString]; - } - } - return YES; } - + return NO; } diff --git a/mozilla/camino/src/extensions/NSPasteboard+Utils.mm b/mozilla/camino/src/extensions/NSPasteboard+Utils.mm index d24fe1b1648..8d77f4d217f 100644 --- a/mozilla/camino/src/extensions/NSPasteboard+Utils.mm +++ b/mozilla/camino/src/extensions/NSPasteboard+Utils.mm @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #import "NSPasteboard+Utils.h" +#import "NSURL+Utils.h" NSString* const kCorePasteboardFlavorType_url = @"CorePasteboardFlavorType 0x75726C20"; // 'url ' url NSString* const kCorePasteboardFlavorType_urln = @"CorePasteboardFlavorType 0x75726C6E"; // 'urln' title @@ -132,6 +133,41 @@ NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; NSArray* urlAndTitleContainer = [self propertyListForType:kWebURLsWithTitlesPboardType]; *outUrls = [urlAndTitleContainer objectAtIndex:0]; *outTitles = [urlAndTitleContainer objectAtIndex:1]; + } else if ([types containsObject:NSFilenamesPboardType]) { + NSArray *files = [self propertyListForType:NSFilenamesPboardType]; + *outUrls = [NSMutableArray arrayWithCapacity:[files count]]; + *outTitles = [NSMutableArray arrayWithCapacity:[files count]]; + for ( unsigned int i = 0; i < [files count]; ++i ) { + NSString *file = [files objectAtIndex:i]; + NSString *ext = [file pathExtension]; + NSString *urlString = nil; + NSString *title = [NSString string]; + + // Check whether the file is a .webloc, a .url, or some other kind of file. + if ([ext isEqualToString:@"webloc"]) { + NSURL* urlFromWebloc = [NSURL urlFromWebloc:file]; + if (urlFromWebloc) { + urlString = [urlFromWebloc absoluteString]; + title = [[file lastPathComponent] stringByDeletingPathExtension]; + } + } else if ([ext isEqualToString:@"url"]) { + NSURL* urlFromIEURLFile = [NSURL urlFromIEURLFile:file]; + if (urlFromIEURLFile) { + urlString = [urlFromIEURLFile absoluteString]; + title = [[file lastPathComponent] stringByDeletingPathExtension]; + } + } + + // Use the filename if not a .webloc or .url file, or if either of the + // functions returns nil. + if (!urlString) { + urlString = file; + title = [file lastPathComponent]; + } + + [(NSMutableArray*) *outUrls addObject:urlString]; + [(NSMutableArray*) *outTitles addObject:title]; + } } else if ([types containsObject:NSURLPboardType]) { *outUrls = [NSArray arrayWithObject:[[NSURL URLFromPasteboard:self] absoluteString]]; if ([types containsObject:kCorePasteboardFlavorType_urld]) @@ -170,7 +206,8 @@ NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; { NSArray* types = [self types]; if ( [types containsObject:kWebURLsWithTitlesPboardType] - || [types containsObject:NSURLPboardType] ) + || [types containsObject:NSURLPboardType] + || [types containsObject:NSFilenamesPboardType] ) return YES; if ([types containsObject:NSStringPboardType]) { diff --git a/mozilla/camino/src/extensions/NSURL+Utils.h b/mozilla/camino/src/extensions/NSURL+Utils.h new file mode 100644 index 00000000000..ddfd6fd9ea1 --- /dev/null +++ b/mozilla/camino/src/extensions/NSURL+Utils.h @@ -0,0 +1,47 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Camino code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Josh Aas - josha@mac.com + * Nate Weaver (Wevah) - wevah@derailer.org + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#import + + +@interface NSURL (CaminoExtensions) + ++(NSURL*)urlFromWebloc:(NSString*)inFile; ++(NSURL*)urlFromIEURLFile:(NSString*)inFile; + +@end diff --git a/mozilla/camino/src/extensions/NSURL+Utils.m b/mozilla/camino/src/extensions/NSURL+Utils.m new file mode 100644 index 00000000000..b1d33eec8b5 --- /dev/null +++ b/mozilla/camino/src/extensions/NSURL+Utils.m @@ -0,0 +1,100 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Camino code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Josh Aas - josha@mac.com + * Nate Weaver (Wevah) - wevah@derailer.org + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#import "NSURL+Utils.h" + + +@implementation NSURL (CaminoExtensions) + +// +// Reads the URL from a .webloc file. +// Returns the URL, or nil on failure. ++(NSURL*)urlFromWebloc:(NSString*)inFile +{ + FSRef ref; + FSSpec spec; + NSURL *ret = nil; + + if (inFile && !FSPathMakeRef((UInt8 *)[inFile fileSystemRepresentation], &ref, NULL) && !FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec, NULL)) { + short resRef; + + resRef = FSpOpenResFile(&spec, fsRdPerm); + + if (resRef != -1) { // Has resouce fork. + Handle urlResHandle; + + if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource with ID 256. + long size; + + size = GetMaxResourceSize(urlResHandle); + ret = [NSURL URLWithString:[NSString stringWithCString:(char *)*urlResHandle length:size]]; + } + + CloseResFile(resRef); + } + } + + return ret; +} + +// +// Reads the URL from a .url file. +// Returns the URL or nil on failure. +// ++(NSURL*)urlFromIEURLFile:(NSString*)inFile +{ + NSURL *ret = nil; + + // Is this really an IE .url file? (Is this too strict?) + if (inFile) { + NSArray *contents = [[NSString stringWithContentsOfFile:inFile] componentsSeparatedByString:@"\r\n"]; + unsigned idx = [contents indexOfObject:@"[InternetShortcut]"]; + + if (idx != NSNotFound) { + NSString *urlline = [contents objectAtIndex:idx + 1]; + + if ([urlline hasPrefix:@"URL="]) { + ret = [NSURL URLWithString:[urlline substringFromIndex:4]]; + } + } + } + + return ret; +} + +@end