Bug 685236 - Stop using GetNativePath in widget/windows. r=jimm
MozReview-Commit-ID: I49ngV1Jq9I
--- a/widget/windows/PDFViaEMFPrintHelper.cpp
+++ b/widget/windows/PDFViaEMFPrintHelper.cpp
@@ -6,16 +6,17 @@
#include "PDFViaEMFPrintHelper.h"
#include "nsIFileStreams.h"
#include "WindowsEMF.h"
#include "nsFileStreams.h"
#include "mozilla/UniquePtrExtensions.h"
#include "mozilla/dom/File.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/ProtocolUtils.h"
+#include "mozilla/FileUtils.h"
/* Scale DC by keeping aspect ratio */
static
float ComputeScaleFactor(int aDCWidth, int aDCHeight,
int aPageWidth, int aPageHeight)
{
MOZ_ASSERT(aPageWidth !=0 && aPageWidth != 0);
@@ -42,44 +43,24 @@ PDFViaEMFPrintHelper::OpenDocument(nsIFi
if (mPDFDoc) {
MOZ_ASSERT_UNREACHABLE("We can only open one PDF at a time,"
"Use CloseDocument() to close the opened file"
"before calling OpenDocument()");
return NS_ERROR_FAILURE;
}
-
- nsAutoCString nativePath;
- nsresult rv = aFile->GetNativePath(nativePath);
+ AutoFDClose prFileDesc;
+ nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &prFileDesc.rwget());
if (NS_FAILED(rv)) {
return rv;
}
- return OpenDocument(nativePath.get());
-}
-
-nsresult
-PDFViaEMFPrintHelper::OpenDocument(const char* aFileName)
-{
- MOZ_ASSERT(aFileName);
-
- if (mPDFDoc) {
- MOZ_ASSERT_UNREACHABLE("We can only open one PDF at a time,"
- "Use CloseDocument() to close the opened file"
- "before calling OpenDocument()");
- return NS_ERROR_FAILURE;
- }
-
- NS_ENSURE_TRUE(CreatePDFiumEngineIfNeed(), NS_ERROR_FAILURE);
-
- mPDFDoc = mPDFiumEngine->LoadDocument(aFileName, nullptr);
- NS_ENSURE_TRUE(mPDFDoc, NS_ERROR_FAILURE);
-
- return NS_OK;
+ return OpenDocument(FileDescriptor(FileDescriptor::PlatformHandleType(
+ PR_FileDesc2NativeHandle(prFileDesc))));
}
nsresult
PDFViaEMFPrintHelper::OpenDocument(const FileDescriptor& aFD)
{
MOZ_ASSERT(!mPrfile, "Forget to call CloseDocument?");
if (mPDFDoc) {
--- a/widget/windows/PDFViaEMFPrintHelper.h
+++ b/widget/windows/PDFViaEMFPrintHelper.h
@@ -37,17 +37,16 @@ class PDFViaEMFPrintHelper
public:
typedef mozilla::ipc::FileDescriptor FileDescriptor;
PDFViaEMFPrintHelper();
virtual ~PDFViaEMFPrintHelper();
/** Loads the specified PDF file. */
NS_IMETHOD OpenDocument(nsIFile* aFile);
- NS_IMETHOD OpenDocument(const char* aFileName);
NS_IMETHOD OpenDocument(const FileDescriptor& aFD);
/** Releases document buffer. */
void CloseDocument();
int GetPageCount() const { return mPDFiumEngine->GetPageCount(mPDFDoc); }
/**
--- a/widget/windows/WinTaskbar.cpp
+++ b/widget/windows/WinTaskbar.cpp
@@ -226,17 +226,17 @@ WinTaskbar::GetAppUserModelID(nsAString
Preferences::GetBool("taskbar.grouping.useprofile", false);
if (useProfile) {
nsCOMPtr<nsIFile> profileDir;
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
bool exists = false;
if (profileDir && NS_SUCCEEDED(profileDir->Exists(&exists)) && exists) {
nsAutoCString path;
- if (NS_SUCCEEDED(profileDir->GetNativePath(path))) {
+ if (NS_SUCCEEDED(profileDir->GetPersistentDescriptor(path))) {
nsAutoString id;
id.AppendInt(HashString(path));
if (!id.IsEmpty()) {
aDefaultGroupId.Assign(id);
return true;
}
}
}
--- a/widget/windows/gtest/TestEMFConversion.cpp
+++ b/widget/windows/gtest/TestEMFConversion.cpp
@@ -36,20 +36,20 @@ static NS_IMETHODIMP
GetFilePathViaSpecialDirectory(const char* aSpecialDirName,
const char* aFileName,
nsAutoString& aPath)
{
nsCOMPtr<nsIFile> file = GetFileViaSpecialDirectory(aSpecialDirName,
aFileName);
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
- nsAutoCString path;
- nsresult rv = file->GetNativePath(path);
+ nsAutoString path;
+ nsresult rv = file->GetPath(path);
if (NS_SUCCEEDED(rv)) {
- aPath = NS_ConvertUTF8toUTF16(path);
+ aPath = path;
}
return rv;
}
static bool
SetupPrintHelper(const char* aFileName, PDFViaEMFPrintHelper* aHelper)
{
nsCOMPtr<nsIFile> file = GetFileViaSpecialDirectory(NS_OS_CURRENT_WORKING_DIR,
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -1210,39 +1210,53 @@ nsDataObj :: GetFileContentsInternetShor
nsAutoCString asciiUrl;
rv = aUri->GetAsciiSpec(asciiUrl);
if (NS_FAILED(rv)) {
return E_FAIL;
}
const char *shortcutFormatStr;
int totalLen;
- nsCString path;
+ nsCString asciiPath;
if (!Preferences::GetBool(kShellIconPref, true)) {
shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n";
const int formatLen = strlen(shortcutFormatStr) - 2; // don't include %s
totalLen = formatLen + asciiUrl.Length(); // don't include null character
} else {
nsCOMPtr<nsIFile> icoFile;
nsAutoString aUriHash;
mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
NS_ENSURE_SUCCESS(rv, E_FAIL);
- rv = icoFile->GetNativePath(path);
+ nsString path;
+ rv = icoFile->GetPath(path);
NS_ENSURE_SUCCESS(rv, E_FAIL);
- shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
- "IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
- "IconIndex=0\r\n";
+ if (NS_IsAscii(path.get())) {
+ LossyCopyUTF16toASCII(path, asciiPath);
+ shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
+ "IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
+ "IconIndex=0\r\n";
+ } else {
+ int len = WideCharToMultiByte(CP_UTF7, 0, char16ptr_t(path.BeginReading()),
+ path.Length(), nullptr, 0, nullptr, nullptr);
+ NS_ENSURE_TRUE(len > 0, E_FAIL);
+ asciiPath.SetLength(len);
+ WideCharToMultiByte(CP_UTF7, 0, char16ptr_t(path.BeginReading()), path.Length(),
+ asciiPath.BeginWriting(), len, nullptr, nullptr);
+ shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
+ "IDList=\r\nHotKey=0\r\nIconIndex=0\r\n"
+ "[InternetShortcut.W]\r\nIconFile=%s\r\n";
+ }
const int formatLen = strlen(shortcutFormatStr) - 2 * 2; // no %s twice
totalLen = formatLen + asciiUrl.Length() +
- path.Length(); // we don't want a null character on the end
+ asciiPath.Length(); // we don't want a null character on the end
}
// create a global memory area and build up the file contents w/in it
HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_SHARE, totalLen);
if ( !hGlobalMemory )
return E_OUTOFMEMORY;
char* contents = reinterpret_cast<char*>(::GlobalLock(hGlobalMemory));
@@ -1254,17 +1268,17 @@ nsDataObj :: GetFileContentsInternetShor
//NOTE: we intentionally use the Microsoft version of snprintf here because it does NOT null
// terminate strings which reach the maximum size of the buffer. Since we know that the
// formatted length here is totalLen, this call to _snprintf will format the string into
// the buffer without appending the null character.
if (!Preferences::GetBool(kShellIconPref, true)) {
_snprintf(contents, totalLen, shortcutFormatStr, asciiUrl.get());
} else {
- _snprintf(contents, totalLen, shortcutFormatStr, asciiUrl.get(), path.get());
+ _snprintf(contents, totalLen, shortcutFormatStr, asciiUrl.get(), asciiPath.get());
}
::GlobalUnlock(hGlobalMemory);
aSTG.hGlobal = hGlobalMemory;
aSTG.tymed = TYMED_HGLOBAL;
return S_OK;
} // GetFileContentsInternetShortcut