2015-05-20 17:21:09 +00:00
|
|
|
/* -*- 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
|
|
|
|
|
2016-08-04 18:22:00 +00:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2015-05-21 01:49:53 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-06-30 17:24:27 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-05-21 01:49:53 +00:00
|
|
|
|
2016-04-11 09:00:03 +00:00
|
|
|
class nsIDocument;
|
2015-05-20 17:21:09 +00:00
|
|
|
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.
|
2015-10-27 18:12:46 +00:00
|
|
|
* Controlled documents do not share their cache entries with
|
|
|
|
* non-controlled documents, or other controlled documents.
|
2015-05-20 17:21:09 +00:00
|
|
|
*/
|
|
|
|
class ImageCacheKey final
|
|
|
|
{
|
|
|
|
public:
|
2016-08-04 18:22:00 +00:00
|
|
|
ImageCacheKey(nsIURI* aURI, const PrincipalOriginAttributes& aAttrs,
|
2016-08-29 05:34:32 +00:00
|
|
|
nsIDocument* aDocument, nsresult& aRv);
|
2016-08-04 18:22:00 +00:00
|
|
|
ImageCacheKey(ImageURL* aURI, const PrincipalOriginAttributes& aAttrs,
|
|
|
|
nsIDocument* aDocument);
|
2015-05-20 17:21:09 +00:00
|
|
|
|
|
|
|
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.
|
2015-05-20 17:21:11 +00:00
|
|
|
const char* Spec() const;
|
2015-05-20 17:21:09 +00:00
|
|
|
|
|
|
|
/// Is this cache entry for a chrome image?
|
|
|
|
bool IsChrome() const { return mIsChrome; }
|
|
|
|
|
2015-10-28 20:01:07 +00:00
|
|
|
/// A token indicating which service worker controlled document this entry
|
|
|
|
/// belongs to, if any.
|
|
|
|
void* ControlledDocument() const { return mControlledDocument; }
|
|
|
|
|
2015-05-20 17:21:09 +00:00
|
|
|
private:
|
2015-05-21 01:49:53 +00:00
|
|
|
static uint32_t ComputeHash(ImageURL* aURI,
|
2015-10-27 18:12:46 +00:00
|
|
|
const Maybe<uint64_t>& aBlobSerial,
|
2016-08-04 18:22:00 +00:00
|
|
|
const PrincipalOriginAttributes& aAttrs,
|
2015-10-27 18:12:46 +00:00
|
|
|
void* aControlledDocument);
|
2016-04-11 09:00:03 +00:00
|
|
|
static void* GetControlledDocumentToken(nsIDocument* aDocument);
|
2015-05-20 17:21:09 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ImageURL> mURI;
|
2015-05-21 01:49:53 +00:00
|
|
|
Maybe<uint64_t> mBlobSerial;
|
2016-08-04 18:22:00 +00:00
|
|
|
PrincipalOriginAttributes mOriginAttributes;
|
2015-10-27 18:12:46 +00:00
|
|
|
void* mControlledDocument;
|
2015-05-20 17:21:09 +00:00
|
|
|
uint32_t mHash;
|
|
|
|
bool mIsChrome;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_image_src_ImageCacheKey_h
|