diff --git a/xpcom/io/nsILocalFileMac.h b/xpcom/io/nsILocalFileMac.h index 8ee5d4725cb6..c77328fb6e01 100644 --- a/xpcom/io/nsILocalFileMac.h +++ b/xpcom/io/nsILocalFileMac.h @@ -64,9 +64,9 @@ public: // we provide a way to initialize an nsLocalFile with one NS_IMETHOD InitWithFSSpec(const FSSpec *fileSpec) = 0; - // Init this filespec to point to an application which is sought by - // creator code. If this app is missing, this will fail. It will first - // look for running application with the given creator. + // Init this filespec to point to an application which is sought by + // creator code. If this app is missing, this will fail. It will first + // look for running application with the given creator. NS_IMETHOD InitFindingAppByCreatorCode(OSType aAppCreator) = 0; // In case we need to get the FSSpecs at the heart of an nsLocalFileMac @@ -85,11 +85,15 @@ public: NS_IMETHOD GetFileTypeAndCreator(OSType *type, OSType *creator) = 0; NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator) = 0; - // Methods for setting the file type from other means. Just setting the + // Method for setting the file type by suffix. Just setting the // type is probably enough. The creator is set to that of the current process // by default. Failure is likely on these methods - take it lightly. NS_IMETHOD SetFileTypeFromSuffix(const char *suffix) = 0; - NS_IMETHOD SetFileTypeFromMIMEType(const char *mimetype) = 0; + + // Method for setting the file type and creator by MIME type. Internet + // Config is consulted for the mapping of MIME type to the appropriate file + // type and creator pair. + NS_IMETHOD SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType) = 0; // Since Mac files can consist of both a data and resource fork we have a // method that will return the combined size of both forks rather than just the diff --git a/xpcom/io/nsLocalFileMac.cpp b/xpcom/io/nsLocalFileMac.cpp index 463cf5772191..95671850d67f 100644 --- a/xpcom/io/nsLocalFileMac.cpp +++ b/xpcom/io/nsLocalFileMac.cpp @@ -2822,24 +2822,30 @@ NS_IMETHODIMP nsLocalFile::SetFileTypeFromSuffix(const char *suffix) return SetOSTypeAndCreatorFromExtension(suffix); } -NS_IMETHODIMP nsLocalFile::SetFileTypeFromMIMEType(const char *mimetype) +NS_IMETHODIMP nsLocalFile::SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType) { - NS_ENSURE_ARG(mimetype); + NS_ENSURE_ARG(aMIMEType); nsresult rv; - NS_WITH_SERVICE(nsIInternetConfigService, icService, NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv); + nsCOMPtr icService(do_GetService + (NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) { nsCOMPtr mimeInfo; - rv = icService->FillInMIMEInfo(mimetype, nsnull, getter_AddRefs(mimeInfo)); + PRUint32 fileType = 'TEXT'; + PRUint32 fileCreator = nsILocalFileMac::CURRENT_PROCESS_CREATOR; + + rv = icService->FillInMIMEInfo(aMIMEType, + nsnull, getter_AddRefs(mimeInfo)); if (NS_SUCCEEDED(rv)) - { - PRUint32 osType; - rv = mimeInfo->GetMacType(&osType); - if (NS_SUCCEEDED(rv)) - mType = osType; - } + rv = mimeInfo->GetMacType(&fileType); + if (NS_SUCCEEDED(rv)) + rv = mimeInfo->GetMacCreator(&fileCreator); + if (NS_SUCCEEDED(rv)) + rv = SetFileTypeAndCreator(fileType, fileCreator); } + return rv; } diff --git a/xpcom/io/nsLocalFileMac.h b/xpcom/io/nsLocalFileMac.h index f9d3fcf785ee..f568fef9d590 100644 --- a/xpcom/io/nsLocalFileMac.h +++ b/xpcom/io/nsLocalFileMac.h @@ -72,7 +72,7 @@ public: NS_IMETHOD SetFileTypeAndCreator(OSType type, OSType creator); NS_IMETHOD SetFileTypeFromSuffix(const char *suffix); - NS_IMETHOD SetFileTypeFromMIMEType(const char *mimetype); + NS_IMETHOD SetFileTypeAndCreatorFromMIMEType(const char *aMIMEType); NS_IMETHOD GetFileSizeWithResFork(PRInt64 *aFileSize); diff --git a/xpfe/components/xfer/src/nsStreamXferOp.cpp b/xpfe/components/xfer/src/nsStreamXferOp.cpp index 3373ae9f7b5a..9ffdacac86cd 100644 --- a/xpfe/components/xfer/src/nsStreamXferOp.cpp +++ b/xpfe/components/xfer/src/nsStreamXferOp.cpp @@ -473,6 +473,25 @@ nsStreamXferOp::OnStopRequest( nsIRequest *request, } } +#ifdef XP_MAC + // Mac only: set the file type and creator based on Internet Config settings + + if (mInputChannel) + { + // Get the content type + nsXPIDLCString contentType; + rv = mInputChannel->GetContentType(getter_Copies(contentType)); + + if (NS_SUCCEEDED(rv)) + { + // Set the creator and file type on the output file + nsCOMPtr macFile = do_QueryInterface(mOutputFile); + if (contentType.get() && *contentType.get() && macFile) + macFile->SetFileTypeAndCreatorFromMIMEType(contentType.get()); + } + } +#endif // XP_MAC + // Unhook input/output channels (don't need to cancel 'em). mInputChannel = 0; mOutputTransport = 0;