Bug 827784 - Provide an option to disable favicons on webpage shortcuts in Windows. r=bbondy

This commit is contained in:
Joshua Yuan 2013-02-12 19:48:18 -05:00
Родитель 28da168ef4
Коммит 7ccbecdbd6
1 изменённых файлов: 35 добавлений и 16 удалений

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsDirectoryServiceDefs.h"
#include "nsITimer.h"
#include "nsThreadUtils.h"
#include "mozilla/Preferences.h"
#include "WinUtils.h"
#include "mozilla/LazyIdleThread.h"
@ -1097,6 +1098,7 @@ nsDataObj :: GetFileDescriptorInternetShortcutW ( FORMATETC& aFE, STGMEDIUM& aST
HRESULT
nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
{
static const char * kShellIconPref = "browser.shell.shortcutFavicons";
nsAutoString url;
if ( NS_FAILED(ExtractShortcutURL(url)) )
return E_OUTOFMEMORY;
@ -1109,22 +1111,34 @@ nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
nsCOMPtr<nsIURI> aUri;
NS_NewURI(getter_AddRefs(aUri), url);
nsAutoString aUriHash;
mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
NS_ENSURE_SUCCESS(rv, E_FAIL);
const char *shortcutFormatStr;
int totalLen;
nsCString path;
rv = icoFile->GetNativePath(path);
NS_ENSURE_SUCCESS(rv, E_FAIL);
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;
nsCOMPtr<nsIURI> aUri;
NS_NewURI(getter_AddRefs(aUri), url);
static const char* shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n"
"IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
"IconIndex=0\r\n";
static const int formatLen = strlen(shortcutFormatStr) - 2*2; // don't include %s (2 times) in the len
const int totalLen = formatLen + asciiUrl.Length()
+ path.Length(); // we don't want a null character on the end
nsAutoString aUriHash;
mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
NS_ENSURE_SUCCESS(rv, E_FAIL);
rv = icoFile->GetNativePath(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";
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
}
// create a global memory area and build up the file contents w/in it
HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_SHARE, totalLen);
@ -1141,8 +1155,13 @@ nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
// 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.
_snprintf( contents, totalLen, shortcutFormatStr, asciiUrl.get(), path.get() );
if (!Preferences::GetBool(kShellIconPref, true)) {
_snprintf(contents, totalLen, shortcutFormatStr, asciiUrl.get());
} else {
_snprintf(contents, totalLen, shortcutFormatStr, asciiUrl.get(), path.get());
}
::GlobalUnlock(hGlobalMemory);
aSTG.hGlobal = hGlobalMemory;
aSTG.tymed = TYMED_HGLOBAL;