Bug 1776893 - Replace do_CreateInstance for nsIFile with NS_NewLocalFile (part 2) r=emilio,necko-reviewers,win-reviewers,handyman,valentin
Differential Revision: https://phabricator.services.mozilla.com/D227297
This commit is contained in:
@@ -346,10 +346,8 @@ UploadLastDir::ContentPrefCallback::HandleCompletion(uint16_t aReason) {
|
||||
}
|
||||
|
||||
if (!prefStr.IsEmpty()) {
|
||||
localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
if (localFile && NS_WARN_IF(NS_FAILED(localFile->InitWithPath(prefStr)))) {
|
||||
localFile = nullptr;
|
||||
}
|
||||
nsresult rv = NS_NewLocalFile(prefStr, getter_AddRefs(localFile));
|
||||
(void)NS_WARN_IF(NS_FAILED(rv));
|
||||
}
|
||||
|
||||
if (localFile) {
|
||||
|
||||
@@ -261,9 +261,9 @@ mozilla::ipc::IPCResult FilePickerParent::RecvOpen(
|
||||
mFilePicker->SetCapture(aCapture);
|
||||
|
||||
if (!aDisplayDirectory.IsEmpty()) {
|
||||
nsCOMPtr<nsIFile> localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
if (localFile) {
|
||||
localFile->InitWithPath(aDisplayDirectory);
|
||||
nsCOMPtr<nsIFile> localFile;
|
||||
if (NS_SUCCEEDED(
|
||||
NS_NewLocalFile(aDisplayDirectory, getter_AddRefs(localFile)))) {
|
||||
mFilePicker->SetDisplayDirectory(localFile);
|
||||
}
|
||||
} else if (!aDisplaySpecialDirectory.IsEmpty()) {
|
||||
|
||||
@@ -6351,13 +6351,9 @@ nsresult QuotaManager::EnsureTemporaryStorageIsInitializedInternal() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
QM_TRY_INSPECT(
|
||||
const auto& storageDir,
|
||||
MOZ_TO_RESULT_GET_TYPED(nsCOMPtr<nsIFile>,
|
||||
MOZ_SELECT_OVERLOAD(do_CreateInstance),
|
||||
NS_LOCAL_FILE_CONTRACTID));
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(storageDir->InitWithPath(GetStoragePath())));
|
||||
nsCOMPtr<nsIFile> storageDir;
|
||||
QM_TRY(MOZ_TO_RESULT(
|
||||
NS_NewLocalFile(GetStoragePath(), getter_AddRefs(storageDir))));
|
||||
|
||||
// The storage directory must exist before calling GetTemporaryStorageLimit.
|
||||
QM_TRY_INSPECT(const bool& created, EnsureDirectory(*storageDir));
|
||||
|
||||
@@ -214,12 +214,7 @@ nsresult StorageDBThread::Init(const nsString& aProfilePath) {
|
||||
profilePath = aProfilePath;
|
||||
}
|
||||
|
||||
mDatabaseFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = mDatabaseFile->InitWithPath(profilePath);
|
||||
rv = NS_NewLocalFile(profilePath, getter_AddRefs(mDatabaseFile));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,15 @@ using namespace mozilla;
|
||||
|
||||
static already_AddRefed<nsIURI> FileToURI(const char* aFilename,
|
||||
nsresult* aRv = 0) {
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, aRv));
|
||||
NS_ENSURE_TRUE(lf, nullptr);
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
// XXX Handle relative paths somehow.
|
||||
lf->InitWithNativePath(nsDependentCString(aFilename));
|
||||
nsresult rv =
|
||||
NS_NewNativeLocalFile(nsDependentCString(aFilename), getter_AddRefs(lf));
|
||||
|
||||
nsIURI* uri = nullptr;
|
||||
nsresult rv = NS_NewFileURI(&uri, lf);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_NewFileURI(&uri, lf);
|
||||
}
|
||||
if (aRv) *aRv = rv;
|
||||
return uri;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsProxyRelease.h"
|
||||
@@ -2523,14 +2524,11 @@ nsPrefBranch::GetComplexValue(const char* aPrefName, const nsIID& aType,
|
||||
if (aType.Equals(NS_GET_IID(nsIFile))) {
|
||||
ENSURE_PARENT_PROCESS("GetComplexValue(nsIFile)", aPrefName);
|
||||
|
||||
nsCOMPtr<nsIFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
|
||||
nsCOMPtr<nsIFile> file = new nsLocalFile();
|
||||
rv = file->SetPersistentDescriptor(utf8String);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = file->SetPersistentDescriptor(utf8String);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
file.forget(reinterpret_cast<nsIFile**>(aRetVal));
|
||||
return NS_OK;
|
||||
}
|
||||
file.forget(reinterpret_cast<nsIFile**>(aRetVal));
|
||||
return NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -56,12 +56,6 @@ nsresult net_GetFileFromURLSpec(const nsACString& aURL, nsIFile** result) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> localFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Only nsIFile supported right now");
|
||||
return rv;
|
||||
}
|
||||
|
||||
const nsACString* specPtr;
|
||||
|
||||
nsAutoCString buf;
|
||||
@@ -95,14 +89,19 @@ nsresult net_GetFileFromURLSpec(const nsACString& aURL, nsIFile** result) {
|
||||
// remove leading '\'
|
||||
if (path.CharAt(0) == '\\') path.Cut(0, 1);
|
||||
|
||||
if (IsUtf8(path)) rv = localFile->InitWithPath(NS_ConvertUTF8toUTF16(path));
|
||||
nsCOMPtr<nsIFile> localFile;
|
||||
if (IsUtf8(path)) {
|
||||
rv =
|
||||
NS_NewLocalFile(NS_ConvertUTF8toUTF16(path), getter_AddRefs(localFile));
|
||||
}
|
||||
// XXX In rare cases, a valid UTF-8 string can be valid as a native
|
||||
// encoding (e.g. 0xC5 0x83 is valid both as UTF-8 and Windows-125x).
|
||||
// However, the chance is very low that a meaningful word in a legacy
|
||||
// encoding is valid as UTF-8.
|
||||
else
|
||||
else {
|
||||
// if path is not in UTF-8, assume it is encoded in the native charset
|
||||
rv = localFile->InitWithNativePath(path);
|
||||
rv = NS_NewNativeLocalFile(path, getter_AddRefs(localFile));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
@@ -707,13 +707,9 @@ static nsresult GetNSS3Directory(nsCString& result) {
|
||||
MOZ_LOG(gPIPNSSLog, LogLevel::Debug, ("nss not loaded?"));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsCOMPtr<nsIFile> nss3File(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
if (!nss3File) {
|
||||
MOZ_LOG(gPIPNSSLog, LogLevel::Debug, ("couldn't create a file?"));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsAutoCString nss3PathAsString(nss3Path.get());
|
||||
nsresult rv = nss3File->InitWithNativePath(nss3PathAsString);
|
||||
nsCOMPtr<nsIFile> nss3File;
|
||||
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(nss3Path.get()),
|
||||
getter_AddRefs(nss3File));
|
||||
if (NS_FAILED(rv)) {
|
||||
MOZ_LOG(gPIPNSSLog, LogLevel::Debug,
|
||||
("couldn't initialize file with path '%s'", nss3Path.get()));
|
||||
|
||||
@@ -173,11 +173,8 @@ static void CachePathsFromFileInternal(FileCacheT& aCache,
|
||||
const nsACString& aCwd,
|
||||
const nsACString& aPath) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> ldconfig(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
rv = ldconfig->InitWithNativePath(aPath);
|
||||
nsCOMPtr<nsIFile> ldconfig;
|
||||
rv = NS_NewNativeLocalFile(aPath, getter_AddRefs(ldconfig));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
@@ -255,12 +252,8 @@ static void CachePathsFromFileInternal(FileCacheT& aCache,
|
||||
static void CachePathsFromFile(FileCacheT& aCache, const nsACString& aPath) {
|
||||
// Find the new base path where that file sits in.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> includeFile(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
rv = includeFile->InitWithNativePath(aPath);
|
||||
nsCOMPtr<nsIFile> includeFile;
|
||||
rv = NS_NewNativeLocalFile(aPath, getter_AddRefs(includeFile));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,10 +43,8 @@ struct VirtualTableCursor : public VirtualTableCursorBase {
|
||||
};
|
||||
|
||||
nsresult VirtualTableCursor::Init(const nsAString& aPath) {
|
||||
nsCOMPtr<nsIFile> directory = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(directory, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult rv = directory->InitWithPath(aPath);
|
||||
nsCOMPtr<nsIFile> directory;
|
||||
nsresult rv = (NS_NewLocalFile(aPath, getter_AddRefs(directory)));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = directory->GetPath(mDirectoryPath);
|
||||
|
||||
@@ -184,24 +184,12 @@ nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile** aResult) {
|
||||
// the dir from which we were started was deleted before we started,
|
||||
#if defined(XP_UNIX)
|
||||
if (aArgument.First() == '/') {
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsresult rv = lf->InitWithPath(aArgument);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
lf.forget(aResult);
|
||||
return NS_OK;
|
||||
return NS_NewLocalFile(aArgument, aResult);
|
||||
}
|
||||
#elif defined(XP_WIN)
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Just try creating the file with the absolute path; if it fails,
|
||||
// we'll keep going and try it as a relative path.
|
||||
if (NS_SUCCEEDED(lf->InitWithPath(aArgument))) {
|
||||
lf.forget(aResult);
|
||||
if (NS_SUCCEEDED(NS_NewLocalFile(aArgument, aResult))) {
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -211,25 +199,21 @@ nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile** aResult) {
|
||||
|
||||
nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
nsIFile** aResult) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!mWorkingDir) {
|
||||
*aResult = nullptr;
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// This is some seriously screwed-up code. nsIFile.appendRelativeNativePath
|
||||
// explicitly does not accept .. or . path parts, but that is exactly what we
|
||||
// need here. So we hack around it.
|
||||
|
||||
nsresult rv;
|
||||
|
||||
#if defined(MOZ_WIDGET_COCOA)
|
||||
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mWorkingDir));
|
||||
NS_ENSURE_TRUE(lfm, NS_ERROR_NO_INTERFACE);
|
||||
|
||||
nsCOMPtr<nsILocalFileMac> newfile(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(newfile, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
CFURLRef baseurl;
|
||||
rv = lfm->GetCFURL(&baseurl);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -242,7 +226,8 @@ nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
|
||||
CFRelease(baseurl);
|
||||
|
||||
rv = newfile->InitWithCFURL(newurl);
|
||||
nsCOMPtr<nsILocalFileMac> newfile;
|
||||
rv = NS_NewLocalFileWithCFURL(newurl, getter_AddRefs(newfile));
|
||||
CFRelease(newurl);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -250,9 +235,6 @@ nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
return NS_OK;
|
||||
|
||||
#elif defined(XP_UNIX)
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsAutoCString nativeArg;
|
||||
NS_CopyUnicodeToNative(aArgument, nativeArg);
|
||||
|
||||
@@ -262,8 +244,8 @@ nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
newpath.Append('/');
|
||||
newpath.Append(nativeArg);
|
||||
|
||||
rv = lf->InitWithNativePath(newpath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
MOZ_TRY(NS_NewNativeLocalFile(newpath, getter_AddRefs(lf)));
|
||||
|
||||
rv = lf->Normalize();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -272,9 +254,6 @@ nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
return NS_OK;
|
||||
|
||||
#elif defined(XP_WIN)
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// This is a relative path. We use string magic
|
||||
// and win32 _fullpath. Note that paths of the form "\Relative\To\CurDrive"
|
||||
// are going to fail, and I haven't figured out a way to work around this
|
||||
@@ -290,10 +269,7 @@ nsresult nsCommandLine::ResolveRelativeFile(const nsAString& aArgument,
|
||||
WCHAR pathBuf[MAX_PATH];
|
||||
if (!_wfullpath(pathBuf, fullPath.get(), MAX_PATH)) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = lf->InitWithPath(nsDependentString(pathBuf));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
lf.forget(aResult);
|
||||
return NS_OK;
|
||||
return NS_NewLocalFile(nsDependentString(pathBuf), aResult);
|
||||
|
||||
#else
|
||||
# error Need platform-specific logic here.
|
||||
@@ -315,8 +291,8 @@ nsCommandLine::ResolveURI(const nsAString& aArgument, nsIURI** aResult) {
|
||||
io->NewFileURI(mWorkingDir, getter_AddRefs(workingDirURI));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
rv = lf->InitWithPath(aArgument);
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
rv = NS_NewLocalFile(aArgument, getter_AddRefs(lf));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
lf->Normalize();
|
||||
nsAutoCString url;
|
||||
|
||||
@@ -2984,16 +2984,17 @@ static bool GetPendingDir(nsIFile** dir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> pending = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
if (!pending) {
|
||||
NS_WARNING("Can't set up pending directory during shutdown.");
|
||||
nsCOMPtr<nsIFile> pending;
|
||||
#ifdef XP_WIN
|
||||
nsresult rv = NS_NewLocalFile(nsDependentString(pendingDirectory.c_str()),
|
||||
getter_AddRefs(pending));
|
||||
#else
|
||||
nsresult rv = NS_NewNativeLocalFile(
|
||||
nsDependentCString(pendingDirectory.c_str()), getter_AddRefs(pending));
|
||||
#endif
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
#ifdef XP_WIN
|
||||
pending->InitWithPath(nsDependentString(pendingDirectory.c_str()));
|
||||
#else
|
||||
pending->InitWithNativePath(nsDependentCString(pendingDirectory.c_str()));
|
||||
#endif
|
||||
pending.swap(*dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,12 +42,11 @@ class BuildIDReader : public ::testing::Test {
|
||||
public:
|
||||
nsresult getLib(const nsString& lib, nsAutoString& val) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> file
|
||||
nsCOMPtr<nsIFile> file;
|
||||
#if defined(ANDROID)
|
||||
= do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
rv = file->InitWithPath(u"/data/local/tmp/test_root/"_ns);
|
||||
rv =
|
||||
NS_NewLocalFile(u"/data/local/tmp/test_root/"_ns, getter_AddRefs(file));
|
||||
#else
|
||||
;
|
||||
rv = NS_GetSpecialDirectory(NS_GRE_BIN_DIR, getter_AddRefs(file));
|
||||
#endif
|
||||
if (!NS_SUCCEEDED(rv)) {
|
||||
|
||||
@@ -23,10 +23,9 @@ TEST(ProfileLock, RetryLock)
|
||||
nsProfileLock myLock;
|
||||
nsProfileLock myLock2;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> dir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
ASSERT_EQ(NS_SUCCEEDED(rv), true);
|
||||
|
||||
rv = dir->InitWithNativePath(nsCString(tmpdir));
|
||||
nsCOMPtr<nsIFile> dir;
|
||||
rv = NS_NewNativeLocalFile(nsCString(tmpdir), getter_AddRefs(dir));
|
||||
ASSERT_EQ(NS_SUCCEEDED(rv), true);
|
||||
|
||||
int eventfd_fd = eventfd(0, 0);
|
||||
|
||||
@@ -192,11 +192,6 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(
|
||||
const char16_t* aPlatformAppPath, nsIFile** aFile) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFileMac> localFile(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
CFURLRef pathAsCFURL;
|
||||
CFStringRef pathAsCFString = ::CFStringCreateWithCharacters(
|
||||
NULL, reinterpret_cast<const UniChar*>(aPlatformAppPath),
|
||||
@@ -231,7 +226,9 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(
|
||||
}
|
||||
}
|
||||
|
||||
rv = localFile->InitWithCFURL(pathAsCFURL);
|
||||
nsCOMPtr<nsILocalFileMac> localFile;
|
||||
nsresult rv =
|
||||
NS_NewLocalFileWithCFURL(pathAsCFURL, getter_AddRefs(localFile));
|
||||
::CFRelease(pathAsCFString);
|
||||
::CFRelease(pathAsCFURL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -495,44 +492,31 @@ nsresult nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
|
||||
if (typeAppIsDefault || extAppIsDefault) {
|
||||
if (haveAppForExt) mimeInfoMac->AppendExtension(aFileExt);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFileMac> app(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
[localPool release];
|
||||
return rv;
|
||||
}
|
||||
const FSRef* appFSRef = typeAppIsDefault ? &typeAppFSRef : &extAppFSRef;
|
||||
nsCOMPtr<nsILocalFileMac> app;
|
||||
if (NS_SUCCEEDED(NS_NewLocalFileWithFSRef(appFSRef, getter_AddRefs(app)))) {
|
||||
mimeInfoMac->SetDefaultApplication(app);
|
||||
|
||||
CFStringRef cfAppName = NULL;
|
||||
if (typeAppIsDefault) {
|
||||
app->InitWithFSRef(&typeAppFSRef);
|
||||
::LSCopyItemAttribute((const FSRef*)&typeAppFSRef, kLSRolesAll,
|
||||
kLSItemDisplayName, (CFTypeRef*)&cfAppName);
|
||||
} else {
|
||||
app->InitWithFSRef(&extAppFSRef);
|
||||
::LSCopyItemAttribute((const FSRef*)&extAppFSRef, kLSRolesAll,
|
||||
kLSItemDisplayName, (CFTypeRef*)&cfAppName);
|
||||
CFStringRef cfAppName = NULL;
|
||||
::LSCopyItemAttribute(appFSRef, kLSRolesAll, kLSItemDisplayName,
|
||||
(CFTypeRef*)&cfAppName);
|
||||
if (cfAppName) {
|
||||
AutoTArray<UniChar, 255> buffer;
|
||||
CFIndex appNameLength = ::CFStringGetLength(cfAppName);
|
||||
buffer.SetLength(appNameLength);
|
||||
::CFStringGetCharacters(cfAppName, CFRangeMake(0, appNameLength),
|
||||
buffer.Elements());
|
||||
nsAutoString appName;
|
||||
appName.Assign(reinterpret_cast<char16_t*>(buffer.Elements()),
|
||||
appNameLength);
|
||||
mimeInfoMac->SetDefaultDescription(appName);
|
||||
::CFRelease(cfAppName);
|
||||
}
|
||||
}
|
||||
if (cfAppName) {
|
||||
AutoTArray<UniChar, 255> buffer;
|
||||
CFIndex appNameLength = ::CFStringGetLength(cfAppName);
|
||||
buffer.SetLength(appNameLength);
|
||||
::CFStringGetCharacters(cfAppName, CFRangeMake(0, appNameLength),
|
||||
buffer.Elements());
|
||||
nsAutoString appName;
|
||||
appName.Assign(reinterpret_cast<char16_t*>(buffer.Elements()),
|
||||
appNameLength);
|
||||
mimeInfoMac->SetDefaultDescription(appName);
|
||||
::CFRelease(cfAppName);
|
||||
}
|
||||
|
||||
mimeInfoMac->SetDefaultApplication(app);
|
||||
mimeInfoMac->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
|
||||
} else {
|
||||
mimeInfoMac->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
}
|
||||
|
||||
mimeInfoMac->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
||||
|
||||
nsAutoCString mimeType;
|
||||
mimeInfoMac->GetMIMEType(mimeType);
|
||||
if (*aFound && !mimeType.IsEmpty()) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "nsILineInputStream.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIProcess.h"
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
@@ -263,13 +264,10 @@ static nsresult DoGetFileLocation(FileKind aKind, nsAString& aFileLocation) {
|
||||
// natural way to do the charset conversion is by just initing
|
||||
// an nsIFile with the native path and asking it for the Unicode
|
||||
// version.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(envValue),
|
||||
getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = file->InitWithNativePath(nsDependentCString(envValue));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return file->GetPath(aFileLocation);
|
||||
}
|
||||
}
|
||||
@@ -332,10 +330,8 @@ nsresult nsOSHelperAppService::CreateInputStream(
|
||||
LOG("-- CreateInputStream");
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = file->InitWithPath(aFilename);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
MOZ_TRY(NS_NewLocalFile(aFilename, getter_AddRefs(file)));
|
||||
|
||||
nsCOMPtr<nsIFileInputStream> fileStream(
|
||||
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
|
||||
@@ -911,10 +907,8 @@ nsresult nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(
|
||||
nsresult rv = NS_OK;
|
||||
bool more = false;
|
||||
|
||||
nsCOMPtr<nsIFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = file->InitWithPath(aFilename);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
MOZ_TRY(NS_NewLocalFile(aFilename, getter_AddRefs(file)));
|
||||
|
||||
nsCOMPtr<nsIFileInputStream> mailcapFile(
|
||||
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
|
||||
@@ -1046,10 +1040,9 @@ nsresult nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(
|
||||
nsCOMPtr<nsIProcess> process =
|
||||
do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
nsCOMPtr<nsIFile> file(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) continue;
|
||||
rv = file->InitWithNativePath("/bin/sh"_ns);
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv =
|
||||
NS_NewNativeLocalFile("/bin/sh"_ns, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) continue;
|
||||
rv = process->Init(file);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
@@ -1166,10 +1159,6 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(
|
||||
// If we get here, we really should have a relative path.
|
||||
NS_ASSERTION(*platformAppPath != char16_t('/'), "Unexpected absolute path");
|
||||
|
||||
nsCOMPtr<nsIFile> localFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
|
||||
if (!localFile) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
bool exists = false;
|
||||
// ugly hack. Walk the PATH variable...
|
||||
char* unixpath = PR_GetEnv("PATH");
|
||||
@@ -1179,11 +1168,13 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(
|
||||
const char* colon_iter = start_iter;
|
||||
const char* end_iter = path.EndReading(end_iter);
|
||||
|
||||
nsCOMPtr<nsIFile> localFile = new nsLocalFile();
|
||||
while (start_iter != end_iter && !exists) {
|
||||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
// Failing AppendRelativePath is a bad thing - it should basically always
|
||||
// succeed given a relative path. Show a warning if it does fail.
|
||||
|
||||
@@ -62,9 +62,8 @@ nsresult CheckValidHDROP(STGMEDIUM* pSTG) {
|
||||
s = (char16_t*)((char*)pDropFiles + pDropFiles->pFiles + offset);
|
||||
if (s.IsEmpty()) break;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> localFile(
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
rv = localFile->InitWithPath(s);
|
||||
nsCOMPtr<nsIFile> localFile;
|
||||
rv = NS_NewLocalFile(s, getter_AddRefs(localFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("File could not be opened");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
@@ -170,10 +170,8 @@ nsresult nsMacUtilsImpl::GetBloatLogDir(nsCString& aDirectoryPath) {
|
||||
nsresult nsMacUtilsImpl::GetDirectoryPath(const char* aPath,
|
||||
nsCString& aDirectoryPath) {
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = file->InitWithNativePath(nsDependentCString(aPath));
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(aPath), getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> directoryFile;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#ifdef XP_WIN
|
||||
# include "nsILocalFileWin.h"
|
||||
#endif
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
@@ -44,8 +45,7 @@ static void SetUseDOSDevicePathSyntax(nsIFile* aFile) {
|
||||
|
||||
static already_AddRefed<nsIFile> NewFile(nsIFile* aBase) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
VerifyResult(rv, "Creating nsIFile");
|
||||
nsCOMPtr<nsIFile> file = new nsLocalFile();
|
||||
rv = file->InitWithFile(aBase);
|
||||
VerifyResult(rv, "InitWithFile");
|
||||
|
||||
|
||||
@@ -17,20 +17,27 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
static void CanInitWith(const char* aPath, bool aShouldWork) {
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
nsresult rv = file->InitWithNativePath(nsDependentCString(aPath));
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv =
|
||||
NS_NewNativeLocalFile(nsDependentCString(aPath), getter_AddRefs(file));
|
||||
bool success = aShouldWork ? NS_SUCCEEDED(rv) : NS_FAILED(rv);
|
||||
EXPECT_TRUE(success) << "'" << aPath << "' rv=" << std::hex
|
||||
<< (unsigned int)rv;
|
||||
}
|
||||
|
||||
static void CanAppend(const char* aRoot, const char* aPath, bool aShouldWork) {
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
file->InitWithNativePath(nsDependentCString(aRoot));
|
||||
nsAutoCString basePath;
|
||||
file->GetNativeTarget(basePath);
|
||||
static nsresult SetUpFile(const char* aRoot, nsIFile** aFile,
|
||||
nsAutoCString& aBasePath) {
|
||||
MOZ_TRY(NS_NewNativeLocalFile(nsDependentCString(aRoot), aFile));
|
||||
return (*aFile)->GetNativeTarget(aBasePath);
|
||||
}
|
||||
|
||||
nsresult rv = file->AppendNative(nsDependentCString(aPath));
|
||||
static void CanAppend(const char* aRoot, const char* aPath, bool aShouldWork) {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsAutoCString basePath;
|
||||
nsresult rv = SetUpFile(aRoot, getter_AddRefs(file), basePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = file->AppendNative(nsDependentCString(aPath));
|
||||
}
|
||||
bool success = aShouldWork ? NS_SUCCEEDED(rv) : NS_FAILED(rv);
|
||||
EXPECT_TRUE(success) << "'" << basePath.get() << "' + '" << aPath
|
||||
<< "' rv=" << std::hex << (unsigned int)rv;
|
||||
@@ -38,13 +45,12 @@ static void CanAppend(const char* aRoot, const char* aPath, bool aShouldWork) {
|
||||
|
||||
static void CanSetLeafName(const char* aRoot, const char* aPath,
|
||||
bool aShouldWork) {
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
file->InitWithNativePath(nsDependentCString(aRoot));
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsAutoCString basePath;
|
||||
file->GetNativeTarget(basePath);
|
||||
|
||||
nsresult rv =
|
||||
file->SetLeafName(NS_ConvertUTF8toUTF16(nsDependentCString(aPath)));
|
||||
nsresult rv = SetUpFile(aRoot, getter_AddRefs(file), basePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = file->SetLeafName(NS_ConvertUTF8toUTF16(nsDependentCString(aPath)));
|
||||
}
|
||||
bool success = aShouldWork ? NS_SUCCEEDED(rv) : NS_FAILED(rv);
|
||||
EXPECT_TRUE(success) << "'" << basePath.get() << "' set leaf to '" << aPath
|
||||
<< "' rv=" << std::hex << (unsigned int)rv;
|
||||
@@ -278,11 +284,11 @@ TEST(TestFileNTFSSpecialPaths, Normalization)
|
||||
}
|
||||
startingFilePath.AppendLiteral(u"$mft");
|
||||
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
nsCOMPtr<nsIFile> file;
|
||||
// This should fail immediately, rather than waiting for a call to
|
||||
// nsIFile::Normalize, because normalization doesn't happen reliably,
|
||||
// and where it does happen consumers often don't check for errors.
|
||||
nsresult rv = file->InitWithPath(startingFilePath);
|
||||
nsresult rv = NS_NewLocalFile(startingFilePath, getter_AddRefs(file));
|
||||
EXPECT_NS_FAILED(rv) << " from normalizing '"
|
||||
<< NS_ConvertUTF16toUTF8(startingFilePath).get()
|
||||
<< "' rv=" << std::hex << (unsigned int)rv;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
|
||||
TEST(FilePreferencesWin, Normalization)
|
||||
@@ -112,7 +113,7 @@ TEST(FilePreferencesWin, Normalization)
|
||||
|
||||
TEST(FilePreferencesWin, AccessUNC)
|
||||
{
|
||||
nsCOMPtr<nsIFile> lf = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
nsCOMPtr<nsIFile> lf = new nsLocalFile();
|
||||
|
||||
nsresult rv;
|
||||
|
||||
@@ -139,7 +140,7 @@ TEST(FilePreferencesWin, AccessDOSDevicePath)
|
||||
{
|
||||
const auto devicePathSpecifier = u"\\\\?\\"_ns;
|
||||
|
||||
nsCOMPtr<nsIFile> lf = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
nsCOMPtr<nsIFile> lf = new nsLocalFile();
|
||||
|
||||
nsresult rv;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user