mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changeset f6c93f02146c, bug 571193.
This commit is contained in:
parent
6a6d3c8ee5
commit
5759fdff07
@ -1507,17 +1507,22 @@ XRE_GetBinaryPath(const char* argv0, nsILocalFile* *aResult)
|
||||
if (!appBundle)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
|
||||
if (!executableURL)
|
||||
CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
|
||||
if (!bundleURL)
|
||||
return NS_ERROR_FAILURE;
|
||||
rv = lfm->InitWithCFURL(executableURL);
|
||||
CFRelease(executableURL);
|
||||
|
||||
FSRef fileRef;
|
||||
if (!CFURLGetFSRef(bundleURL, &fileRef)) {
|
||||
CFRelease(bundleURL);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = lfm->InitWithFSRef(&fileRef);
|
||||
CFRelease(bundleURL);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// Callers expect a normalized path.
|
||||
lfm->Normalize();
|
||||
|
||||
#elif defined(XP_UNIX)
|
||||
struct stat fileStat;
|
||||
char exePath[MAXPATHLEN];
|
||||
|
@ -1,60 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
// vim:set ts=2 sts=2 sw=2 et cin:
|
||||
/* ***** 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 Mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 ***** */
|
||||
|
||||
// This namespace contains methods with Obj-C/Cocoa implementations. The header
|
||||
// is C/C++ for inclusion in C/C++-only files.
|
||||
|
||||
#ifndef CocoaFileUtils_h_
|
||||
#define CocoaFileUtils_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
namespace CocoaFileUtils {
|
||||
|
||||
nsresult RevealFileInFinder(CFURLRef url);
|
||||
nsresult OpenURL(CFURLRef url);
|
||||
nsresult GetFileCreatorCode(CFURLRef url, OSType *creatorCode);
|
||||
nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode);
|
||||
nsresult GetFileTypeCode(CFURLRef url, OSType *typeCode);
|
||||
nsresult SetFileTypeCode(CFURLRef url, OSType typeCode);
|
||||
|
||||
} // namespace CocoaFileUtils
|
||||
|
||||
#endif
|
@ -1,153 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
// vim:set ts=2 sts=2 sw=2 et cin:
|
||||
/* ***** 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 Mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 ***** */
|
||||
|
||||
#include "CocoaFileUtils.h"
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
namespace CocoaFileUtils {
|
||||
|
||||
nsresult RevealFileInFinder(CFURLRef url)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
BOOL success = [[NSWorkspace sharedWorkspace] selectFile:[(NSURL*)url path] inFileViewerRootedAtPath:@""];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
nsresult OpenURL(CFURLRef url)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
BOOL success = [[NSWorkspace sharedWorkspace] openURL:(NSURL*)url];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
nsresult GetFileCreatorCode(CFURLRef url, OSType *creatorCode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
NS_ENSURE_ARG_POINTER(creatorCode);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [[NSFileManager defaultManager] fileAttributesAtPath:[(NSURL*)url path] traverseLink:YES];
|
||||
NSNumber* creatorNum = (NSNumber*)[dict objectForKey:NSFileHFSCreatorCode];
|
||||
if (creatorNum) {
|
||||
*creatorCode = [creatorNum unsignedLongValue];
|
||||
rv = NS_OK;
|
||||
}
|
||||
[ap release];
|
||||
|
||||
return rv;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:creatorCode] forKey:NSFileHFSCreatorCode];
|
||||
BOOL success = [[NSFileManager defaultManager] setAttributes:dict ofItemAtPath:[(NSURL*)url path] error:nil];
|
||||
[ap release];
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
nsresult GetFileTypeCode(CFURLRef url, OSType *typeCode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
NS_ENSURE_ARG_POINTER(typeCode);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [[NSFileManager defaultManager] fileAttributesAtPath:[(NSURL*)url path] traverseLink:YES];
|
||||
NSNumber* typeNum = (NSNumber*)[dict objectForKey:NSFileHFSTypeCode];
|
||||
if (typeNum) {
|
||||
*typeCode = [typeNum unsignedLongValue];
|
||||
rv = NS_OK;
|
||||
}
|
||||
[ap release];
|
||||
|
||||
return rv;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
nsresult SetFileTypeCode(CFURLRef url, OSType typeCode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(url);
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:typeCode] forKey:NSFileHFSTypeCode];
|
||||
BOOL success = [[NSFileManager defaultManager] setAttributes:dict ofItemAtPath:[(NSURL*)url path] error:nil];
|
||||
[ap release];
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
} // namespace CocoaFileUtils
|
@ -77,12 +77,6 @@ CPPSRCS = \
|
||||
SpecialSystemDirectory.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
CMMSRCS += \
|
||||
CocoaFileUtils.mm \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifndef MOZ_NO_FAST_LOAD
|
||||
CPPSRCS += \
|
||||
nsFastLoadFile.cpp \
|
||||
@ -93,11 +87,15 @@ endif
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsLocalFileOS2.cpp
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CMMSRCS = nsLocalFileOSX.mm
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
CPPSRCS += nsLocalFileWin.cpp
|
||||
else
|
||||
CPPSRCS += nsLocalFileUnix.cpp
|
||||
endif # windows
|
||||
endif # mac
|
||||
endif # OS2
|
||||
|
||||
EXPORTS = \
|
||||
@ -120,11 +118,15 @@ EXPORTS = \
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
EXPORTS += nsLocalFileOS2.h
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
EXPORTS += nsLocalFileOSX.h
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
EXPORTS += nsLocalFileWin.h
|
||||
else
|
||||
EXPORTS += nsLocalFileUnix.h
|
||||
endif # windows
|
||||
endif # cocoa
|
||||
endif # os2
|
||||
|
||||
XPIDLSRCS = \
|
||||
|
@ -50,7 +50,7 @@
|
||||
[ptr] native FSRefPtr(FSRef);
|
||||
native CFURLRef(CFURLRef);
|
||||
|
||||
[scriptable, uuid(DE4C75BE-D42B-4F8C-95D9-284C83CF29A4)]
|
||||
[scriptable, uuid(86D685E5-EE3F-405A-B521-446529DB82E5)]
|
||||
interface nsILocalFileMac : nsILocalFile
|
||||
{
|
||||
/**
|
||||
@ -78,6 +78,18 @@ interface nsILocalFileMac : nsILocalFile
|
||||
*/
|
||||
[noscript] void initWithFSRef([const] in FSRefPtr aFSRef);
|
||||
|
||||
/**
|
||||
* initToAppWithCreatorCode
|
||||
*
|
||||
* Init this object to point to an application having the given
|
||||
* creator code. If this app is missing, this will fail. It will first
|
||||
* look for running application with the given creator.
|
||||
*
|
||||
* @param aAppCreator the signature of the app
|
||||
*
|
||||
*/
|
||||
[noscript] void initToAppWithCreatorCode(in OSType aAppCreator);
|
||||
|
||||
/**
|
||||
* getCFURL
|
||||
*
|
||||
@ -137,7 +149,12 @@ interface nsILocalFileMac : nsILocalFile
|
||||
*
|
||||
*/
|
||||
readonly attribute PRInt64 fileSizeWithResFork;
|
||||
|
||||
|
||||
/**
|
||||
* Use with SetFileType() to specify the signature of current process
|
||||
*/
|
||||
const unsigned long CURRENT_PROCESS_CREATOR = 0x8000000;
|
||||
|
||||
/**
|
||||
* fileType, creator
|
||||
*
|
||||
|
@ -72,6 +72,8 @@
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "nsLocalFileWin.h"
|
||||
#elif defined(XP_MACOSX)
|
||||
#include "nsLocalFileOSX.h"
|
||||
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
||||
#include "nsLocalFileUnix.h"
|
||||
#elif defined(XP_OS2)
|
||||
|
112
xpcom/io/nsLocalFileOSX.h
Normal file
112
xpcom/io/nsLocalFileOSX.h
Normal file
@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <ccarlen@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef nsLocalFileMac_h_
|
||||
#define nsLocalFileMac_h_
|
||||
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIHashable.h"
|
||||
|
||||
class nsDirEnumerator;
|
||||
|
||||
// Mac OS X 10.4 does not have stat64/lstat64
|
||||
#if defined(HAVE_STAT64) && defined(HAVE_LSTAT64) && (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4)
|
||||
#define STAT stat64
|
||||
#define LSTAT lstat64
|
||||
#else
|
||||
#define STAT stat
|
||||
#define LSTAT lstat
|
||||
#endif
|
||||
|
||||
// Mac OS X 10.4 does not have statvfs64
|
||||
#if defined(HAVE_STATVFS64) && (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4)
|
||||
#define STATVFS statvfs64
|
||||
#else
|
||||
#define STATVFS statvfs
|
||||
#endif
|
||||
|
||||
// The native charset of this implementation is UTF-8. The Unicode used by the
|
||||
// Mac OS file system is decomposed, so "Native" versions of these routines will
|
||||
// always use decomposed Unicode (NFD). Their "non-Native" counterparts are
|
||||
// intended to be simple wrappers which call the "Native" version and convert
|
||||
// between UTF-8 and UTF-16. All the work is done on the "Native" side except
|
||||
// for the conversion to NFC (composed Unicode) done in "non-Native" getters.
|
||||
|
||||
class NS_COM nsLocalFile : public nsILocalFileMac,
|
||||
public nsIHashable
|
||||
{
|
||||
friend class nsDirEnumerator;
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
|
||||
|
||||
nsLocalFile();
|
||||
|
||||
static nsresult nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFILE
|
||||
NS_DECL_NSILOCALFILE
|
||||
NS_DECL_NSILOCALFILEMAC
|
||||
NS_DECL_NSIHASHABLE
|
||||
|
||||
public:
|
||||
static void GlobalInit();
|
||||
static void GlobalShutdown();
|
||||
|
||||
private:
|
||||
~nsLocalFile();
|
||||
|
||||
protected:
|
||||
nsLocalFile(const nsLocalFile& src);
|
||||
nsresult SetBaseURL(CFURLRef aCFURLRef); // retains aCFURLRef
|
||||
nsresult GetFSRefInternal(FSRef& aFSRef);
|
||||
nsresult GetPathInternal(nsACString& path); // Returns path respecting mFollowLinks
|
||||
nsresult CopyInternal(nsIFile* newParentDir,
|
||||
const nsAString& newName,
|
||||
PRBool followLinks);
|
||||
nsresult FillStatBufferInternal(struct STAT *statBuffer);
|
||||
|
||||
protected:
|
||||
CFURLRef mBaseURL; // The FS object we represent
|
||||
char mPath[PATH_MAX]; // POSIX path, UTF-8, NULL terminated
|
||||
PRPackedBool mFollowLinks;
|
||||
};
|
||||
|
||||
#endif // nsLocalFileMac_h_
|
2278
xpcom/io/nsLocalFileOSX.mm
Normal file
2278
xpcom/io/nsLocalFileOSX.mm
Normal file
File diff suppressed because it is too large
Load Diff
@ -46,7 +46,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Implementation of nsIFile for "unixy" systems.
|
||||
* Implementation of nsIFile for ``Unixy'' systems.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -92,11 +92,6 @@
|
||||
#include "nsIGnomeVFSService.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
#include <Carbon/Carbon.h>
|
||||
#include "CocoaFileUtils.h"
|
||||
#endif
|
||||
|
||||
#if (MOZ_PLATFORM_MAEMO == 5)
|
||||
#include <glib.h>
|
||||
#include <hildon-uri.h>
|
||||
@ -265,18 +260,10 @@ nsLocalFile::nsLocalFile(const nsLocalFile& other)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile,
|
||||
nsILocalFileMac,
|
||||
nsILocalFile,
|
||||
nsIFile,
|
||||
nsIHashable)
|
||||
#else
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsLocalFile,
|
||||
nsILocalFile,
|
||||
nsIFile,
|
||||
nsILocalFile,
|
||||
nsIHashable)
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
nsLocalFile::nsLocalFileConstructor(nsISupports *outer,
|
||||
@ -1300,7 +1287,7 @@ nsLocalFile::GetParent(nsIFile **aParent)
|
||||
{
|
||||
CHECK_mPath();
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
*aParent = nsnull;
|
||||
*aParent = nsnull;
|
||||
|
||||
// if '/' we are at the top of the volume, return null
|
||||
if (mPath.Equals("/"))
|
||||
@ -1312,7 +1299,7 @@ nsLocalFile::GetParent(nsIFile **aParent)
|
||||
|
||||
// find the last significant slash in buffer
|
||||
slashp = strrchr(buffer, '/');
|
||||
NS_ASSERTION(slashp, "non-canonical path?");
|
||||
NS_ASSERTION(slashp, "non-canonical mPath?");
|
||||
if (!slashp)
|
||||
return NS_ERROR_FILE_INVALID_PATH;
|
||||
|
||||
@ -1653,6 +1640,7 @@ nsLocalFile::GetNativeTarget(nsACString &_retval)
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* attribute PRBool followLinks; */
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFollowLinks(PRBool *aFollowLinks)
|
||||
{
|
||||
@ -1785,14 +1773,6 @@ nsLocalFile::Reveal()
|
||||
else
|
||||
return gnomevfs->ShowURIForInput(dirPath);
|
||||
}
|
||||
#elif defined(XP_MACOSX)
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::RevealFileInFinder(url);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
#else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
@ -1843,14 +1823,6 @@ nsLocalFile::Launch()
|
||||
fileUri.Append(mPath);
|
||||
mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
|
||||
return bridge->OpenUriExternal(fileUri, type) ? NS_OK : NS_ERROR_FAILURE;
|
||||
#elif defined(XP_MACOSX)
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::OpenURL(url);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
#else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
@ -1865,8 +1837,6 @@ NS_NewNativeLocalFile(const nsACString &path, PRBool followSymlinks, nsILocalFil
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(file);
|
||||
|
||||
file->SetFollowLinks(followSymlinks);
|
||||
|
||||
if (!path.IsEmpty()) {
|
||||
nsresult rv = file->InitWithNativePath(path);
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -2004,429 +1974,3 @@ void
|
||||
nsLocalFile::GlobalShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
// nsILocalFileMac
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
|
||||
static nsresult MacErrorMapper(OSErr inErr)
|
||||
{
|
||||
nsresult outErr;
|
||||
|
||||
switch (inErr)
|
||||
{
|
||||
case noErr:
|
||||
outErr = NS_OK;
|
||||
break;
|
||||
|
||||
case fnfErr:
|
||||
case afpObjectNotFound:
|
||||
case afpDirNotFound:
|
||||
outErr = NS_ERROR_FILE_NOT_FOUND;
|
||||
break;
|
||||
|
||||
case dupFNErr:
|
||||
case afpObjectExists:
|
||||
outErr = NS_ERROR_FILE_ALREADY_EXISTS;
|
||||
break;
|
||||
|
||||
case dskFulErr:
|
||||
case afpDiskFull:
|
||||
outErr = NS_ERROR_FILE_DISK_FULL;
|
||||
break;
|
||||
|
||||
case fLckdErr:
|
||||
case afpVolLocked:
|
||||
outErr = NS_ERROR_FILE_IS_LOCKED;
|
||||
break;
|
||||
|
||||
case afpAccessDenied:
|
||||
outErr = NS_ERROR_FILE_ACCESS_DENIED;
|
||||
break;
|
||||
|
||||
case afpDirNotEmpty:
|
||||
outErr = NS_ERROR_FILE_DIR_NOT_EMPTY;
|
||||
break;
|
||||
|
||||
// Can't find good map for some
|
||||
case bdNamErr:
|
||||
outErr = NS_ERROR_FAILURE;
|
||||
break;
|
||||
|
||||
default:
|
||||
outErr = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
return outErr;
|
||||
}
|
||||
|
||||
static nsresult CFStringReftoUTF8(CFStringRef aInStrRef, nsACString& aOutStr)
|
||||
{
|
||||
// first see if the conversion would succeed and find the length of the result
|
||||
CFIndex usedBufLen, inStrLen = ::CFStringGetLength(aInStrRef);
|
||||
CFIndex charsConverted = ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen),
|
||||
kCFStringEncodingUTF8, 0, PR_FALSE,
|
||||
NULL, 0, &usedBufLen);
|
||||
if (charsConverted == inStrLen) {
|
||||
// all characters converted, do the actual conversion
|
||||
aOutStr.SetLength(usedBufLen);
|
||||
if (aOutStr.Length() != (unsigned int)usedBufLen)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
UInt8 *buffer = (UInt8*)aOutStr.BeginWriting();
|
||||
::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen), kCFStringEncodingUTF8,
|
||||
0, false, buffer, usedBufLen, &usedBufLen);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::InitWithCFURL(CFURLRef aCFURL)
|
||||
{
|
||||
UInt8 path[PATH_MAX];
|
||||
if (::CFURLGetFileSystemRepresentation(aCFURL, false, path, PATH_MAX)) {
|
||||
nsDependentCString nativePath((char*)path);
|
||||
return InitWithNativePath(nativePath);
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::InitWithFSRef(const FSRef *aFSRef)
|
||||
{
|
||||
NS_ENSURE_ARG(aFSRef);
|
||||
|
||||
CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef);
|
||||
if (newURLRef) {
|
||||
nsresult rv = InitWithCFURL(newURLRef);
|
||||
::CFRelease(newURLRef);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetCFURL(CFURLRef *_retval)
|
||||
{
|
||||
CHECK_mPath();
|
||||
|
||||
PRBool isDir;
|
||||
IsDirectory(&isDir);
|
||||
*_retval = ::CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
|
||||
(UInt8*)mPath.get(),
|
||||
mPath.Length(),
|
||||
isDir);
|
||||
|
||||
return (*_retval ? NS_OK : NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFSRef(FSRef *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
CFURLRef url = NULL;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
if (::CFURLGetFSRef(url, _retval)) {
|
||||
rv = NS_OK;
|
||||
}
|
||||
::CFRelease(url);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFSSpec(FSSpec *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
FSRef fsRef;
|
||||
nsresult rv = GetFSRef(&fsRef);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNone, nsnull, nsnull, _retval, nsnull);
|
||||
return MacErrorMapper(err);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFileSizeWithResFork(PRInt64 *aFileSizeWithResFork)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFileSizeWithResFork);
|
||||
|
||||
FSRef fsRef;
|
||||
nsresult rv = GetFSRef(&fsRef);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
FSCatalogInfo catalogInfo;
|
||||
OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes + kFSCatInfoRsrcSizes,
|
||||
&catalogInfo, nsnull, nsnull, nsnull);
|
||||
if (err != noErr)
|
||||
return MacErrorMapper(err);
|
||||
|
||||
*aFileSizeWithResFork = catalogInfo.dataLogicalSize + catalogInfo.rsrcLogicalSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFileType(OSType *aFileType)
|
||||
{
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::GetFileTypeCode(url, aFileType);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::SetFileType(OSType aFileType)
|
||||
{
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::SetFileTypeCode(url, aFileType);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetFileCreator(OSType *aFileCreator)
|
||||
{
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::GetFileCreatorCode(url, aFileCreator);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::SetFileCreator(OSType aFileCreator)
|
||||
{
|
||||
CFURLRef url;
|
||||
if (NS_SUCCEEDED(GetCFURL(&url))) {
|
||||
nsresult rv = CocoaFileUtils::SetFileCreatorCode(url, aFileCreator);
|
||||
::CFRelease(url);
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::LaunchWithDoc(nsILocalFile *aDocToLoad, PRBool aLaunchInBackground)
|
||||
{
|
||||
PRBool isExecutable;
|
||||
nsresult rv = IsExecutable(&isExecutable);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (!isExecutable)
|
||||
return NS_ERROR_FILE_EXECUTION_FAILED;
|
||||
|
||||
FSRef appFSRef, docFSRef;
|
||||
rv = GetFSRef(&appFSRef);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (aDocToLoad) {
|
||||
nsCOMPtr<nsILocalFileMac> macDoc = do_QueryInterface(aDocToLoad);
|
||||
rv = macDoc->GetFSRef(&docFSRef);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
|
||||
LSLaunchFSRefSpec thelaunchSpec;
|
||||
|
||||
if (aLaunchInBackground)
|
||||
theLaunchFlags |= kLSLaunchDontSwitch;
|
||||
memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
|
||||
|
||||
thelaunchSpec.appRef = &appFSRef;
|
||||
if (aDocToLoad) {
|
||||
thelaunchSpec.numDocs = 1;
|
||||
thelaunchSpec.itemRefs = &docFSRef;
|
||||
}
|
||||
thelaunchSpec.launchFlags = theLaunchFlags;
|
||||
|
||||
OSErr err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
|
||||
if (err != noErr)
|
||||
return MacErrorMapper(err);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::OpenDocWithApp(nsILocalFile *aAppToOpenWith, PRBool aLaunchInBackground)
|
||||
{
|
||||
FSRef docFSRef;
|
||||
nsresult rv = GetFSRef(&docFSRef);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!aAppToOpenWith) {
|
||||
OSErr err = ::LSOpenFSRef(&docFSRef, NULL);
|
||||
return MacErrorMapper(err);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILocalFileMac> appFileMac = do_QueryInterface(aAppToOpenWith, &rv);
|
||||
if (!appFileMac)
|
||||
return rv;
|
||||
|
||||
PRBool isExecutable;
|
||||
rv = appFileMac->IsExecutable(&isExecutable);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (!isExecutable)
|
||||
return NS_ERROR_FILE_EXECUTION_FAILED;
|
||||
|
||||
FSRef appFSRef;
|
||||
rv = appFileMac->GetFSRef(&appFSRef);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
LSLaunchFlags theLaunchFlags = kLSLaunchDefaults;
|
||||
LSLaunchFSRefSpec thelaunchSpec;
|
||||
|
||||
if (aLaunchInBackground)
|
||||
theLaunchFlags |= kLSLaunchDontSwitch;
|
||||
memset(&thelaunchSpec, 0, sizeof(LSLaunchFSRefSpec));
|
||||
|
||||
thelaunchSpec.appRef = &appFSRef;
|
||||
thelaunchSpec.numDocs = 1;
|
||||
thelaunchSpec.itemRefs = &docFSRef;
|
||||
thelaunchSpec.launchFlags = theLaunchFlags;
|
||||
|
||||
OSErr err = ::LSOpenFromRefSpec(&thelaunchSpec, NULL);
|
||||
if (err != noErr)
|
||||
return MacErrorMapper(err);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::IsPackage(PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(_retval);
|
||||
*_retval = PR_FALSE;
|
||||
|
||||
CFURLRef url;
|
||||
nsresult rv = GetCFURL(&url);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
CFBundleRef bundle = ::CFBundleCreate(kCFAllocatorDefault, url);
|
||||
if (bundle) {
|
||||
*_retval = PR_TRUE;
|
||||
::CFRelease(bundle);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetBundleDisplayName(nsAString& outBundleName)
|
||||
{
|
||||
PRBool isPackage = PR_FALSE;
|
||||
nsresult rv = IsPackage(&isPackage);
|
||||
if (NS_FAILED(rv) || !isPackage)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString name;
|
||||
rv = GetLeafName(name);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt32 length = name.Length();
|
||||
if (Substring(name, length - 4, length).EqualsLiteral(".app")) {
|
||||
// 4 characters in ".app"
|
||||
outBundleName = Substring(name, 0, length - 4);
|
||||
}
|
||||
else {
|
||||
outBundleName = name;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetBundleIdentifier(nsACString& outBundleIdentifier)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
CFURLRef urlRef;
|
||||
if (NS_SUCCEEDED(GetCFURL(&urlRef))) {
|
||||
CFBundleRef bundle = ::CFBundleCreate(NULL, urlRef);
|
||||
if (bundle) {
|
||||
CFStringRef bundleIdentifier = ::CFBundleGetIdentifier(bundle);
|
||||
if (bundleIdentifier)
|
||||
rv = CFStringReftoUTF8(bundleIdentifier, outBundleIdentifier);
|
||||
::CFRelease(bundle);
|
||||
}
|
||||
::CFRelease(urlRef);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::InitWithFile(nsILocalFile *aFile)
|
||||
{
|
||||
NS_ENSURE_ARG(aFile);
|
||||
|
||||
nsCAutoString nativePath;
|
||||
nsresult rv = aFile->GetNativePath(nativePath);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return InitWithNativePath(nativePath);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowLinks, nsILocalFileMac** result)
|
||||
{
|
||||
nsLocalFile* file = new nsLocalFile();
|
||||
if (file == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(file);
|
||||
|
||||
file->SetFollowLinks(aFollowLinks);
|
||||
|
||||
nsresult rv = file->InitWithFSRef(aFSRef);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(file);
|
||||
return rv;
|
||||
}
|
||||
*result = file;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewLocalFileWithCFURL(const CFURLRef aURL, PRBool aFollowLinks, nsILocalFileMac** result)
|
||||
{
|
||||
nsLocalFile* file = new nsLocalFile();
|
||||
if (!file)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(file);
|
||||
|
||||
file->SetFollowLinks(aFollowLinks);
|
||||
|
||||
nsresult rv = file->InitWithCFURL(aURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(file);
|
||||
return rv;
|
||||
}
|
||||
*result = file;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -53,9 +53,6 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIHashable.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#ifdef XP_MACOSX
|
||||
#include "nsILocalFileMac.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* we need these for statfs()
|
||||
@ -104,12 +101,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
class NS_COM nsLocalFile :
|
||||
#ifdef XP_MACOSX
|
||||
public nsILocalFileMac,
|
||||
#else
|
||||
public nsILocalFile,
|
||||
#endif
|
||||
class NS_COM nsLocalFile : public nsILocalFile,
|
||||
public nsIHashable
|
||||
{
|
||||
public:
|
||||
@ -119,12 +111,16 @@ public:
|
||||
|
||||
static nsresult nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFile
|
||||
NS_DECL_NSIFILE
|
||||
|
||||
// nsILocalFile
|
||||
NS_DECL_NSILOCALFILE
|
||||
#ifdef XP_MACOSX
|
||||
NS_DECL_NSILOCALFILEMAC
|
||||
#endif
|
||||
|
||||
// nsIHashable
|
||||
NS_DECL_NSIHASHABLE
|
||||
|
||||
public:
|
||||
@ -136,8 +132,8 @@ private:
|
||||
~nsLocalFile() {}
|
||||
|
||||
protected:
|
||||
// This stat cache holds the *last stat* - it does not invalidate.
|
||||
// Call "FillStatCache" whenever you want to stat our file.
|
||||
// This stat cache holds the *last stat* - it does not invalidate.
|
||||
// Call "FillStatCache" whenever you want to stat our file.
|
||||
struct STAT mCachedStat;
|
||||
nsCString mPath;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user