fix regressions regarding dragging multiple weblocs from Finder. Move
webloc/IEweblocs to a separate NSURL extension (bug 155484) git-svn-id: svn://10.0.0.236/trunk@173152 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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]) {
|
||||
|
||||
47
mozilla/camino/src/extensions/NSURL+Utils.h
Normal file
47
mozilla/camino/src/extensions/NSURL+Utils.h
Normal file
@@ -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 <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface NSURL (CaminoExtensions)
|
||||
|
||||
+(NSURL*)urlFromWebloc:(NSString*)inFile;
|
||||
+(NSURL*)urlFromIEURLFile:(NSString*)inFile;
|
||||
|
||||
@end
|
||||
100
mozilla/camino/src/extensions/NSURL+Utils.m
Normal file
100
mozilla/camino/src/extensions/NSURL+Utils.m
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user