2010-05-14 13:47:59 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2014-08-22 13:12:38 -07:00
|
|
|
#include "ImageLogging.h"
|
2010-05-14 13:47:59 -07:00
|
|
|
#include "imgStatusTracker.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgRequestProxy.h"
|
2012-12-18 08:37:15 -08:00
|
|
|
#include "imgDecoderObserver.h"
|
2010-08-13 21:09:48 -07:00
|
|
|
#include "Image.h"
|
2013-09-28 11:28:42 -07:00
|
|
|
#include "nsNetUtil.h"
|
2012-10-12 09:11:21 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-10-11 18:34:22 -07:00
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-10-12 09:11:21 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-10-12 09:11:20 -07:00
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
using namespace mozilla::image;
|
2013-12-12 13:17:35 -08:00
|
|
|
using mozilla::WeakPtr;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
class imgStatusTrackerObserver : public imgDecoderObserver
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 09:20:24 -07:00
|
|
|
explicit imgStatusTrackerObserver(imgStatusTracker* aTracker)
|
2014-07-30 12:52:05 -07:00
|
|
|
: mTracker(aTracker)
|
2013-09-28 11:28:44 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTracker);
|
|
|
|
}
|
2013-01-02 09:00:50 -08:00
|
|
|
|
2013-09-28 11:28:44 -07:00
|
|
|
void SetTracker(imgStatusTracker* aTracker)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTracker);
|
2014-07-30 12:52:05 -07:00
|
|
|
mTracker = aTracker;
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** imgDecoderObserver methods **/
|
|
|
|
|
|
|
|
virtual void OnStartDecode() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartDecode");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordStartDecode();
|
|
|
|
if (!tracker->IsMultipart()) {
|
|
|
|
tracker->RecordBlockOnload();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartRequest() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("imgStatusTrackerObserver(imgDecoderObserver)::OnStartRequest");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartContainer() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartContainer");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
nsRefPtr<Image> image = tracker->GetImage();;
|
|
|
|
tracker->RecordStartContainer(image);
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartFrame() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartFrame");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordStartFrame();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FrameChanged(const nsIntRect* dirtyRect) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::FrameChanged");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordFrameChanged(dirtyRect);
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStopFrame() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStopFrame");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordStopFrame();
|
|
|
|
tracker->RecordUnblockOnload();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStopDecode(nsresult aStatus) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStopDecode");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordStopDecode(aStatus);
|
2013-01-02 09:00:50 -08:00
|
|
|
|
|
|
|
// This is really hacky. We need to handle the case where we start decoding,
|
|
|
|
// block onload, but then hit an error before we get to our first frame.
|
2013-09-28 11:28:44 -07:00
|
|
|
tracker->RecordUnblockOnload();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
virtual void OnStopRequest(bool aLastPart, nsresult aStatus) MOZ_OVERRIDE
|
2013-01-02 09:00:50 -08:00
|
|
|
{
|
2013-02-01 17:06:34 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStopRequest");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordStopRequest(aLastPart, aStatus);
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDiscard() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnDiscard");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordDiscard();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnUnlockedDraw() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnUnlockedDraw");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
2013-09-28 11:28:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(tracker->HasImage(),
|
2013-01-02 09:00:50 -08:00
|
|
|
"OnUnlockedDraw callback before we've created our image");
|
2013-09-28 11:28:44 -07:00
|
|
|
tracker->RecordUnlockedDraw();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnImageIsAnimated() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnImageIsAnimated");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordImageIsAnimated();
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
virtual void OnError() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnError");
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
|
|
|
|
if (!tracker) { return; }
|
|
|
|
tracker->RecordError();
|
2013-02-01 17:06:34 -08:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:32:23 -07:00
|
|
|
protected:
|
|
|
|
virtual ~imgStatusTrackerObserver() {}
|
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
private:
|
2013-12-12 13:17:35 -08:00
|
|
|
WeakPtr<imgStatusTracker> mTracker;
|
2013-01-02 09:00:50 -08:00
|
|
|
};
|
2012-10-12 09:11:21 -07:00
|
|
|
|
|
|
|
// imgStatusTracker methods
|
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
imgStatusTracker::imgStatusTracker(Image* aImage)
|
2010-05-14 13:47:59 -07:00
|
|
|
: mImage(aImage),
|
|
|
|
mState(0),
|
|
|
|
mImageStatus(imgIRequest::STATUS_NONE),
|
2012-12-19 13:28:54 -08:00
|
|
|
mIsMultipart(false),
|
2013-04-18 16:31:46 -07:00
|
|
|
mHadLastPart(false),
|
|
|
|
mHasBeenDecoded(false)
|
2013-01-18 13:47:18 -08:00
|
|
|
{
|
|
|
|
mTrackerObserver = new imgStatusTrackerObserver(this);
|
|
|
|
}
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
// Private, used only by CloneForRecording.
|
2010-08-12 08:59:28 -07:00
|
|
|
imgStatusTracker::imgStatusTracker(const imgStatusTracker& aOther)
|
|
|
|
: mImage(aOther.mImage),
|
|
|
|
mState(aOther.mState),
|
|
|
|
mImageStatus(aOther.mImageStatus),
|
2012-12-19 13:28:54 -08:00
|
|
|
mIsMultipart(aOther.mIsMultipart),
|
2013-04-30 16:35:00 -07:00
|
|
|
mHadLastPart(aOther.mHadLastPart),
|
|
|
|
mHasBeenDecoded(aOther.mHasBeenDecoded)
|
2013-01-18 13:47:17 -08:00
|
|
|
// Note: we explicitly don't copy several fields:
|
|
|
|
// - mRequestRunnable, because it won't be nulled out when the
|
|
|
|
// mRequestRunnable's Run function eventually gets called.
|
|
|
|
// - mProperties, because we don't need it and it'd just point at the same
|
|
|
|
// object
|
|
|
|
// - mConsumers, because we don't need to talk to consumers
|
|
|
|
// - mInvalidRect, because the point of it is to be fired off and reset
|
2013-01-18 13:47:18 -08:00
|
|
|
{
|
|
|
|
mTrackerObserver = new imgStatusTrackerObserver(this);
|
|
|
|
}
|
2010-08-12 08:59:28 -07:00
|
|
|
|
2012-12-18 08:37:14 -08:00
|
|
|
imgStatusTracker::~imgStatusTracker()
|
|
|
|
{}
|
|
|
|
|
2013-09-28 11:28:44 -07:00
|
|
|
imgStatusTrackerInit::imgStatusTrackerInit(mozilla::image::Image* aImage,
|
|
|
|
imgStatusTracker* aTracker)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aImage);
|
|
|
|
|
|
|
|
if (aTracker) {
|
|
|
|
mTracker = aTracker;
|
|
|
|
mTracker->SetImage(aImage);
|
|
|
|
} else {
|
|
|
|
mTracker = new imgStatusTracker(aImage);
|
|
|
|
}
|
|
|
|
aImage->SetStatusTracker(mTracker);
|
|
|
|
MOZ_ASSERT(mTracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
imgStatusTrackerInit::~imgStatusTrackerInit()
|
|
|
|
{
|
|
|
|
mTracker->ResetImage();
|
|
|
|
}
|
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::SetImage(Image* aImage)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aImage, "Setting null image");
|
|
|
|
NS_ABORT_IF_FALSE(!mImage, "Setting image when we already have one");
|
|
|
|
mImage = aImage;
|
|
|
|
}
|
|
|
|
|
2013-09-28 11:28:44 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::ResetImage()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mImage, "Resetting image when it's already null!");
|
|
|
|
mImage = nullptr;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-05-14 13:47:59 -07:00
|
|
|
imgStatusTracker::IsLoading() const
|
|
|
|
{
|
|
|
|
// Checking for whether OnStopRequest has fired allows us to say we're
|
|
|
|
// loading before OnStartRequest gets called, letting the request properly
|
|
|
|
// get removed from the cache in certain cases.
|
|
|
|
return !(mState & stateRequestStopped);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2010-05-14 13:47:59 -07:00
|
|
|
imgStatusTracker::GetImageStatus() const
|
|
|
|
{
|
|
|
|
return mImageStatus;
|
|
|
|
}
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
// A helper class to allow us to call SyncNotify asynchronously.
|
|
|
|
class imgRequestNotifyRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-09-28 11:28:44 -07:00
|
|
|
imgRequestNotifyRunnable(imgStatusTracker* aTracker,
|
|
|
|
imgRequestProxy* aRequestProxy)
|
2012-12-19 13:28:54 -08:00
|
|
|
: mTracker(aTracker)
|
2010-08-12 08:59:28 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be created on the main thread");
|
|
|
|
MOZ_ASSERT(aRequestProxy, "aRequestProxy should not be null");
|
|
|
|
MOZ_ASSERT(aTracker, "aTracker should not be null");
|
2012-12-19 13:28:54 -08:00
|
|
|
mProxies.AppendElement(aRequestProxy);
|
2010-08-12 08:59:28 -07:00
|
|
|
}
|
2010-07-28 14:52:14 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
|
|
|
|
MOZ_ASSERT(mTracker, "mTracker should not be null");
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mProxies.Length(); ++i) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mProxies[i]->SetNotificationsDeferred(false);
|
2012-12-19 13:28:54 -08:00
|
|
|
mTracker->SyncNotify(mProxies[i]);
|
2010-08-12 08:59:28 -07:00
|
|
|
}
|
2010-07-28 14:52:14 -07:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
mTracker->mRequestRunnable = nullptr;
|
2010-07-28 14:52:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-12 08:59:28 -07:00
|
|
|
void AddProxy(imgRequestProxy* aRequestProxy)
|
|
|
|
{
|
|
|
|
mProxies.AppendElement(aRequestProxy);
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
void RemoveProxy(imgRequestProxy* aRequestProxy)
|
|
|
|
{
|
|
|
|
mProxies.RemoveElement(aRequestProxy);
|
|
|
|
}
|
|
|
|
|
2010-07-28 14:52:14 -07:00
|
|
|
private:
|
2010-08-12 08:59:28 -07:00
|
|
|
friend class imgStatusTracker;
|
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
nsRefPtr<imgStatusTracker> mTracker;
|
|
|
|
nsTArray< nsRefPtr<imgRequestProxy> > mProxies;
|
2010-07-28 14:52:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2012-12-19 13:28:54 -08:00
|
|
|
imgStatusTracker::Notify(imgRequestProxy* proxy)
|
2010-07-28 14:52:14 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "imgRequestProxy is not threadsafe");
|
2010-07-28 14:52:34 -07:00
|
|
|
#ifdef PR_LOGGING
|
2013-09-28 11:28:44 -07:00
|
|
|
if (mImage && mImage->GetURI()) {
|
|
|
|
nsRefPtr<ImageURL> uri(mImage->GetURI());
|
2012-12-19 13:28:54 -08:00
|
|
|
nsAutoCString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgStatusTracker::Notify async", "uri", spec.get());
|
|
|
|
} else {
|
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgStatusTracker::Notify async", "uri", "<unknown>");
|
|
|
|
}
|
2010-07-28 14:52:34 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
proxy->SetNotificationsDeferred(true);
|
2010-07-28 14:52:14 -07:00
|
|
|
|
2010-08-12 08:59:28 -07:00
|
|
|
// If we have an existing runnable that we can use, we just append this proxy
|
|
|
|
// to its list of proxies to be notified. This ensures we don't unnecessarily
|
|
|
|
// delay onload.
|
|
|
|
imgRequestNotifyRunnable* runnable = static_cast<imgRequestNotifyRunnable*>(mRequestRunnable.get());
|
2012-12-19 13:28:54 -08:00
|
|
|
if (runnable) {
|
2010-08-12 08:59:28 -07:00
|
|
|
runnable->AddProxy(proxy);
|
|
|
|
} else {
|
2012-12-19 13:28:54 -08:00
|
|
|
mRequestRunnable = new imgRequestNotifyRunnable(this, proxy);
|
2010-08-12 08:59:28 -07:00
|
|
|
NS_DispatchToCurrentThread(mRequestRunnable);
|
|
|
|
}
|
2010-07-28 14:52:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// A helper class to allow us to call SyncNotify asynchronously for a given,
|
|
|
|
// fixed, state.
|
|
|
|
class imgStatusNotifyRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-09-28 11:28:44 -07:00
|
|
|
imgStatusNotifyRunnable(imgStatusTracker* statusTracker,
|
2010-07-28 14:52:14 -07:00
|
|
|
imgRequestProxy* requestproxy)
|
2013-09-28 11:28:44 -07:00
|
|
|
: mStatusTracker(statusTracker), mProxy(requestproxy)
|
2013-09-28 11:28:43 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be created on the main thread");
|
|
|
|
MOZ_ASSERT(requestproxy, "requestproxy cannot be null");
|
2013-09-28 11:28:44 -07:00
|
|
|
MOZ_ASSERT(statusTracker, "status should not be null");
|
|
|
|
mImage = statusTracker->GetImage();
|
2013-09-28 11:28:43 -07:00
|
|
|
}
|
2010-07-28 14:52:14 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
|
2011-10-17 07:59:28 -07:00
|
|
|
mProxy->SetNotificationsDeferred(false);
|
2010-07-28 14:52:14 -07:00
|
|
|
|
2013-09-28 11:28:44 -07:00
|
|
|
mStatusTracker->SyncNotify(mProxy);
|
2010-07-28 14:52:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<imgStatusTracker> mStatusTracker;
|
2010-07-28 14:52:14 -07:00
|
|
|
// We have to hold on to a reference to the tracker's image, just in case
|
|
|
|
// it goes away while we're in the event queue.
|
2010-08-13 21:09:49 -07:00
|
|
|
nsRefPtr<Image> mImage;
|
2010-07-28 14:52:14 -07:00
|
|
|
nsRefPtr<imgRequestProxy> mProxy;
|
|
|
|
};
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
2010-07-28 14:52:14 -07:00
|
|
|
imgStatusTracker::NotifyCurrentState(imgRequestProxy* proxy)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "imgRequestProxy is not threadsafe");
|
2010-07-28 14:52:34 -07:00
|
|
|
#ifdef PR_LOGGING
|
2013-09-28 11:28:42 -07:00
|
|
|
nsRefPtr<ImageURL> uri;
|
2010-07-28 14:52:34 -07:00
|
|
|
proxy->GetURI(getter_AddRefs(uri));
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2010-07-28 14:52:34 -07:00
|
|
|
uri->GetSpec(spec);
|
2012-10-29 16:32:10 -07:00
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgStatusTracker::NotifyCurrentState", "uri", spec.get());
|
2010-07-28 14:52:34 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
proxy->SetNotificationsDeferred(true);
|
2010-07-28 14:52:14 -07:00
|
|
|
|
2013-03-29 13:14:19 -07:00
|
|
|
// We don't keep track of
|
2013-09-28 11:28:44 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new imgStatusNotifyRunnable(this, proxy);
|
2010-07-28 14:52:14 -07:00
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
#define NOTIFY_IMAGE_OBSERVERS(func) \
|
|
|
|
do { \
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(proxies); \
|
2013-01-18 13:47:18 -08:00
|
|
|
while (iter.HasMore()) { \
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get(); \
|
|
|
|
if (proxy && !proxy->NotificationsDeferred()) { \
|
2013-01-18 13:47:18 -08:00
|
|
|
proxy->func; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (false);
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
/* static */ void
|
2013-12-12 13:17:35 -08:00
|
|
|
imgStatusTracker::SyncNotifyState(ProxyArray& proxies,
|
2013-01-18 13:47:18 -08:00
|
|
|
bool hasImage, uint32_t state,
|
|
|
|
nsIntRect& dirtyRect, bool hadLastPart)
|
2010-07-28 14:52:14 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-05-14 13:47:59 -07:00
|
|
|
// OnStartRequest
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateRequestStarted)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStartRequest());
|
2010-05-14 13:47:59 -07:00
|
|
|
|
|
|
|
// OnStartContainer
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateHasSize)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStartContainer());
|
2012-10-11 18:58:24 -07:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
// OnStartDecode
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateDecodeStarted)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStartDecode());
|
2012-12-19 13:28:54 -08:00
|
|
|
|
2012-08-13 15:58:53 -07:00
|
|
|
// BlockOnload
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateBlockingOnload)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(BlockOnload());
|
2012-08-13 15:58:53 -07:00
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
if (hasImage) {
|
2013-01-18 13:47:17 -08:00
|
|
|
// OnFrameUpdate
|
2012-12-17 14:05:18 -08:00
|
|
|
// If there's any content in this frame at all (always true for
|
|
|
|
// vector images, true for raster images that have decoded at
|
|
|
|
// least one frame) then send OnFrameUpdate.
|
2013-01-18 13:47:17 -08:00
|
|
|
if (!dirtyRect.IsEmpty())
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnFrameUpdate(&dirtyRect));
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateFrameStopped)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStopFrame());
|
2011-11-09 13:39:15 -08:00
|
|
|
|
|
|
|
// OnImageIsAnimated
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateImageIsAnimated)
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnImageIsAnimated());
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateDecodeStopped) {
|
|
|
|
NS_ABORT_IF_FALSE(hasImage, "stopped decoding without ever having an image?");
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStopDecode());
|
2010-08-23 15:44:07 -07:00
|
|
|
}
|
2010-05-14 13:47:59 -07:00
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
if (state & stateRequestStopped) {
|
2013-01-18 13:47:18 -08:00
|
|
|
NOTIFY_IMAGE_OBSERVERS(OnStopRequest(hadLastPart));
|
2013-01-18 13:47:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
ImageStatusDiff
|
|
|
|
imgStatusTracker::Difference(imgStatusTracker* aOther) const
|
2013-01-18 13:47:17 -08:00
|
|
|
{
|
2013-09-28 11:28:44 -07:00
|
|
|
MOZ_ASSERT(aOther, "aOther cannot be null");
|
2013-08-28 15:39:04 -07:00
|
|
|
ImageStatusDiff diff;
|
|
|
|
diff.diffState = ~mState & aOther->mState & ~stateRequestStarted;
|
|
|
|
diff.diffImageStatus = ~mImageStatus & aOther->mImageStatus;
|
|
|
|
diff.unblockedOnload = mState & stateBlockingOnload && !(aOther->mState & stateBlockingOnload);
|
|
|
|
diff.unsetDecodeStarted = mImageStatus & imgIRequest::STATUS_DECODE_STARTED
|
|
|
|
&& !(aOther->mImageStatus & imgIRequest::STATUS_DECODE_STARTED);
|
|
|
|
diff.foundError = (mImageStatus != imgIRequest::STATUS_ERROR)
|
|
|
|
&& (aOther->mImageStatus == imgIRequest::STATUS_ERROR);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mIsMultipart || aOther->mIsMultipart, "mIsMultipart should be monotonic");
|
|
|
|
diff.foundIsMultipart = !mIsMultipart && aOther->mIsMultipart;
|
|
|
|
diff.foundLastPart = !mHadLastPart && aOther->mHadLastPart;
|
|
|
|
|
|
|
|
diff.gotDecoded = !mHasBeenDecoded && aOther->mHasBeenDecoded;
|
|
|
|
|
|
|
|
// Only record partial invalidations if we haven't been decoded before.
|
|
|
|
// When images are re-decoded after discarding, we don't want to display
|
|
|
|
// partially decoded versions to the user.
|
|
|
|
const uint32_t combinedStatus = mImageStatus | aOther->mImageStatus;
|
|
|
|
const bool doInvalidations = !(mHasBeenDecoded || aOther->mHasBeenDecoded)
|
|
|
|
|| combinedStatus & imgIRequest::STATUS_ERROR
|
|
|
|
|| combinedStatus & imgIRequest::STATUS_DECODE_COMPLETE;
|
|
|
|
|
|
|
|
// Record and reset the invalid rectangle.
|
|
|
|
// XXX(seth): We shouldn't be resetting anything here; see bug 910441.
|
|
|
|
if (doInvalidations) {
|
|
|
|
diff.invalidRect = aOther->mInvalidRect;
|
|
|
|
aOther->mInvalidRect.SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:39:05 -07:00
|
|
|
ImageStatusDiff
|
|
|
|
imgStatusTracker::DecodeStateAsDifference() const
|
|
|
|
{
|
|
|
|
ImageStatusDiff diff;
|
|
|
|
diff.diffState = mState & ~stateRequestStarted;
|
|
|
|
|
|
|
|
// All other ImageStatusDiff fields are intentionally left at their default
|
|
|
|
// values; we only want to notify decode state changes.
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::ApplyDifference(const ImageStatusDiff& aDiff)
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTracker::ApplyDifference");
|
2013-02-01 17:06:34 -08:00
|
|
|
|
|
|
|
// We must not modify or notify for the start-load state, which happens from Necko callbacks.
|
2013-01-18 13:47:18 -08:00
|
|
|
uint32_t loadState = mState & stateRequestStarted;
|
2013-03-01 15:17:24 -08:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
// Synchronize our state.
|
|
|
|
mState |= aDiff.diffState | loadState;
|
|
|
|
if (aDiff.unblockedOnload)
|
|
|
|
mState &= ~stateBlockingOnload;
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
mIsMultipart = mIsMultipart || aDiff.foundIsMultipart;
|
|
|
|
mHadLastPart = mHadLastPart || aDiff.foundLastPart;
|
|
|
|
mHasBeenDecoded = mHasBeenDecoded || aDiff.gotDecoded;
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
// Update the image status. There are some subtle points which are handled below.
|
|
|
|
mImageStatus |= aDiff.diffImageStatus;
|
2013-05-08 06:14:26 -07:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
// Unset bits which can get unset as part of the decoding process.
|
|
|
|
if (aDiff.unsetDecodeStarted)
|
|
|
|
mImageStatus &= ~imgIRequest::STATUS_DECODE_STARTED;
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
// The error state is sticky and overrides all other bits.
|
2013-08-28 15:39:04 -07:00
|
|
|
if (mImageStatus & imgIRequest::STATUS_ERROR)
|
2013-01-18 13:47:18 -08:00
|
|
|
mImageStatus = imgIRequest::STATUS_ERROR;
|
2013-03-01 15:17:24 -08:00
|
|
|
}
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2013-03-01 15:17:24 -08:00
|
|
|
void
|
2013-08-28 15:39:04 -07:00
|
|
|
imgStatusTracker::SyncNotifyDifference(const ImageStatusDiff& diff)
|
2013-03-01 15:17:24 -08:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Use mConsumers on main thread only");
|
2013-03-01 15:17:24 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTracker::SyncNotifyDifference");
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
nsIntRect invalidRect = mInvalidRect.Union(diff.invalidRect);
|
2013-11-18 13:12:59 -08:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
SyncNotifyState(mConsumers, !!mImage, diff.diffState, invalidRect, mHadLastPart);
|
2013-03-01 15:17:24 -08:00
|
|
|
|
2013-11-18 13:12:59 -08:00
|
|
|
mInvalidRect.SetEmpty();
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
if (diff.unblockedOnload) {
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2013-01-18 13:47:18 -08:00
|
|
|
while (iter.HasMore()) {
|
|
|
|
// Hold on to a reference to this proxy, since notifying the state can
|
|
|
|
// cause it to disappear.
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
2013-01-18 13:47:18 -08:00
|
|
|
|
2013-12-12 13:17:35 -08:00
|
|
|
if (proxy && !proxy->NotificationsDeferred()) {
|
2013-01-18 13:47:17 -08:00
|
|
|
SendUnblockOnload(proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
if (diff.foundError) {
|
2013-01-18 13:47:17 -08:00
|
|
|
FireFailureNotification();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-28 11:28:44 -07:00
|
|
|
already_AddRefed<imgStatusTracker>
|
2013-01-18 13:47:17 -08:00
|
|
|
imgStatusTracker::CloneForRecording()
|
|
|
|
{
|
2013-09-28 11:28:44 -07:00
|
|
|
// Grab a ref to this to ensure it isn't deleted.
|
|
|
|
nsRefPtr<imgStatusTracker> thisStatusTracker = this;
|
|
|
|
nsRefPtr<imgStatusTracker> clone = new imgStatusTracker(*thisStatusTracker);
|
|
|
|
return clone.forget();
|
2013-01-18 13:47:17 -08:00
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::SyncNotify(imgRequestProxy* proxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "imgRequestProxy is not threadsafe");
|
2013-01-18 13:47:17 -08:00
|
|
|
#ifdef PR_LOGGING
|
2013-09-28 11:28:42 -07:00
|
|
|
nsRefPtr<ImageURL> uri;
|
2013-01-18 13:47:17 -08:00
|
|
|
proxy->GetURI(getter_AddRefs(uri));
|
|
|
|
nsAutoCString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgStatusTracker::SyncNotify", "uri", spec.get());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIntRect r;
|
|
|
|
if (mImage) {
|
|
|
|
// XXX - Should only send partial rects here, but that needs to
|
|
|
|
// wait until we fix up the observer interface
|
|
|
|
r = mImage->FrameRect(imgIContainer::FRAME_CURRENT);
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray array;
|
2014-07-30 12:52:05 -07:00
|
|
|
array.AppendElement(proxy);
|
2013-01-18 13:47:18 -08:00
|
|
|
SyncNotifyState(array, !!mImage, mState, r, mHadLastPart);
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
2012-10-11 09:35:43 -07:00
|
|
|
imgStatusTracker::EmulateRequestFinished(imgRequestProxy* aProxy,
|
|
|
|
nsresult aStatus)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"SyncNotifyState and mConsumers are not threadsafe");
|
2010-05-14 13:47:59 -07:00
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(aProxy);
|
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
// In certain cases the request might not have started yet.
|
|
|
|
// We still need to fulfill the contract.
|
2012-10-12 09:11:22 -07:00
|
|
|
if (!(mState & stateRequestStarted)) {
|
|
|
|
aProxy->OnStartRequest();
|
|
|
|
}
|
|
|
|
|
2012-10-09 09:47:14 -07:00
|
|
|
if (mState & stateBlockingOnload) {
|
|
|
|
aProxy->UnblockOnload();
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
if (!(mState & stateRequestStopped)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aProxy->OnStopRequest(true);
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::AddConsumer(imgRequestProxy* aConsumer)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-07-30 12:52:05 -07:00
|
|
|
mConsumers.AppendElementUnlessExists(aConsumer);
|
2012-10-12 09:11:20 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
// XXX - The last argument should go away.
|
2012-10-12 09:11:20 -07:00
|
|
|
bool
|
|
|
|
imgStatusTracker::RemoveConsumer(imgRequestProxy* aConsumer, nsresult aStatus)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-10-12 09:11:20 -07:00
|
|
|
// Remove the proxy from the list.
|
|
|
|
bool removed = mConsumers.RemoveElement(aConsumer);
|
|
|
|
|
|
|
|
// Consumers can get confused if they don't get all the proper teardown
|
|
|
|
// notifications. Part ways on good terms.
|
2013-01-18 13:47:18 -08:00
|
|
|
if (removed && !aConsumer->NotificationsDeferred()) {
|
2012-10-12 09:11:20 -07:00
|
|
|
EmulateRequestFinished(aConsumer, aStatus);
|
2013-01-18 13:47:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we don't give callbacks to a consumer that isn't interested in
|
|
|
|
// them any more.
|
|
|
|
imgRequestNotifyRunnable* runnable = static_cast<imgRequestNotifyRunnable*>(mRequestRunnable.get());
|
|
|
|
if (aConsumer->NotificationsDeferred() && runnable) {
|
|
|
|
runnable->RemoveProxy(aConsumer);
|
|
|
|
aConsumer->SetNotificationsDeferred(false);
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:20 -07:00
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2013-12-12 13:17:35 -08:00
|
|
|
bool
|
|
|
|
imgStatusTracker::FirstConsumerIs(imgRequestProxy* aConsumer)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Use mConsumers on main thread only");
|
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
return proxy.get() == aConsumer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordCancel()
|
|
|
|
{
|
|
|
|
if (!(mImageStatus & imgIRequest::STATUS_LOAD_PARTIAL))
|
2013-02-01 17:06:34 -08:00
|
|
|
mImageStatus = imgIRequest::STATUS_ERROR;
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordLoaded()
|
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage, "RecordLoaded called before we have an Image");
|
2010-05-14 13:47:59 -07:00
|
|
|
mState |= stateRequestStarted | stateHasSize | stateRequestStopped;
|
|
|
|
mImageStatus |= imgIRequest::STATUS_SIZE_AVAILABLE | imgIRequest::STATUS_LOAD_COMPLETE;
|
2011-10-17 07:59:28 -07:00
|
|
|
mHadLastPart = true;
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordDecoded()
|
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage, "RecordDecoded called before we have an Image");
|
2012-12-19 13:28:54 -08:00
|
|
|
mState |= stateDecodeStarted | stateDecodeStopped | stateFrameStopped;
|
2010-05-14 13:47:59 -07:00
|
|
|
mImageStatus |= imgIRequest::STATUS_FRAME_COMPLETE | imgIRequest::STATUS_DECODE_COMPLETE;
|
2013-02-15 08:48:17 -08:00
|
|
|
mImageStatus &= ~imgIRequest::STATUS_DECODE_STARTED;
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordStartDecode()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mImage, "RecordStartDecode without an Image");
|
|
|
|
mState |= stateDecodeStarted;
|
2013-02-15 08:48:17 -08:00
|
|
|
mImageStatus |= imgIRequest::STATUS_DECODE_STARTED;
|
2012-12-19 13:28:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendStartDecode(imgRequestProxy* aProxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-12-19 13:28:54 -08:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
|
|
|
aProxy->OnStartDecode();
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordStartContainer(imgIContainer* aContainer)
|
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordStartContainer called before we have an Image");
|
|
|
|
NS_ABORT_IF_FALSE(mImage == aContainer,
|
|
|
|
"RecordStartContainer called with wrong Image");
|
2010-05-14 13:47:59 -07:00
|
|
|
mState |= stateHasSize;
|
|
|
|
mImageStatus |= imgIRequest::STATUS_SIZE_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::SendStartContainer(imgRequestProxy* aProxy)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-08-12 08:59:37 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
2012-10-12 09:11:23 -07:00
|
|
|
aProxy->OnStartContainer();
|
2012-10-11 18:58:24 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordStartFrame()
|
|
|
|
{
|
2013-01-18 13:47:17 -08:00
|
|
|
mInvalidRect.SetEmpty();
|
2013-01-18 13:47:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No SendStartFrame since it's not observed below us.
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::RecordStopFrame()
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage, "RecordStopFrame called before we have an Image");
|
2010-05-14 13:47:59 -07:00
|
|
|
mState |= stateFrameStopped;
|
|
|
|
mImageStatus |= imgIRequest::STATUS_FRAME_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::SendStopFrame(imgRequestProxy* aProxy)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
2012-10-12 09:11:23 -07:00
|
|
|
aProxy->OnStopFrame();
|
2012-10-11 18:58:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:22 -07:00
|
|
|
imgStatusTracker::RecordStopDecode(nsresult aStatus)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordStopDecode called before we have an Image");
|
2010-05-14 13:47:59 -07:00
|
|
|
mState |= stateDecodeStopped;
|
|
|
|
|
2013-02-15 08:48:17 -08:00
|
|
|
if (NS_SUCCEEDED(aStatus) && mImageStatus != imgIRequest::STATUS_ERROR) {
|
2010-05-14 13:47:59 -07:00
|
|
|
mImageStatus |= imgIRequest::STATUS_DECODE_COMPLETE;
|
2013-02-15 08:48:17 -08:00
|
|
|
mImageStatus &= ~imgIRequest::STATUS_DECODE_STARTED;
|
2013-04-18 16:31:46 -07:00
|
|
|
mHasBeenDecoded = true;
|
2010-05-14 13:47:59 -07:00
|
|
|
// If we weren't successful, clear all success status bits and set error.
|
2013-02-15 08:48:17 -08:00
|
|
|
} else {
|
2010-05-14 13:47:59 -07:00
|
|
|
mImageStatus = imgIRequest::STATUS_ERROR;
|
2013-02-15 08:48:17 -08:00
|
|
|
}
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::SendStopDecode(imgRequestProxy* aProxy,
|
|
|
|
nsresult aStatus)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
2012-10-12 09:11:22 -07:00
|
|
|
aProxy->OnStopDecode();
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordDiscard()
|
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordDiscard called before we have an Image");
|
2010-05-14 13:47:59 -07:00
|
|
|
// Clear the state bits we no longer deserve.
|
2012-10-12 09:11:23 -07:00
|
|
|
uint32_t stateBitsToClear = stateDecodeStopped;
|
2010-05-14 13:47:59 -07:00
|
|
|
mState &= ~stateBitsToClear;
|
|
|
|
|
|
|
|
// Clear the status bits we no longer deserve.
|
2013-02-15 08:48:17 -08:00
|
|
|
uint32_t statusBitsToClear = imgIRequest::STATUS_DECODE_STARTED |
|
|
|
|
imgIRequest::STATUS_FRAME_COMPLETE |
|
|
|
|
imgIRequest::STATUS_DECODE_COMPLETE;
|
2010-05-14 13:47:59 -07:00
|
|
|
mImageStatus &= ~statusBitsToClear;
|
|
|
|
}
|
|
|
|
|
2013-02-24 16:59:22 -08:00
|
|
|
void
|
2013-01-18 13:47:17 -08:00
|
|
|
imgStatusTracker::SendDiscard(imgRequestProxy* aProxy)
|
2013-02-24 16:59:22 -08:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-18 13:47:17 -08:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
|
|
|
aProxy->OnDiscard();
|
2013-02-24 16:59:22 -08:00
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
|
2011-11-09 13:39:15 -08:00
|
|
|
void
|
2013-01-18 13:47:17 -08:00
|
|
|
imgStatusTracker::RecordUnlockedDraw()
|
2011-11-09 13:39:15 -08:00
|
|
|
{
|
2013-01-18 13:47:17 -08:00
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordUnlockedDraw called before we have an Image");
|
2011-11-09 13:39:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordImageIsAnimated()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordImageIsAnimated called before we have an Image");
|
2013-01-18 13:47:18 -08:00
|
|
|
mState |= stateImageIsAnimated;
|
2011-11-09 13:39:15 -08:00
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
2013-01-18 13:47:17 -08:00
|
|
|
imgStatusTracker::SendImageIsAnimated(imgRequestProxy* aProxy)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
2013-01-18 13:47:17 -08:00
|
|
|
aProxy->OnImageIsAnimated();
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
2013-02-24 16:59:22 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::SendUnlockedDraw(imgRequestProxy* aProxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-02-24 16:59:22 -08:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
|
|
|
aProxy->OnUnlockedDraw();
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnUnlockedDraw()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-18 13:47:18 -08:00
|
|
|
RecordUnlockedDraw();
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2013-01-18 13:47:18 -08:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendUnlockedDraw(proxy);
|
|
|
|
}
|
2013-01-18 13:47:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:47:59 -07:00
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::RecordFrameChanged(const nsIntRect* aDirtyRect)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2010-08-23 15:44:35 -07:00
|
|
|
NS_ABORT_IF_FALSE(mImage,
|
|
|
|
"RecordFrameChanged called before we have an Image");
|
2013-01-18 13:47:17 -08:00
|
|
|
mInvalidRect = mInvalidRect.Union(*aDirtyRect);
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::SendFrameChanged(imgRequestProxy* aProxy,
|
2010-08-13 21:09:48 -07:00
|
|
|
const nsIntRect* aDirtyRect)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
2012-10-12 09:11:23 -07:00
|
|
|
aProxy->OnFrameUpdate(aDirtyRect);
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* non-virtual sort-of-nsIRequestObserver methods */
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordStartRequest()
|
|
|
|
{
|
|
|
|
// We're starting a new load, so clear any status and state bits indicating
|
|
|
|
// load/decode
|
|
|
|
mImageStatus &= ~imgIRequest::STATUS_LOAD_PARTIAL;
|
|
|
|
mImageStatus &= ~imgIRequest::STATUS_LOAD_COMPLETE;
|
|
|
|
mImageStatus &= ~imgIRequest::STATUS_FRAME_COMPLETE;
|
2013-02-15 08:48:17 -08:00
|
|
|
mImageStatus &= ~imgIRequest::STATUS_DECODE_STARTED;
|
|
|
|
mImageStatus &= ~imgIRequest::STATUS_DECODE_COMPLETE;
|
2010-05-14 13:47:59 -07:00
|
|
|
mState &= ~stateRequestStarted;
|
2012-12-19 13:28:54 -08:00
|
|
|
mState &= ~stateDecodeStarted;
|
2010-05-14 13:47:59 -07:00
|
|
|
mState &= ~stateDecodeStopped;
|
|
|
|
mState &= ~stateRequestStopped;
|
2012-08-13 15:58:53 -07:00
|
|
|
mState &= ~stateBlockingOnload;
|
2013-02-01 17:06:34 -08:00
|
|
|
mState &= ~stateImageIsAnimated;
|
2010-05-14 13:47:59 -07:00
|
|
|
|
|
|
|
mState |= stateRequestStarted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendStartRequest(imgRequestProxy* aProxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred())
|
|
|
|
aProxy->OnStartRequest();
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnStartRequest()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-10-12 09:11:21 -07:00
|
|
|
RecordStartRequest();
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2012-10-12 09:11:21 -07:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendStartRequest(proxy);
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 18:34:23 -07:00
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::RecordStopRequest(bool aLastPart,
|
|
|
|
nsresult aStatus)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
|
|
|
mHadLastPart = aLastPart;
|
|
|
|
mState |= stateRequestStopped;
|
|
|
|
|
|
|
|
// If we were successful in loading, note that the image is complete.
|
2012-10-12 09:11:22 -07:00
|
|
|
if (NS_SUCCEEDED(aStatus) && mImageStatus != imgIRequest::STATUS_ERROR)
|
2010-05-14 13:47:59 -07:00
|
|
|
mImageStatus |= imgIRequest::STATUS_LOAD_COMPLETE;
|
2012-10-12 09:11:22 -07:00
|
|
|
else
|
|
|
|
mImageStatus = imgIRequest::STATUS_ERROR;
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::SendStopRequest(imgRequestProxy* aProxy,
|
|
|
|
bool aLastPart,
|
|
|
|
nsresult aStatus)
|
2010-05-14 13:47:59 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-07-28 14:52:14 -07:00
|
|
|
if (!aProxy->NotificationsDeferred()) {
|
|
|
|
aProxy->OnStopRequest(aLastPart);
|
|
|
|
}
|
2010-05-14 13:47:59 -07:00
|
|
|
}
|
2012-08-13 15:58:53 -07:00
|
|
|
|
2013-09-28 11:28:43 -07:00
|
|
|
class OnStopRequestEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OnStopRequestEvent(imgStatusTracker* aTracker,
|
|
|
|
bool aLastPart,
|
|
|
|
nsresult aStatus)
|
|
|
|
: mTracker(aTracker)
|
|
|
|
, mLastPart(aLastPart)
|
|
|
|
, mStatus(aStatus)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "Should be created off the main thread");
|
|
|
|
MOZ_ASSERT(aTracker, "aTracker should not be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
|
|
|
|
MOZ_ASSERT(mTracker, "mTracker should not be null");
|
|
|
|
mTracker->OnStopRequest(mLastPart, mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgStatusTracker> mTracker;
|
|
|
|
bool mLastPart;
|
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
void
|
2012-10-12 09:11:23 -07:00
|
|
|
imgStatusTracker::OnStopRequest(bool aLastPart,
|
|
|
|
nsresult aStatus)
|
2012-10-12 09:11:21 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
new OnStopRequestEvent(this, aLastPart, aStatus));
|
|
|
|
return;
|
|
|
|
}
|
2012-10-12 09:11:23 -07:00
|
|
|
bool preexistingError = mImageStatus == imgIRequest::STATUS_ERROR;
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
RecordStopRequest(aLastPart, aStatus);
|
|
|
|
/* notify the kids */
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator srIter(mConsumers);
|
2012-10-12 09:11:21 -07:00
|
|
|
while (srIter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = srIter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendStopRequest(proxy, aLastPart, aStatus);
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
2012-10-12 09:11:22 -07:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
if (NS_FAILED(aStatus) && !preexistingError) {
|
|
|
|
FireFailureNotification();
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2013-02-07 14:22:38 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnDiscard()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-02-07 14:22:38 -08:00
|
|
|
RecordDiscard();
|
|
|
|
|
|
|
|
/* notify the kids */
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2013-02-07 14:22:38 -08:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendDiscard(proxy);
|
|
|
|
}
|
2013-02-07 14:22:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::FrameChanged(const nsIntRect* aDirtyRect)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-01-18 13:47:18 -08:00
|
|
|
RecordFrameChanged(aDirtyRect);
|
|
|
|
|
|
|
|
/* notify the kids */
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2013-01-18 13:47:18 -08:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendFrameChanged(proxy, aDirtyRect);
|
|
|
|
}
|
2013-01-18 13:47:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:34:20 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnStopFrame()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-02-11 16:34:20 -08:00
|
|
|
RecordStopFrame();
|
|
|
|
|
|
|
|
/* notify the kids */
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2013-02-11 16:34:20 -08:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendStopFrame(proxy);
|
|
|
|
}
|
2013-02-11 16:34:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnDataAvailable()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// Note: SetHasImage calls Image::Lock and Image::IncrementAnimationCounter
|
|
|
|
// so subsequent calls or dispatches which Unlock or Decrement~ should
|
|
|
|
// be issued after this to avoid race conditions.
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableMethod(this, &imgStatusTracker::OnDataAvailable));
|
|
|
|
return;
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
// Notify any imgRequestProxys that are observing us that we have an Image.
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2012-10-12 09:11:21 -07:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
proxy->SetHasImage();
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 15:58:53 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordBlockOnload()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!(mState & stateBlockingOnload));
|
|
|
|
mState |= stateBlockingOnload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendBlockOnload(imgRequestProxy* aProxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-08-13 15:58:53 -07:00
|
|
|
if (!aProxy->NotificationsDeferred()) {
|
|
|
|
aProxy->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordUnblockOnload()
|
|
|
|
{
|
|
|
|
mState &= ~stateBlockingOnload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendUnblockOnload(imgRequestProxy* aProxy)
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-08-13 15:58:53 -07:00
|
|
|
if (!aProxy->NotificationsDeferred()) {
|
|
|
|
aProxy->UnblockOnload();
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::MaybeUnblockOnload()
|
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_DispatchToMainThread(
|
|
|
|
NS_NewRunnableMethod(this, &imgStatusTracker::MaybeUnblockOnload));
|
|
|
|
return;
|
|
|
|
}
|
2012-12-20 08:49:26 -08:00
|
|
|
if (!(mState & stateBlockingOnload)) {
|
2012-10-12 09:11:21 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecordUnblockOnload();
|
|
|
|
|
2013-12-12 13:17:35 -08:00
|
|
|
ProxyArray::ForwardIterator iter(mConsumers);
|
2012-10-12 09:11:21 -07:00
|
|
|
while (iter.HasMore()) {
|
2013-12-12 13:17:35 -08:00
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
|
|
|
|
if (proxy) {
|
|
|
|
SendUnblockOnload(proxy);
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
}
|
2012-11-17 05:33:20 -08:00
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordError()
|
|
|
|
{
|
|
|
|
mImageStatus = imgIRequest::STATUS_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-11-17 05:33:20 -08:00
|
|
|
void
|
2012-12-19 13:28:54 -08:00
|
|
|
imgStatusTracker::FireFailureNotification()
|
2012-11-17 05:33:20 -08:00
|
|
|
{
|
2013-01-18 13:47:18 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
// Some kind of problem has happened with image decoding.
|
|
|
|
// Report the URI to net:failed-to-process-uri-conent observers.
|
2013-09-28 11:28:44 -07:00
|
|
|
if (mImage) {
|
2013-09-28 11:28:42 -07:00
|
|
|
// Should be on main thread, so ok to create a new nsIURI.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
{
|
2013-09-28 11:28:44 -07:00
|
|
|
nsRefPtr<ImageURL> threadsafeUriData = mImage->GetURI();
|
2013-09-28 11:28:42 -07:00
|
|
|
uri = threadsafeUriData ? threadsafeUriData->ToIURI() : nullptr;
|
|
|
|
}
|
2013-02-01 17:06:34 -08:00
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
|
|
|
|
}
|
2012-12-19 13:28:54 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-17 05:33:20 -08:00
|
|
|
}
|