зеркало из https://github.com/mozilla/gecko-dev.git
Bug 827784 - Provide an option to disable favicons on webpage shortcuts in Windows. r=bbondy
This commit is contained in:
Родитель
28da168ef4
Коммит
7ccbecdbd6
|
@ -29,6 +29,7 @@
|
||||||
#include "nsDirectoryServiceDefs.h"
|
#include "nsDirectoryServiceDefs.h"
|
||||||
#include "nsITimer.h"
|
#include "nsITimer.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
#include "mozilla/Preferences.h"
|
||||||
|
|
||||||
#include "WinUtils.h"
|
#include "WinUtils.h"
|
||||||
#include "mozilla/LazyIdleThread.h"
|
#include "mozilla/LazyIdleThread.h"
|
||||||
|
@ -1097,6 +1098,7 @@ nsDataObj :: GetFileDescriptorInternetShortcutW ( FORMATETC& aFE, STGMEDIUM& aST
|
||||||
HRESULT
|
HRESULT
|
||||||
nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
|
nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
|
||||||
{
|
{
|
||||||
|
static const char * kShellIconPref = "browser.shell.shortcutFavicons";
|
||||||
nsAutoString url;
|
nsAutoString url;
|
||||||
if ( NS_FAILED(ExtractShortcutURL(url)) )
|
if ( NS_FAILED(ExtractShortcutURL(url)) )
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
@ -1109,22 +1111,34 @@ nsDataObj :: GetFileContentsInternetShortcut ( FORMATETC& aFE, STGMEDIUM& aSTG )
|
||||||
nsCOMPtr<nsIURI> aUri;
|
nsCOMPtr<nsIURI> aUri;
|
||||||
NS_NewURI(getter_AddRefs(aUri), url);
|
NS_NewURI(getter_AddRefs(aUri), url);
|
||||||
|
|
||||||
nsAutoString aUriHash;
|
const char *shortcutFormatStr;
|
||||||
|
int totalLen;
|
||||||
mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
|
|
||||||
|
|
||||||
nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
|
|
||||||
NS_ENSURE_SUCCESS(rv, E_FAIL);
|
|
||||||
nsCString path;
|
nsCString path;
|
||||||
rv = icoFile->GetNativePath(path);
|
if (!Preferences::GetBool(kShellIconPref, true)) {
|
||||||
NS_ENSURE_SUCCESS(rv, E_FAIL);
|
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"
|
nsAutoString aUriHash;
|
||||||
"IDList=\r\nHotKey=0\r\nIconFile=%s\r\n"
|
|
||||||
"IconIndex=0\r\n";
|
mozilla::widget::FaviconHelper::ObtainCachedIconFile(aUri, aUriHash, mIOThread, true);
|
||||||
static const int formatLen = strlen(shortcutFormatStr) - 2*2; // don't include %s (2 times) in the len
|
|
||||||
const int totalLen = formatLen + asciiUrl.Length()
|
nsresult rv = mozilla::widget::FaviconHelper::GetOutputIconPath(aUri, icoFile, true);
|
||||||
+ path.Length(); // we don't want a null character on the end
|
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
|
// create a global memory area and build up the file contents w/in it
|
||||||
HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_SHARE, totalLen);
|
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
|
// 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
|
// formatted length here is totalLen, this call to _snprintf will format the string into
|
||||||
// the buffer without appending the null character.
|
// 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);
|
::GlobalUnlock(hGlobalMemory);
|
||||||
aSTG.hGlobal = hGlobalMemory;
|
aSTG.hGlobal = hGlobalMemory;
|
||||||
aSTG.tymed = TYMED_HGLOBAL;
|
aSTG.tymed = TYMED_HGLOBAL;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче