зеркало из https://github.com/mozilla/pjs.git
Bug 523646: make favicon optimization size and file limit configurable using a pref, r=mak
This commit is contained in:
Родитель
703cd7808c
Коммит
e3f0cbbada
|
@ -69,6 +69,7 @@
|
|||
#include "mozIStorageStatementCallback.h"
|
||||
#include "mozIStorageError.h"
|
||||
#include "nsPlacesTables.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
// For favicon optimization
|
||||
#include "imgITools.h"
|
||||
|
@ -81,10 +82,13 @@
|
|||
|
||||
#define CONTENT_SNIFFING_SERVICES "content-sniffing-services"
|
||||
|
||||
// If favicon is bigger than this size we will try to optimize it into a
|
||||
// 16x16 png. An uncompressed 16x16 RGBA image is 1024 bytes, and almost all
|
||||
// sensible 16x16 icons are under 1024 bytes.
|
||||
#define OPTIMIZED_FAVICON_SIZE 1024
|
||||
|
||||
// Default value for mOptimizedIconDimension
|
||||
#define OPTIMIZED_FAVICON_DIMENSION 16
|
||||
|
||||
// Most icons will be smaller than this rough estimate of the size of an
|
||||
// uncompressed 16x16 RGBA image of the same dimensions.
|
||||
#define MAX_ICON_FILESIZE(s) ((PRUint32) s*s*4)
|
||||
|
||||
/**
|
||||
* The maximum time we will keep a favicon around. We always ask the cache, if
|
||||
|
@ -143,6 +147,7 @@ NS_IMPL_ISUPPORTS1(
|
|||
// nsFaviconService::nsFaviconService
|
||||
|
||||
nsFaviconService::nsFaviconService() : mExpirationRunning(false)
|
||||
, mOptimizedIconDimension(OPTIMIZED_FAVICON_DIMENSION)
|
||||
, mFailedFaviconSerial(0)
|
||||
{
|
||||
NS_ASSERTION(! gFaviconService, "ATTEMPTING TO CREATE TWO FAVICON SERVICES!");
|
||||
|
@ -221,6 +226,10 @@ nsFaviconService::Init()
|
|||
if (! mFailedFavicons.Init(MAX_FAVICON_CACHE_SIZE))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> pb = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (pb)
|
||||
pb->GetIntPref("places.favicons.optimizeToDimension", &mOptimizedIconDimension);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -697,7 +706,7 @@ nsFaviconService::SetFaviconData(nsIURI* aFaviconURI, const PRUint8* aData,
|
|||
// If the page provided a large image for the favicon (eg, a highres image
|
||||
// or a multiresolution .ico file), we don't want to store more data than
|
||||
// needed.
|
||||
if (aDataLen > OPTIMIZED_FAVICON_SIZE) {
|
||||
if (aDataLen > MAX_ICON_FILESIZE(mOptimizedIconDimension)) {
|
||||
rv = OptimizeFaviconImage(aData, aDataLen, aMimeType, newData, newMimeType);
|
||||
if (NS_SUCCEEDED(rv) && newData.Length() < aDataLen) {
|
||||
data = reinterpret_cast<PRUint8*>(const_cast<char*>(newData.get())),
|
||||
|
@ -1102,7 +1111,9 @@ nsFaviconService::OptimizeFaviconImage(const PRUint8* aData, PRUint32 aDataLen,
|
|||
|
||||
// scale and recompress
|
||||
nsCOMPtr<nsIInputStream> iconStream;
|
||||
rv = imgtool->EncodeScaledImage(container, aNewMimeType, 16, 16,
|
||||
rv = imgtool->EncodeScaledImage(container, aNewMimeType,
|
||||
mOptimizedIconDimension,
|
||||
mOptimizedIconDimension,
|
||||
getter_AddRefs(iconStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -95,9 +95,9 @@ public:
|
|||
nsresult GetFaviconLinkForIconString(const nsCString& aIcon, nsIURI** aOutput);
|
||||
void GetFaviconSpecForIconString(const nsCString& aIcon, nsACString& aOutput);
|
||||
|
||||
static nsresult OptimizeFaviconImage(const PRUint8* aData, PRUint32 aDataLen,
|
||||
const nsACString& aMimeType,
|
||||
nsACString& aNewData, nsACString& aNewMimeType);
|
||||
nsresult OptimizeFaviconImage(const PRUint8* aData, PRUint32 aDataLen,
|
||||
const nsACString& aMimeType,
|
||||
nsACString& aNewData, nsACString& aNewMimeType);
|
||||
|
||||
/**
|
||||
* Obtains the favicon data asynchronously.
|
||||
|
@ -146,6 +146,12 @@ private:
|
|||
// till expiration has finished.
|
||||
bool mExpirationRunning;
|
||||
|
||||
// The target dimension, in pixels, for favicons we optimize.
|
||||
// If we find images that are as large or larger than an uncompressed RGBA
|
||||
// image of this size (mOptimizedIconDimension*mOptimizedIconDimension*4),
|
||||
// we will try to optimize it.
|
||||
PRInt32 mOptimizedIconDimension;
|
||||
|
||||
PRUint32 mFailedFaviconSerial;
|
||||
nsDataHashtable<nsCStringHashKey, PRUint32> mFailedFavicons;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче