5 // Created by Chris Blumenberg on Thu Apr 11 2002.
6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved.
9 #import <WebKit/IFDownloadHandler.h>
10 #import <WebKit/IFWebDataSourcePrivate.h>
11 #import <WebKit/WebKitDebug.h>
13 @implementation IFDownloadHandler
15 - initWithDataSource:(IFWebDataSource *)dSource
17 dataSource = [dSource retain];
18 WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "Download started for: %s", [[[dSource inputURL] absoluteString] cString]);
27 - (void)downloadCompletedWithData:(NSData *)data;
29 NSString *path = [dataSource _downloadPath];
30 NSFileManager *fileManager;
32 // FIXME: Should probably not replace existing file
33 // FIXME: Should report error if there is one
34 fileManager = [NSFileManager defaultManager];
35 [fileManager createFileAtPath:path contents:data attributes:nil];
36 WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "Download complete. Saved to: %s", [path cString]);
38 // Send Finder notification
39 WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "Notifying Finder");
40 FNNotifyByPath((UInt8 *)[[path stringByDeletingLastPathComponent] UTF8String], kFNDirectoryModifiedMessage, kNilOptions);
42 if([dataSource contentPolicy] == IFContentPolicyOpenExternally){
43 [[self class] launchURL:[NSURL fileURLWithPath:path]];
47 + (void) launchURL:(NSURL *) url{
48 WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD,"Launching: %s", [[url absoluteString] cString]);
49 LSOpenCFURLRef((CFURLRef)url, NULL);