image/src/imgRequest.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef imgRequest_h__
michael@0 8 #define imgRequest_h__
michael@0 9
michael@0 10 #include "nsIChannelEventSink.h"
michael@0 11 #include "nsIInterfaceRequestor.h"
michael@0 12 #include "nsIStreamListener.h"
michael@0 13 #include "nsIThreadRetargetableStreamListener.h"
michael@0 14 #include "nsIPrincipal.h"
michael@0 15
michael@0 16 #include "nsAutoPtr.h"
michael@0 17 #include "nsCOMPtr.h"
michael@0 18 #include "nsProxyRelease.h"
michael@0 19 #include "nsStringGlue.h"
michael@0 20 #include "nsError.h"
michael@0 21 #include "nsIAsyncVerifyRedirectCallback.h"
michael@0 22
michael@0 23 class imgCacheValidator;
michael@0 24 class imgStatusTracker;
michael@0 25 class imgLoader;
michael@0 26 class imgRequestProxy;
michael@0 27 class imgCacheEntry;
michael@0 28 class imgMemoryReporter;
michael@0 29 class imgRequestNotifyRunnable;
michael@0 30 class nsIApplicationCache;
michael@0 31 class nsIProperties;
michael@0 32 class nsIRequest;
michael@0 33 class nsITimedChannel;
michael@0 34 class nsIURI;
michael@0 35
michael@0 36 namespace mozilla {
michael@0 37 namespace image {
michael@0 38 class Image;
michael@0 39 class ImageURL;
michael@0 40 } // namespace image
michael@0 41 } // namespace mozilla
michael@0 42
michael@0 43 class imgRequest : public nsIStreamListener,
michael@0 44 public nsIThreadRetargetableStreamListener,
michael@0 45 public nsIChannelEventSink,
michael@0 46 public nsIInterfaceRequestor,
michael@0 47 public nsIAsyncVerifyRedirectCallback
michael@0 48 {
michael@0 49 public:
michael@0 50 typedef mozilla::image::ImageURL ImageURL;
michael@0 51 imgRequest(imgLoader* aLoader);
michael@0 52 virtual ~imgRequest();
michael@0 53
michael@0 54 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 55
michael@0 56 nsresult Init(nsIURI *aURI,
michael@0 57 nsIURI *aCurrentURI,
michael@0 58 nsIURI *aFirstPartyIsolationURI,
michael@0 59 nsIRequest *aRequest,
michael@0 60 nsIChannel *aChannel,
michael@0 61 imgCacheEntry *aCacheEntry,
michael@0 62 void *aLoadId,
michael@0 63 nsIPrincipal* aLoadingPrincipal,
michael@0 64 int32_t aCORSMode);
michael@0 65
michael@0 66 // Callers must call imgRequestProxy::Notify later.
michael@0 67 void AddProxy(imgRequestProxy *proxy);
michael@0 68
michael@0 69 nsresult RemoveProxy(imgRequestProxy *proxy, nsresult aStatus);
michael@0 70
michael@0 71 // Cancel, but also ensure that all work done in Init() is undone. Call this
michael@0 72 // only when the channel has failed to open, and so calling Cancel() on it
michael@0 73 // won't be sufficient.
michael@0 74 void CancelAndAbort(nsresult aStatus);
michael@0 75
michael@0 76 // Called or dispatched by cancel for main thread only execution.
michael@0 77 void ContinueCancel(nsresult aStatus);
michael@0 78
michael@0 79 // Methods that get forwarded to the Image, or deferred until it's
michael@0 80 // instantiated.
michael@0 81 nsresult LockImage();
michael@0 82 nsresult UnlockImage();
michael@0 83 nsresult StartDecoding();
michael@0 84 nsresult RequestDecode();
michael@0 85
michael@0 86 inline void SetInnerWindowID(uint64_t aInnerWindowId) {
michael@0 87 mInnerWindowId = aInnerWindowId;
michael@0 88 }
michael@0 89
michael@0 90 inline uint64_t InnerWindowID() const {
michael@0 91 return mInnerWindowId;
michael@0 92 }
michael@0 93
michael@0 94 // Set the cache validation information (expiry time, whether we must
michael@0 95 // validate, etc) on the cache entry based on the request information.
michael@0 96 // If this function is called multiple times, the information set earliest
michael@0 97 // wins.
michael@0 98 static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest);
michael@0 99
michael@0 100 // Check if application cache of the original load is different from
michael@0 101 // application cache of the new load. Also lack of application cache
michael@0 102 // on one of the loads is considered a change of a loading cache since
michael@0 103 // HTTP cache may contain a different data then app cache.
michael@0 104 bool CacheChanged(nsIRequest* aNewRequest);
michael@0 105
michael@0 106 bool GetMultipart() const { return mIsMultiPartChannel; }
michael@0 107
michael@0 108 // The CORS mode for which we loaded this image.
michael@0 109 int32_t GetCORSMode() const { return mCORSMode; }
michael@0 110
michael@0 111 // The principal for the document that loaded this image. Used when trying to
michael@0 112 // validate a CORS image load.
michael@0 113 already_AddRefed<nsIPrincipal> GetLoadingPrincipal() const
michael@0 114 {
michael@0 115 nsCOMPtr<nsIPrincipal> principal = mLoadingPrincipal;
michael@0 116 return principal.forget();
michael@0 117 }
michael@0 118
michael@0 119 // Return the imgStatusTracker associated with this imgRequest. It may live
michael@0 120 // in |mStatusTracker| or in |mImage.mStatusTracker|, depending on whether
michael@0 121 // mImage has been instantiated yet.
michael@0 122 already_AddRefed<imgStatusTracker> GetStatusTracker();
michael@0 123
michael@0 124 // Get the current principal of the image. No AddRefing.
michael@0 125 inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); }
michael@0 126
michael@0 127 // Resize the cache entry to 0 if it exists
michael@0 128 void ResetCacheEntry();
michael@0 129
michael@0 130 // Update the cache entry size based on the image container
michael@0 131 void UpdateCacheEntrySize();
michael@0 132
michael@0 133 // OK to use on any thread.
michael@0 134 nsresult GetURI(ImageURL **aURI);
michael@0 135
michael@0 136 private:
michael@0 137 friend class imgCacheEntry;
michael@0 138 friend class imgRequestProxy;
michael@0 139 friend class imgLoader;
michael@0 140 friend class imgCacheValidator;
michael@0 141 friend class imgStatusTracker;
michael@0 142 friend class imgCacheExpirationTracker;
michael@0 143 friend class imgRequestNotifyRunnable;
michael@0 144
michael@0 145 inline void SetLoadId(void *aLoadId) {
michael@0 146 mLoadId = aLoadId;
michael@0 147 }
michael@0 148 void Cancel(nsresult aStatus);
michael@0 149 void RemoveFromCache();
michael@0 150
michael@0 151 nsresult GetSecurityInfo(nsISupports **aSecurityInfo);
michael@0 152
michael@0 153 inline const char *GetMimeType() const {
michael@0 154 return mContentType.get();
michael@0 155 }
michael@0 156 inline nsIProperties *Properties() {
michael@0 157 return mProperties;
michael@0 158 }
michael@0 159
michael@0 160 // Reset the cache entry after we've dropped our reference to it. Used by the
michael@0 161 // imgLoader when our cache entry is re-requested after we've dropped our
michael@0 162 // reference to it.
michael@0 163 void SetCacheEntry(imgCacheEntry *entry);
michael@0 164
michael@0 165 // Returns whether we've got a reference to the cache entry.
michael@0 166 bool HasCacheEntry() const;
michael@0 167
michael@0 168 // Return the priority of the underlying network request, or return
michael@0 169 // PRIORITY_NORMAL if it doesn't support nsISupportsPriority.
michael@0 170 int32_t Priority() const;
michael@0 171
michael@0 172 // Adjust the priority of the underlying network request by the given delta
michael@0 173 // on behalf of the given proxy.
michael@0 174 void AdjustPriority(imgRequestProxy *aProxy, int32_t aDelta);
michael@0 175
michael@0 176 // Return whether we've seen some data at this point
michael@0 177 bool HasTransferredData() const { return mGotData; }
michael@0 178
michael@0 179 // Set whether this request is stored in the cache. If it isn't, regardless
michael@0 180 // of whether this request has a non-null mCacheEntry, this imgRequest won't
michael@0 181 // try to update or modify the image cache.
michael@0 182 void SetIsInCache(bool cacheable);
michael@0 183
michael@0 184 bool IsBlockingOnload() const;
michael@0 185 void SetBlockingOnload(bool block) const;
michael@0 186
michael@0 187 public:
michael@0 188 NS_DECL_NSISTREAMLISTENER
michael@0 189 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
michael@0 190 NS_DECL_NSIREQUESTOBSERVER
michael@0 191 NS_DECL_NSICHANNELEVENTSINK
michael@0 192 NS_DECL_NSIINTERFACEREQUESTOR
michael@0 193 NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
michael@0 194
michael@0 195 // Sets properties for this image; will dispatch to main thread if needed.
michael@0 196 void SetProperties(nsIChannel* aChan);
michael@0 197
michael@0 198 private:
michael@0 199 friend class imgMemoryReporter;
michael@0 200
michael@0 201 // Weak reference to parent loader; this request cannot outlive its owner.
michael@0 202 imgLoader* mLoader;
michael@0 203 nsCOMPtr<nsIRequest> mRequest;
michael@0 204 // The original URI we were loaded with. This is the same as the URI we are
michael@0 205 // keyed on in the cache. We store a string here to avoid off main thread
michael@0 206 // refcounting issues with nsStandardURL.
michael@0 207 nsRefPtr<ImageURL> mURI;
michael@0 208 // The URI of the resource we ended up loading after all redirects, etc.
michael@0 209 nsCOMPtr<nsIURI> mCurrentURI;
michael@0 210 // The first party that triggered the load -- for cookie + cache isolation
michael@0 211 nsCOMPtr<nsIURI> mFirstPartyIsolationURI;
michael@0 212 // The principal of the document which loaded this image. Used when validating for CORS.
michael@0 213 nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
michael@0 214 // The principal of this image.
michael@0 215 nsCOMPtr<nsIPrincipal> mPrincipal;
michael@0 216 // Status-tracker -- transferred to mImage, when it gets instantiated
michael@0 217 nsRefPtr<imgStatusTracker> mStatusTracker;
michael@0 218 nsRefPtr<mozilla::image::Image> mImage;
michael@0 219 nsCOMPtr<nsIProperties> mProperties;
michael@0 220 nsCOMPtr<nsISupports> mSecurityInfo;
michael@0 221 nsCOMPtr<nsIChannel> mChannel;
michael@0 222 nsCOMPtr<nsIInterfaceRequestor> mPrevChannelSink;
michael@0 223 nsCOMPtr<nsIApplicationCache> mApplicationCache;
michael@0 224
michael@0 225 nsCOMPtr<nsITimedChannel> mTimedChannel;
michael@0 226
michael@0 227 nsCString mContentType;
michael@0 228
michael@0 229 nsRefPtr<imgCacheEntry> mCacheEntry; /* we hold on to this to this so long as we have observers */
michael@0 230
michael@0 231 void *mLoadId;
michael@0 232
michael@0 233 imgCacheValidator *mValidator;
michael@0 234 nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
michael@0 235 nsCOMPtr<nsIChannel> mNewRedirectChannel;
michael@0 236
michael@0 237 // The ID of the inner window origin, used for error reporting.
michael@0 238 uint64_t mInnerWindowId;
michael@0 239
michael@0 240 // The CORS mode (defined in imgIRequest) this image was loaded with. By
michael@0 241 // default, imgIRequest::CORS_NONE.
michael@0 242 int32_t mCORSMode;
michael@0 243
michael@0 244 // Sometimes consumers want to do things before the image is ready. Let them,
michael@0 245 // and apply the action when the image becomes available.
michael@0 246 bool mDecodeRequested : 1;
michael@0 247
michael@0 248 bool mIsMultiPartChannel : 1;
michael@0 249 bool mGotData : 1;
michael@0 250 bool mIsInCache : 1;
michael@0 251 bool mBlockingOnload : 1;
michael@0 252 bool mResniffMimeType : 1;
michael@0 253 };
michael@0 254
michael@0 255 #endif

mercurial