2001-01-22 22:01:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_imgRequest_h
|
|
|
|
#define mozilla_image_imgRequest_h
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2008-12-22 22:20:46 +00:00
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
#include "nsIStreamListener.h"
|
2013-09-28 18:28:42 +00:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2007-11-09 02:55:41 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2001-05-08 04:21:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-28 18:28:42 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2017-12-07 00:52:51 +00:00
|
|
|
#include "nsString.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2010-08-05 02:15:55 +00:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2015-03-24 02:37:45 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-05-20 17:21:13 +00:00
|
|
|
#include "ImageCacheKey.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2002-12-24 14:30:12 +00:00
|
|
|
class imgCacheValidator;
|
2012-06-26 04:20:12 +00:00
|
|
|
class imgLoader;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
class imgRequestProxy;
|
2008-09-04 23:00:42 +00:00
|
|
|
class imgCacheEntry;
|
2013-09-07 13:01:08 +00:00
|
|
|
class nsIProperties;
|
|
|
|
class nsIRequest;
|
|
|
|
class nsITimedChannel;
|
|
|
|
class nsIURI;
|
2019-07-25 08:23:32 +00:00
|
|
|
class nsIReferrerInfo;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
namespace mozilla {
|
2021-05-05 15:23:25 +00:00
|
|
|
enum CORSMode : uint8_t;
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-14 04:09:48 +00:00
|
|
|
class Image;
|
2014-11-15 04:10:47 +00:00
|
|
|
class ProgressTracker;
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
struct NewPartResult;
|
|
|
|
|
2023-10-27 13:30:11 +00:00
|
|
|
class imgRequest final : public nsIThreadRetargetableStreamListener,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback {
|
2014-11-15 04:10:47 +00:00
|
|
|
typedef mozilla::image::Image Image;
|
2015-05-20 17:21:13 +00:00
|
|
|
typedef mozilla::image::ImageCacheKey ImageCacheKey;
|
2014-11-15 04:10:47 +00:00
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
2019-08-21 13:24:45 +00:00
|
|
|
typedef mozilla::dom::ReferrerPolicy ReferrerPolicy;
|
2014-11-15 04:10:47 +00:00
|
|
|
|
2015-03-24 02:37:46 +00:00
|
|
|
public:
|
2015-05-20 17:21:13 +00:00
|
|
|
imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey);
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2015-03-24 02:37:46 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2001-10-12 06:43:52 +00:00
|
|
|
|
2020-11-18 09:05:59 +00:00
|
|
|
[[nodiscard]] nsresult Init(nsIURI* aURI, nsIURI* aFinalURI,
|
|
|
|
bool aHadInsecureRedirect, nsIRequest* aRequest,
|
|
|
|
nsIChannel* aChannel, imgCacheEntry* aCacheEntry,
|
|
|
|
mozilla::dom::Document* aLoadingDocument,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal,
|
2021-05-05 15:23:25 +00:00
|
|
|
mozilla::CORSMode aCORSMode,
|
2020-11-18 09:05:59 +00:00
|
|
|
nsIReferrerInfo* aReferrerInfo);
|
2001-10-12 06:43:52 +00:00
|
|
|
|
2014-09-05 21:36:11 +00:00
|
|
|
void ClearLoader();
|
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// Callers must call imgRequestProxy::Notify later.
|
2015-03-31 18:06:00 +00:00
|
|
|
void AddProxy(imgRequestProxy* proxy);
|
2006-06-01 18:35:21 +00:00
|
|
|
|
2020-07-30 08:55:24 +00:00
|
|
|
// Whether a given document is allowed to reuse this request without any
|
|
|
|
// revalidation.
|
|
|
|
bool CanReuseWithoutValidation(mozilla::dom::Document*) const;
|
|
|
|
|
2015-03-31 18:06:00 +00:00
|
|
|
nsresult RemoveProxy(imgRequestProxy* proxy, nsresult aStatus);
|
2001-02-26 04:22:47 +00:00
|
|
|
|
2008-12-22 22:20:46 +00:00
|
|
|
// Cancel, but also ensure that all work done in Init() is undone. Call this
|
|
|
|
// only when the channel has failed to open, and so calling Cancel() on it
|
|
|
|
// won't be sufficient.
|
|
|
|
void CancelAndAbort(nsresult aStatus);
|
|
|
|
|
2013-10-15 23:33:11 +00:00
|
|
|
// Called or dispatched by cancel for main thread only execution.
|
|
|
|
void ContinueCancel(nsresult aStatus);
|
|
|
|
|
2014-06-08 22:15:00 +00:00
|
|
|
// Called or dispatched by EvictFromCache for main thread only execution.
|
|
|
|
void ContinueEvict();
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
// Request that we start decoding the image as soon as data becomes available.
|
2015-10-29 23:37:42 +00:00
|
|
|
void StartDecoding();
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2022-02-14 10:00:40 +00:00
|
|
|
uint64_t InnerWindowID() const;
|
|
|
|
void SetInnerWindowID(uint64_t aInnerWindowId);
|
2010-12-20 16:21:59 +00:00
|
|
|
|
2011-07-01 17:03:33 +00:00
|
|
|
// Set the cache validation information (expiry time, whether we must
|
|
|
|
// validate, etc) on the cache entry based on the request information.
|
|
|
|
// If this function is called multiple times, the information set earliest
|
|
|
|
// wins.
|
|
|
|
static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
bool GetMultipart() const;
|
2012-05-19 19:32:37 +00:00
|
|
|
|
2014-12-16 01:40:43 +00:00
|
|
|
// Returns whether we went through an insecure (non-HTTPS) redirect at some
|
2017-11-13 08:31:24 +00:00
|
|
|
// point during loading. This does not consider the final URI.
|
2015-03-29 23:25:48 +00:00
|
|
|
bool HadInsecureRedirect() const;
|
2014-12-16 01:40:43 +00:00
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
// The CORS mode for which we loaded this image.
|
2021-05-05 15:23:25 +00:00
|
|
|
mozilla::CORSMode GetCORSMode() const { return mCORSMode; }
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2019-07-25 08:23:32 +00:00
|
|
|
// The ReferrerInfo in effect when loading this image.
|
|
|
|
nsIReferrerInfo* GetReferrerInfo() const { return mReferrerInfo; }
|
2014-11-18 13:46:53 +00:00
|
|
|
|
2011-07-14 18:47:32 +00:00
|
|
|
// The principal for the document that loaded this image. Used when trying to
|
|
|
|
// validate a CORS image load.
|
2022-09-28 03:56:57 +00:00
|
|
|
already_AddRefed<nsIPrincipal> GetTriggeringPrincipal() const;
|
2011-07-14 18:47:32 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
// Return the ProgressTracker associated with this imgRequest. It may live
|
|
|
|
// in |mProgressTracker| or in |mImage.mProgressTracker|, depending on whether
|
2012-10-12 16:11:21 +00:00
|
|
|
// mImage has been instantiated yet.
|
2015-03-24 02:37:45 +00:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
/// Returns the Image associated with this imgRequest, if it's ready.
|
|
|
|
already_AddRefed<Image> GetImage() const;
|
|
|
|
|
2012-10-12 16:11:20 +00:00
|
|
|
// Get the current principal of the image. No AddRefing.
|
2012-12-09 17:23:19 +00:00
|
|
|
inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); }
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
/// Get the ImageCacheKey associated with this request.
|
|
|
|
const ImageCacheKey& CacheKey() const { return mCacheKey; }
|
|
|
|
|
2012-10-12 16:11:21 +00:00
|
|
|
// Resize the cache entry to 0 if it exists
|
|
|
|
void ResetCacheEntry();
|
|
|
|
|
2013-09-28 18:28:42 +00:00
|
|
|
// OK to use on any thread.
|
2018-06-06 00:42:57 +00:00
|
|
|
nsresult GetURI(nsIURI** aURI);
|
2017-11-13 08:31:24 +00:00
|
|
|
nsresult GetFinalURI(nsIURI** aURI);
|
2015-04-28 18:45:45 +00:00
|
|
|
bool IsChrome() const;
|
2017-09-25 15:44:49 +00:00
|
|
|
bool IsData() const;
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2014-07-19 01:47:11 +00:00
|
|
|
nsresult GetImageErrorCode(void);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
/// Returns a non-owning pointer to this imgRequest's MIME type.
|
|
|
|
const char* GetMimeType() const { return mContentType.get(); }
|
|
|
|
|
2022-05-06 10:00:52 +00:00
|
|
|
void GetFileName(nsACString& aFileName);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
/// @return the priority of the underlying network request, or
|
|
|
|
/// PRIORITY_NORMAL if it doesn't support nsISupportsPriority.
|
|
|
|
int32_t Priority() const;
|
|
|
|
|
|
|
|
/// Adjust the priority of the underlying network request by @aDelta on behalf
|
|
|
|
/// of @aProxy.
|
|
|
|
void AdjustPriority(imgRequestProxy* aProxy, int32_t aDelta);
|
|
|
|
|
2017-03-22 11:52:15 +00:00
|
|
|
void BoostPriority(uint32_t aCategory);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
/// Returns a weak pointer to the underlying request.
|
|
|
|
nsIRequest* GetRequest() const { return mRequest; }
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
nsITimedChannel* GetTimedChannel() const { return mTimedChannel; }
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
imgCacheValidator* GetValidator() const { return mValidator; }
|
|
|
|
void SetValidator(imgCacheValidator* aValidator) { mValidator = aValidator; }
|
2015-03-24 02:37:45 +00:00
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
void* LoadId() const { return mLoadId; }
|
2015-03-24 02:37:45 +00:00
|
|
|
void SetLoadId(void* aLoadId) { mLoadId = aLoadId; }
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
/// Reset the cache entry after we've dropped our reference to it. Used by
|
|
|
|
/// imgLoader when our cache entry is re-requested after we've dropped our
|
|
|
|
/// reference to it.
|
|
|
|
void SetCacheEntry(imgCacheEntry* aEntry);
|
|
|
|
|
|
|
|
/// Returns whether we've got a reference to the cache entry.
|
|
|
|
bool HasCacheEntry() const;
|
|
|
|
|
|
|
|
/// Set whether this request is stored in the cache. If it isn't, regardless
|
|
|
|
/// of whether this request has a non-null mCacheEntry, this imgRequest won't
|
|
|
|
/// try to update or modify the image cache.
|
|
|
|
void SetIsInCache(bool aCacheable);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
void EvictFromCache();
|
|
|
|
void RemoveFromCache();
|
|
|
|
|
2015-03-24 02:37:46 +00:00
|
|
|
// Sets properties for this image; will dispatch to main thread if needed.
|
|
|
|
void SetProperties(const nsACString& aContentType,
|
|
|
|
const nsACString& aContentDisposition);
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
nsIProperties* Properties() const { return mProperties; }
|
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
bool HasConsumers() const;
|
|
|
|
|
2019-05-01 23:05:47 +00:00
|
|
|
bool ImageAvailable() const;
|
|
|
|
|
2020-05-11 14:43:05 +00:00
|
|
|
bool IsDeniedCrossSiteCORSRequest() const {
|
|
|
|
return mIsDeniedCrossSiteCORSRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsCrossSiteNoCORSRequest() const { return mIsCrossSiteNoCORSRequest; }
|
|
|
|
|
2023-11-02 20:53:36 +00:00
|
|
|
bool ShouldReportRenderTimeForLCP() const {
|
|
|
|
return mShouldReportRenderTimeForLCP;
|
|
|
|
}
|
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
private:
|
2015-03-24 02:37:46 +00:00
|
|
|
friend class FinishPreparingForNewPartRunnable;
|
|
|
|
|
|
|
|
virtual ~imgRequest();
|
|
|
|
|
|
|
|
void FinishPreparingForNewPart(const NewPartResult& aResult);
|
|
|
|
|
2023-11-02 20:53:36 +00:00
|
|
|
void UpdateShouldReportRenderTimeForLCP();
|
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
void Cancel(nsresult aStatus);
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
// Update the cache entry size based on the image container.
|
|
|
|
void UpdateCacheEntrySize();
|
|
|
|
|
2015-10-29 23:37:42 +00:00
|
|
|
/// Returns true if StartDecoding() was called.
|
2015-03-24 02:37:45 +00:00
|
|
|
bool IsDecodeRequested() const;
|
|
|
|
|
2017-03-22 11:52:15 +00:00
|
|
|
void AdjustPriorityInternal(int32_t aDelta);
|
|
|
|
|
2012-06-26 04:20:12 +00:00
|
|
|
// Weak reference to parent loader; this request cannot outlive its owner.
|
|
|
|
imgLoader* mLoader;
|
2006-03-11 20:32:47 +00:00
|
|
|
nsCOMPtr<nsIRequest> mRequest;
|
2011-07-01 17:03:40 +00:00
|
|
|
// The original URI we were loaded with. This is the same as the URI we are
|
2013-09-28 18:28:42 +00:00
|
|
|
// keyed on in the cache. We store a string here to avoid off main thread
|
|
|
|
// refcounting issues with nsStandardURL.
|
2018-06-06 00:42:57 +00:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2011-07-01 17:03:40 +00:00
|
|
|
// The URI of the resource we ended up loading after all redirects, etc.
|
2017-11-13 08:31:24 +00:00
|
|
|
nsCOMPtr<nsIURI> mFinalURI;
|
2017-10-03 03:38:30 +00:00
|
|
|
// The principal which triggered the load of this image. Generally either
|
|
|
|
// the principal of the document the image is being loaded into, or of the
|
|
|
|
// stylesheet which specified the image to load. Used when validating for
|
|
|
|
// CORS.
|
|
|
|
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
2011-07-14 18:47:32 +00:00
|
|
|
// The principal of this image.
|
2007-11-09 02:55:41 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2005-03-23 21:09:02 +00:00
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2008-12-22 22:20:46 +00:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mPrevChannelSink;
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2011-06-09 21:11:57 +00:00
|
|
|
nsCOMPtr<nsITimedChannel> mTimedChannel;
|
|
|
|
|
2004-07-19 18:53:02 +00:00
|
|
|
nsCString mContentType;
|
2001-03-16 02:40:04 +00:00
|
|
|
|
2015-03-31 18:06:00 +00:00
|
|
|
/* we hold on to this to this so long as we have observers */
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgCacheEntry> mCacheEntry;
|
2001-10-17 05:57:29 +00:00
|
|
|
|
2015-05-20 17:21:13 +00:00
|
|
|
/// The key under which this imgRequest is stored in the image cache.
|
|
|
|
ImageCacheKey mCacheKey;
|
|
|
|
|
2015-03-31 18:06:00 +00:00
|
|
|
void* mLoadId;
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2015-08-25 02:49:33 +00:00
|
|
|
/// Raw pointer to the first proxy that was added to this imgRequest. Use only
|
|
|
|
/// pointer comparisons; there's no guarantee this will remain valid.
|
|
|
|
void* mFirstProxy;
|
|
|
|
|
2015-03-31 18:06:00 +00:00
|
|
|
imgCacheValidator* mValidator;
|
2010-08-05 02:15:55 +00:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2010-12-20 16:21:59 +00:00
|
|
|
|
2011-07-14 18:47:34 +00:00
|
|
|
// The CORS mode (defined in imgIRequest) this image was loaded with. By
|
2021-05-05 15:23:25 +00:00
|
|
|
// default, CORS_NONE.
|
|
|
|
mozilla::CORSMode mCORSMode;
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2019-07-25 08:23:32 +00:00
|
|
|
// The ReferrerInfo used for this image.
|
|
|
|
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
2014-11-18 13:46:53 +00:00
|
|
|
|
2014-07-19 01:47:11 +00:00
|
|
|
nsresult mImageErrorCode;
|
|
|
|
|
2017-03-22 11:52:15 +00:00
|
|
|
// The categories of prioritization strategy that have been requested.
|
|
|
|
uint32_t mBoostCategoriesRequested = 0;
|
|
|
|
|
2019-05-01 23:05:47 +00:00
|
|
|
// If we've called OnImageAvailable.
|
|
|
|
bool mImageAvailable;
|
2020-05-26 02:06:00 +00:00
|
|
|
bool mIsDeniedCrossSiteCORSRequest;
|
|
|
|
bool mIsCrossSiteNoCORSRequest;
|
2019-05-01 23:05:47 +00:00
|
|
|
|
2023-11-02 20:53:36 +00:00
|
|
|
bool mShouldReportRenderTimeForLCP;
|
2024-03-18 20:04:01 +00:00
|
|
|
// SVGs can't be OffMainThread for example
|
|
|
|
bool mOffMainThreadData = false;
|
2023-11-02 20:53:36 +00:00
|
|
|
|
2022-03-21 20:04:39 +00:00
|
|
|
mutable mozilla::Mutex mMutex;
|
2009-09-16 00:33:14 +00:00
|
|
|
|
2015-03-24 02:37:45 +00:00
|
|
|
// Member variables protected by mMutex. Note that *all* flags in our bitfield
|
|
|
|
// are protected by mMutex; if you're adding a new flag that isn'protected, it
|
|
|
|
// must not be a part of this bitfield.
|
2022-08-03 16:39:41 +00:00
|
|
|
RefPtr<ProgressTracker> mProgressTracker MOZ_GUARDED_BY(mMutex);
|
|
|
|
RefPtr<Image> mImage MOZ_GUARDED_BY(mMutex);
|
|
|
|
bool mIsMultiPartChannel : 1 MOZ_GUARDED_BY(mMutex);
|
|
|
|
bool mIsInCache : 1 MOZ_GUARDED_BY(mMutex);
|
|
|
|
bool mDecodeRequested : 1 MOZ_GUARDED_BY(mMutex);
|
|
|
|
bool mNewPartPending : 1 MOZ_GUARDED_BY(mMutex);
|
|
|
|
bool mHadInsecureRedirect : 1 MOZ_GUARDED_BY(mMutex);
|
2022-03-21 20:04:39 +00:00
|
|
|
// The ID of the inner window origin, used for error reporting.
|
2022-08-03 16:39:41 +00:00
|
|
|
uint64_t mInnerWindowId MOZ_GUARDED_BY(mMutex);
|
2001-01-22 22:01:03 +00:00
|
|
|
};
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_imgRequest_h
|