зеркало из https://github.com/mozilla/gecko-dev.git
Bug 491311 - Simplify "Add to recent documents" code in nsDownload::SetState. r=gavin
This commit is contained in:
Родитель
641a69f729
Коммит
3bcd9d7cc3
|
@ -2206,19 +2206,8 @@ nsDownload::SetState(DownloadState aState)
|
||||||
if (pref)
|
if (pref)
|
||||||
pref->GetBoolPref(PREF_BDM_ADDTORECENTDOCS, &addToRecentDocs);
|
pref->GetBoolPref(PREF_BDM_ADDTORECENTDOCS, &addToRecentDocs);
|
||||||
|
|
||||||
LPSHELLFOLDER lpShellFolder = NULL;
|
if (addToRecentDocs)
|
||||||
if (addToRecentDocs && SUCCEEDED(::SHGetDesktopFolder(&lpShellFolder))) {
|
::SHAddToRecentDocs(SHARD_PATHW, path.get());
|
||||||
PRUnichar *filePath = ToNewUnicode(path);
|
|
||||||
LPITEMIDLIST lpItemIDList = NULL;
|
|
||||||
if (SUCCEEDED(lpShellFolder->ParseDisplayName(NULL, NULL, filePath,
|
|
||||||
NULL, &lpItemIDList,
|
|
||||||
NULL))) {
|
|
||||||
::SHAddToRecentDocs(SHARD_PIDL, lpItemIDList);
|
|
||||||
::CoTaskMemFree(lpItemIDList);
|
|
||||||
}
|
|
||||||
nsMemory::Free(filePath);
|
|
||||||
lpShellFolder->Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Vista and up, we rely on native security prompting when users
|
// On Vista and up, we rely on native security prompting when users
|
||||||
|
|
|
@ -40,16 +40,19 @@
|
||||||
const nsIDownloadManager = Ci.nsIDownloadManager;
|
const nsIDownloadManager = Ci.nsIDownloadManager;
|
||||||
const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
|
const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
|
||||||
|
|
||||||
const resultFileName = "test" + Date.now() + ".doc";
|
// Make sure Unicode is supported:
|
||||||
|
// U+00E3 : LATIN SMALL LETTER A WITH TILDE
|
||||||
|
// U+041B : CYRILLIC CAPITAL LETTER EL
|
||||||
|
// U+3056 : HIRAGANA LETTER ZA
|
||||||
|
const resultFileName = "test\u00e3\u041b\u3056" + Date.now() + ".doc";
|
||||||
|
|
||||||
function checkResult() {
|
function checkResult() {
|
||||||
do_check_true(checkRecentDocsFor(resultFileName));
|
// delete the saved file (this doesn't affect the "recent documents" list)
|
||||||
|
|
||||||
// delete the saved file
|
|
||||||
var resultFile = dirSvc.get("ProfD", Ci.nsIFile);
|
var resultFile = dirSvc.get("ProfD", Ci.nsIFile);
|
||||||
resultFile.append(resultFileName);
|
resultFile.append(resultFileName);
|
||||||
resultFile.remove(false);
|
resultFile.remove(false);
|
||||||
|
|
||||||
|
do_check_true(checkRecentDocsFor(resultFileName));
|
||||||
do_test_finished();
|
do_test_finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,11 +69,15 @@ function checkRecentDocsFor(aFileName) {
|
||||||
var valueName = recentDocsKey.getValueName(i);
|
var valueName = recentDocsKey.getValueName(i);
|
||||||
var binValue = recentDocsKey.readBinaryValue(valueName);
|
var binValue = recentDocsKey.readBinaryValue(valueName);
|
||||||
|
|
||||||
// "fields" in the data are separated by double nulls, use only the first
|
// "fields" in the data are separated by \0 wide characters, which are
|
||||||
var fileName = binValue.split("\0\0")[0];
|
// returned as two \0 "bytes" by readBinaryValue. Use only the first field.
|
||||||
|
var fileNameRaw = binValue.split("\0\0")[0];
|
||||||
|
|
||||||
// Remove any embeded single nulls
|
// Convert the filename from UTF-16LE.
|
||||||
fileName = fileName.replace(/\x00/g, "");
|
var fileName = "";
|
||||||
|
for (var c = 0; c < fileNameRaw.length; c += 2)
|
||||||
|
fileName += String.fromCharCode(fileNameRaw.charCodeAt(c) |
|
||||||
|
fileNameRaw.charCodeAt(c+1) * 256);
|
||||||
|
|
||||||
if (aFileName == fileName)
|
if (aFileName == fileName)
|
||||||
return true;
|
return true;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче