image/src/imgRequestProxy.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 imgRequestProxy_h__
michael@0 8 #define imgRequestProxy_h__
michael@0 9
michael@0 10 #include "mozilla/WeakPtr.h"
michael@0 11 #include "imgIRequest.h"
michael@0 12 #include "nsISecurityInfoProvider.h"
michael@0 13
michael@0 14 #include "nsILoadGroup.h"
michael@0 15 #include "nsISupportsPriority.h"
michael@0 16 #include "nsITimedChannel.h"
michael@0 17 #include "nsCOMPtr.h"
michael@0 18 #include "nsAutoPtr.h"
michael@0 19 #include "nsThreadUtils.h"
michael@0 20 #include "mozilla/TimeStamp.h"
michael@0 21
michael@0 22 #include "imgRequest.h"
michael@0 23
michael@0 24 #define NS_IMGREQUESTPROXY_CID \
michael@0 25 { /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
michael@0 26 0x20557898, \
michael@0 27 0x1dd2, \
michael@0 28 0x11b2, \
michael@0 29 {0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \
michael@0 30 }
michael@0 31
michael@0 32 class imgINotificationObserver;
michael@0 33 class imgRequestNotifyRunnable;
michael@0 34 class imgStatusNotifyRunnable;
michael@0 35 class nsIntRect;
michael@0 36 class ProxyBehaviour;
michael@0 37
michael@0 38 namespace mozilla {
michael@0 39 namespace image {
michael@0 40 class Image;
michael@0 41 class ImageURL;
michael@0 42 } // namespace image
michael@0 43 } // namespace mozilla
michael@0 44
michael@0 45 class imgRequestProxy : public imgIRequest,
michael@0 46 public nsISupportsPriority,
michael@0 47 public nsISecurityInfoProvider,
michael@0 48 public nsITimedChannel,
michael@0 49 public mozilla::SupportsWeakPtr<imgRequestProxy>
michael@0 50 {
michael@0 51 public:
michael@0 52 MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
michael@0 53 typedef mozilla::image::ImageURL ImageURL;
michael@0 54 NS_DECL_ISUPPORTS
michael@0 55 NS_DECL_IMGIREQUEST
michael@0 56 NS_DECL_NSIREQUEST
michael@0 57 NS_DECL_NSISUPPORTSPRIORITY
michael@0 58 NS_DECL_NSISECURITYINFOPROVIDER
michael@0 59 // nsITimedChannel declared below
michael@0 60
michael@0 61 imgRequestProxy();
michael@0 62 virtual ~imgRequestProxy();
michael@0 63
michael@0 64 // Callers to Init or ChangeOwner are required to call NotifyListener after
michael@0 65 // (although not immediately after) doing so.
michael@0 66 nsresult Init(imgRequest* aOwner,
michael@0 67 nsILoadGroup *aLoadGroup,
michael@0 68 ImageURL* aURI,
michael@0 69 imgINotificationObserver *aObserver);
michael@0 70
michael@0 71 nsresult ChangeOwner(imgRequest *aNewOwner); // this will change mOwner. Do not call this if the previous
michael@0 72 // owner has already sent notifications out!
michael@0 73
michael@0 74 void AddToLoadGroup();
michael@0 75 void RemoveFromLoadGroup(bool releaseLoadGroup);
michael@0 76
michael@0 77 inline bool HasObserver() const {
michael@0 78 return mListener != nullptr;
michael@0 79 }
michael@0 80
michael@0 81 // Asynchronously notify this proxy's listener of the current state of the
michael@0 82 // image, and, if we have an imgRequest mOwner, any status changes that
michael@0 83 // happen between the time this function is called and the time the
michael@0 84 // notification is scheduled.
michael@0 85 void NotifyListener();
michael@0 86
michael@0 87 // Synchronously notify this proxy's listener of the current state of the
michael@0 88 // image. Only use this function if you are currently servicing an
michael@0 89 // asynchronously-called function.
michael@0 90 void SyncNotifyListener();
michael@0 91
michael@0 92 // Whether we want notifications from imgStatusTracker to be deferred until
michael@0 93 // an event it has scheduled has been fired.
michael@0 94 bool NotificationsDeferred() const
michael@0 95 {
michael@0 96 return mDeferNotifications;
michael@0 97 }
michael@0 98 void SetNotificationsDeferred(bool aDeferNotifications)
michael@0 99 {
michael@0 100 mDeferNotifications = aDeferNotifications;
michael@0 101 }
michael@0 102
michael@0 103 // XXXbholley - This eventually gets folded into the new notification API.
michael@0 104 void SetHasImage();
michael@0 105
michael@0 106 // Removes all animation consumers that were created with
michael@0 107 // IncrementAnimationConsumers. This is necessary since we need
michael@0 108 // to do it before the proxy itself is destroyed. See
michael@0 109 // imgRequest::RemoveProxy
michael@0 110 void ClearAnimationConsumers();
michael@0 111
michael@0 112 virtual nsresult Clone(imgINotificationObserver* aObserver, imgRequestProxy** aClone);
michael@0 113 nsresult GetStaticRequest(imgRequestProxy** aReturn);
michael@0 114
michael@0 115 nsresult GetURI(ImageURL **aURI);
michael@0 116
michael@0 117 protected:
michael@0 118 friend class imgStatusTracker;
michael@0 119 friend class imgStatusNotifyRunnable;
michael@0 120 friend class imgRequestNotifyRunnable;
michael@0 121
michael@0 122 class imgCancelRunnable;
michael@0 123 friend class imgCancelRunnable;
michael@0 124
michael@0 125 class imgCancelRunnable : public nsRunnable
michael@0 126 {
michael@0 127 public:
michael@0 128 imgCancelRunnable(imgRequestProxy* owner, nsresult status)
michael@0 129 : mOwner(owner), mStatus(status)
michael@0 130 {}
michael@0 131
michael@0 132 NS_IMETHOD Run() {
michael@0 133 mOwner->DoCancel(mStatus);
michael@0 134 return NS_OK;
michael@0 135 }
michael@0 136
michael@0 137 private:
michael@0 138 nsRefPtr<imgRequestProxy> mOwner;
michael@0 139 nsresult mStatus;
michael@0 140 };
michael@0 141
michael@0 142 // The following notification functions are protected to ensure that (friend
michael@0 143 // class) imgStatusTracker is the only class allowed to send us
michael@0 144 // notifications.
michael@0 145
michael@0 146 /* non-virtual imgDecoderObserver methods */
michael@0 147 void OnStartDecode ();
michael@0 148 void OnStartContainer ();
michael@0 149 void OnFrameUpdate (const nsIntRect * aRect);
michael@0 150 void OnStopFrame ();
michael@0 151 void OnStopDecode ();
michael@0 152 void OnDiscard ();
michael@0 153 void OnUnlockedDraw ();
michael@0 154 void OnImageIsAnimated ();
michael@0 155
michael@0 156 /* non-virtual sort-of-nsIRequestObserver methods */
michael@0 157 void OnStartRequest();
michael@0 158 void OnStopRequest(bool aLastPart);
michael@0 159
michael@0 160 /* non-virtual imgIOnloadBlocker methods */
michael@0 161 void BlockOnload();
michael@0 162 void UnblockOnload();
michael@0 163
michael@0 164 /* Finish up canceling ourselves */
michael@0 165 void DoCancel(nsresult status);
michael@0 166
michael@0 167 /* Do the proper refcount management to null out mListener */
michael@0 168 void NullOutListener();
michael@0 169
michael@0 170 void DoRemoveFromLoadGroup() {
michael@0 171 RemoveFromLoadGroup(true);
michael@0 172 }
michael@0 173
michael@0 174 // Return the imgStatusTracker associated with mOwner and/or mImage. It may
michael@0 175 // live either on mOwner or mImage, depending on whether
michael@0 176 // (a) we have an mOwner at all
michael@0 177 // (b) whether mOwner has instantiated its image yet
michael@0 178 already_AddRefed<imgStatusTracker> GetStatusTracker() const;
michael@0 179
michael@0 180 nsITimedChannel* TimedChannel()
michael@0 181 {
michael@0 182 if (!GetOwner())
michael@0 183 return nullptr;
michael@0 184 return GetOwner()->mTimedChannel;
michael@0 185 }
michael@0 186
michael@0 187 already_AddRefed<mozilla::image::Image> GetImage() const;
michael@0 188 bool HasImage() const;
michael@0 189 imgRequest* GetOwner() const;
michael@0 190
michael@0 191 nsresult PerformClone(imgINotificationObserver* aObserver,
michael@0 192 imgRequestProxy* (aAllocFn)(imgRequestProxy*),
michael@0 193 imgRequestProxy** aClone);
michael@0 194
michael@0 195 public:
michael@0 196 NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
michael@0 197
michael@0 198 protected:
michael@0 199 nsAutoPtr<ProxyBehaviour> mBehaviour;
michael@0 200
michael@0 201 private:
michael@0 202 friend class imgCacheValidator;
michael@0 203 friend imgRequestProxy* NewStaticProxy(imgRequestProxy* aThis);
michael@0 204
michael@0 205 // The URI of our request.
michael@0 206 nsRefPtr<ImageURL> mURI;
michael@0 207
michael@0 208 // mListener is only promised to be a weak ref (see imgILoader.idl),
michael@0 209 // but we actually keep a strong ref to it until we've seen our
michael@0 210 // first OnStopRequest.
michael@0 211 imgINotificationObserver* mListener;
michael@0 212 nsCOMPtr<nsILoadGroup> mLoadGroup;
michael@0 213
michael@0 214 nsLoadFlags mLoadFlags;
michael@0 215 uint32_t mLockCount;
michael@0 216 uint32_t mAnimationConsumers;
michael@0 217 bool mCanceled;
michael@0 218 bool mIsInLoadGroup;
michael@0 219 bool mListenerIsStrongRef;
michael@0 220 bool mDecodeRequested;
michael@0 221
michael@0 222 // Whether we want to defer our notifications by the non-virtual Observer
michael@0 223 // interfaces as image loads proceed.
michael@0 224 bool mDeferNotifications;
michael@0 225
michael@0 226 // We only want to send OnStartContainer once for each proxy, but we might
michael@0 227 // get multiple OnStartContainer calls.
michael@0 228 bool mSentStartContainer;
michael@0 229 };
michael@0 230
michael@0 231 // Used for static image proxies for which no requests are available, so
michael@0 232 // certain behaviours must be overridden to compensate.
michael@0 233 class imgRequestProxyStatic : public imgRequestProxy
michael@0 234 {
michael@0 235
michael@0 236 public:
michael@0 237 imgRequestProxyStatic(mozilla::image::Image* aImage,
michael@0 238 nsIPrincipal* aPrincipal);
michael@0 239
michael@0 240 NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal) MOZ_OVERRIDE;
michael@0 241
michael@0 242 using imgRequestProxy::Clone;
michael@0 243
michael@0 244 virtual nsresult Clone(imgINotificationObserver* aObserver,
michael@0 245 imgRequestProxy** aClone) MOZ_OVERRIDE;
michael@0 246
michael@0 247 protected:
michael@0 248 friend imgRequestProxy* NewStaticProxy(imgRequestProxy*);
michael@0 249
michael@0 250 // Our principal. We have to cache it, rather than accessing the underlying
michael@0 251 // request on-demand, because static proxies don't have an underlying request.
michael@0 252 nsCOMPtr<nsIPrincipal> mPrincipal;
michael@0 253 };
michael@0 254
michael@0 255 #endif // imgRequestProxy_h__

mercurial