mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1160703 (Part 1) - Move ImageCacheKey out of imgLoader.h. r=baku
This commit is contained in:
parent
0bf9e896e5
commit
fca79eeea5
70
image/ImageCacheKey.cpp
Normal file
70
image/ImageCacheKey.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "ImageCacheKey.h"
|
||||||
|
|
||||||
|
#include "mozilla/Move.h"
|
||||||
|
#include "File.h"
|
||||||
|
#include "ImageURL.h"
|
||||||
|
#include "nsHostObjectProtocolHandler.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
using namespace dom;
|
||||||
|
|
||||||
|
namespace image {
|
||||||
|
|
||||||
|
ImageCacheKey::ImageCacheKey(nsIURI* aURI)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MOZ_ASSERT(aURI);
|
||||||
|
|
||||||
|
bool isChrome;
|
||||||
|
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
||||||
|
|
||||||
|
aURI->GetSpec(mSpec);
|
||||||
|
mHash = ComputeHash(mSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageCacheKey::ImageCacheKey(ImageURL* aURI)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aURI);
|
||||||
|
|
||||||
|
bool isChrome;
|
||||||
|
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
||||||
|
|
||||||
|
aURI->GetSpec(mSpec);
|
||||||
|
mHash = ComputeHash(mSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
|
||||||
|
: mSpec(aOther.mSpec)
|
||||||
|
, mHash(aOther.mHash)
|
||||||
|
, mIsChrome(aOther.mIsChrome)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
|
||||||
|
: mSpec(Move(aOther.mSpec))
|
||||||
|
, mHash(aOther.mHash)
|
||||||
|
, mIsChrome(aOther.mIsChrome)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool
|
||||||
|
ImageCacheKey::operator==(const ImageCacheKey& aOther) const
|
||||||
|
{
|
||||||
|
return mSpec == aOther.mSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ uint32_t
|
||||||
|
ImageCacheKey::ComputeHash(const nsACString& aSpec)
|
||||||
|
{
|
||||||
|
// Since we frequently call Hash() several times in a row on the same
|
||||||
|
// ImageCacheKey, as an optimization we compute our hash once and store it.
|
||||||
|
return HashString(aSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace image
|
||||||
|
} // namespace mozilla
|
55
image/ImageCacheKey.h
Normal file
55
image/ImageCacheKey.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ImageCacheKey is the key type for the image cache (see imgLoader.h).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef mozilla_image_src_ImageCacheKey_h
|
||||||
|
#define mozilla_image_src_ImageCacheKey_h
|
||||||
|
|
||||||
|
class nsIURI;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace image {
|
||||||
|
|
||||||
|
class ImageURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An ImageLib cache entry key.
|
||||||
|
*
|
||||||
|
* We key the cache on the initial URI (before any redirects), with some
|
||||||
|
* canonicalization applied. See ComputeHash() for the details.
|
||||||
|
*/
|
||||||
|
class ImageCacheKey final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ImageCacheKey(nsIURI* aURI);
|
||||||
|
explicit ImageCacheKey(ImageURL* aURI);
|
||||||
|
|
||||||
|
ImageCacheKey(const ImageCacheKey& aOther);
|
||||||
|
ImageCacheKey(ImageCacheKey&& aOther);
|
||||||
|
|
||||||
|
bool operator==(const ImageCacheKey& aOther) const;
|
||||||
|
uint32_t Hash() const { return mHash; }
|
||||||
|
|
||||||
|
/// A weak pointer to the URI spec for this cache entry. For logging only.
|
||||||
|
const char* Spec() const { return mSpec.get(); }
|
||||||
|
|
||||||
|
/// Is this cache entry for a chrome image?
|
||||||
|
bool IsChrome() const { return mIsChrome; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static uint32_t ComputeHash(const nsACString& aSpec);
|
||||||
|
|
||||||
|
nsCString mSpec;
|
||||||
|
uint32_t mHash;
|
||||||
|
bool mIsChrome;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace image
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // mozilla_image_src_ImageCacheKey_h
|
@ -1100,60 +1100,6 @@ imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// ImageCacheKey
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
ImageCacheKey::ImageCacheKey(nsIURI* aURI)
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
MOZ_ASSERT(aURI);
|
|
||||||
|
|
||||||
bool isChrome;
|
|
||||||
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
|
||||||
|
|
||||||
aURI->GetSpec(mSpec);
|
|
||||||
mHash = ComputeHash(mSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageCacheKey::ImageCacheKey(ImageURL* aURI)
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(aURI);
|
|
||||||
|
|
||||||
bool isChrome;
|
|
||||||
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
|
||||||
|
|
||||||
aURI->GetSpec(mSpec);
|
|
||||||
mHash = ComputeHash(mSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
|
|
||||||
: mSpec(aOther.mSpec)
|
|
||||||
, mHash(aOther.mHash)
|
|
||||||
, mIsChrome(aOther.mIsChrome)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
|
|
||||||
: mSpec(Move(aOther.mSpec))
|
|
||||||
, mHash(aOther.mHash)
|
|
||||||
, mIsChrome(aOther.mIsChrome)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
bool
|
|
||||||
ImageCacheKey::operator==(const ImageCacheKey& aOther) const
|
|
||||||
{
|
|
||||||
return mSpec == aOther.mSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ uint32_t
|
|
||||||
ImageCacheKey::ComputeHash(const nsACString& aSpec)
|
|
||||||
{
|
|
||||||
// Since we frequently call Hash() several times in a row on the same
|
|
||||||
// ImageCacheKey, as an optimization we compute our hash once and store it.
|
|
||||||
return HashString(aSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// imgLoader
|
// imgLoader
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
#include "nsExpirationTracker.h"
|
#include "nsExpirationTracker.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
|
#include "ImageCacheKey.h"
|
||||||
#include "imgRequest.h"
|
#include "imgRequest.h"
|
||||||
#include "nsIProgressEventSink.h"
|
#include "nsIProgressEventSink.h"
|
||||||
#include "nsIChannel.h"
|
#include "nsIChannel.h"
|
||||||
@ -214,38 +215,6 @@ enum class AcceptedMimeTypes : uint8_t {
|
|||||||
IMAGES_AND_DOCUMENTS,
|
IMAGES_AND_DOCUMENTS,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* An ImageLib cache entry key.
|
|
||||||
*
|
|
||||||
* We key the cache on the initial URI (before any redirects), with some
|
|
||||||
* canonicalization applied. See ComputeHash() for the details.
|
|
||||||
*/
|
|
||||||
class ImageCacheKey final
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ImageCacheKey(nsIURI* aURI);
|
|
||||||
explicit ImageCacheKey(mozilla::image::ImageURL* aURI);
|
|
||||||
|
|
||||||
ImageCacheKey(const ImageCacheKey& aOther);
|
|
||||||
ImageCacheKey(ImageCacheKey&& aOther);
|
|
||||||
|
|
||||||
bool operator==(const ImageCacheKey& aOther) const;
|
|
||||||
uint32_t Hash() const { return mHash; }
|
|
||||||
|
|
||||||
/// A weak pointer to the URI spec for this cache entry. For logging only.
|
|
||||||
const char* Spec() const { return mSpec.get(); }
|
|
||||||
|
|
||||||
/// Is this cache entry for a chrome image?
|
|
||||||
bool IsChrome() const { return mIsChrome; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static uint32_t ComputeHash(const nsACString& aSpec);
|
|
||||||
|
|
||||||
nsCString mSpec;
|
|
||||||
uint32_t mHash;
|
|
||||||
bool mIsChrome;
|
|
||||||
};
|
|
||||||
|
|
||||||
class imgLoader final : public imgILoader,
|
class imgLoader final : public imgILoader,
|
||||||
public nsIContentSniffer,
|
public nsIContentSniffer,
|
||||||
public imgICache,
|
public imgICache,
|
||||||
@ -255,6 +224,7 @@ class imgLoader final : public imgILoader,
|
|||||||
virtual ~imgLoader();
|
virtual ~imgLoader();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef mozilla::image::ImageCacheKey ImageCacheKey;
|
||||||
typedef mozilla::image::ImageURL ImageURL;
|
typedef mozilla::image::ImageURL ImageURL;
|
||||||
typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>,
|
typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>,
|
||||||
imgCacheEntry> imgCacheTable;
|
imgCacheEntry> imgCacheTable;
|
||||||
|
@ -34,6 +34,7 @@ XPIDL_SOURCES += [
|
|||||||
XPIDL_MODULE = 'imglib2'
|
XPIDL_MODULE = 'imglib2'
|
||||||
|
|
||||||
EXPORTS += [
|
EXPORTS += [
|
||||||
|
'ImageCacheKey.h',
|
||||||
'ImageLogging.h',
|
'ImageLogging.h',
|
||||||
'ImageOps.h',
|
'ImageOps.h',
|
||||||
'ImageRegion.h',
|
'ImageRegion.h',
|
||||||
@ -53,6 +54,7 @@ UNIFIED_SOURCES += [
|
|||||||
'FrameAnimator.cpp',
|
'FrameAnimator.cpp',
|
||||||
'FrozenImage.cpp',
|
'FrozenImage.cpp',
|
||||||
'Image.cpp',
|
'Image.cpp',
|
||||||
|
'ImageCacheKey.cpp',
|
||||||
'ImageFactory.cpp',
|
'ImageFactory.cpp',
|
||||||
'ImageMetadata.cpp',
|
'ImageMetadata.cpp',
|
||||||
'ImageOps.cpp',
|
'ImageOps.cpp',
|
||||||
|
Loading…
Reference in New Issue
Block a user