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
|
|
|
|
|
|
|
#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"
|
2010-07-28 14:52:34 -07:00
|
|
|
#include "ImageLogging.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;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
class imgStatusTrackerNotifyingObserver : public imgDecoderObserver
|
2012-12-18 08:37:15 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-01-02 09:00:50 -08:00
|
|
|
imgStatusTrackerNotifyingObserver(imgStatusTracker* aTracker)
|
2012-12-18 08:37:14 -08:00
|
|
|
: mTracker(aTracker) {}
|
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
virtual ~imgStatusTrackerNotifyingObserver() {}
|
2012-12-18 08:37:14 -08:00
|
|
|
|
|
|
|
void SetTracker(imgStatusTracker* aTracker) {
|
|
|
|
mTracker = aTracker;
|
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
/** imgDecoderObserver methods **/
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnStartDecode()
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::OnStartDecode");
|
2012-12-18 08:37:15 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnStartDecode callback before we've created our image");
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
mTracker->RecordStartDecode();
|
|
|
|
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendStartDecode(iter.GetNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTracker->IsMultipart()) {
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->RecordBlockOnload();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendBlockOnload(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnStartRequest()
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
NS_NOTREACHED("imgStatusTrackerNotifyingObserver(imgDecoderObserver)::OnStartRequest");
|
2012-12-16 18:13:35 -08:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnStartContainer()
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::OnStartContainer");
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnStartContainer callback before we've created our image");
|
|
|
|
mTracker->RecordStartContainer(mTracker->GetImage());
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendStartContainer(iter.GetNext());
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
virtual void OnStartFrame()
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::OnStartFrame");
|
2013-01-18 13:47:17 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnStartFrame callback before we've created our image");
|
|
|
|
|
|
|
|
mTracker->RecordStartFrame();
|
|
|
|
|
|
|
|
// This is not observed below the imgStatusTracker level, so we don't need
|
|
|
|
// to SendStartFrame.
|
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void FrameChanged(const nsIntRect* dirtyRect)
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::FrameChanged");
|
2012-12-18 08:37:15 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"FrameChanged callback before we've created our image");
|
2012-12-18 08:37:15 -08:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->RecordFrameChanged(dirtyRect);
|
2012-12-18 08:37:15 -08:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendFrameChanged(iter.GetNext(), dirtyRect);
|
|
|
|
}
|
2012-12-18 08:37:15 -08:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnStopFrame()
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::OnStopFrame");
|
2012-12-18 08:37:15 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnStopFrame callback before we've created our image");
|
2012-12-18 08:37:15 -08:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->RecordStopFrame();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendStopFrame(iter.GetNext());
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->MaybeUnblockOnload();
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnStopDecode(nsresult aStatus)
|
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerNotifyingObserver::OnStopDecode");
|
2012-12-18 08:37:15 -08:00
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnStopDecode callback before we've created our image");
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
bool preexistingError = mTracker->GetImageStatus() == imgIRequest::STATUS_ERROR;
|
2012-12-16 18:13:35 -08:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->RecordStopDecode(aStatus);
|
2012-12-16 18:13:35 -08:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendStopDecode(iter.GetNext(), aStatus);
|
|
|
|
}
|
2012-10-12 09:11:23 -07:00
|
|
|
|
2012-12-18 08:37:15 -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.
|
|
|
|
mTracker->MaybeUnblockOnload();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
if (NS_FAILED(aStatus) && !preexistingError) {
|
|
|
|
mTracker->FireFailureNotification();
|
2012-12-18 08:37:15 -08:00
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
virtual void OnStopRequest(bool aLastPart, nsresult aStatus)
|
2012-12-18 08:37:15 -08:00
|
|
|
{
|
2013-01-02 09:00:50 -08:00
|
|
|
NS_NOTREACHED("imgStatusTrackerNotifyingObserver(imgDecoderObserver)::OnStopRequest");
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnDiscard()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnDiscard callback before we've created our image");
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
mTracker->RecordDiscard();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendDiscard(iter.GetNext());
|
|
|
|
}
|
2012-12-16 18:13:35 -08:00
|
|
|
}
|
|
|
|
|
2013-02-24 16:59:22 -08:00
|
|
|
virtual void OnUnlockedDraw()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnUnlockedDraw callback before we've created our image");
|
|
|
|
mTracker->RecordUnlockedDraw();
|
|
|
|
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendUnlockedDraw(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
virtual void OnImageIsAnimated()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnImageIsAnimated callback before we've created our image");
|
|
|
|
mTracker->RecordImageIsAnimated();
|
2012-10-12 09:11:21 -07:00
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
mTracker->SendImageIsAnimated(iter.GetNext());
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
virtual void OnError()
|
|
|
|
{
|
|
|
|
mTracker->RecordError();
|
|
|
|
}
|
|
|
|
|
2012-12-18 08:37:15 -08:00
|
|
|
private:
|
|
|
|
imgStatusTracker* mTracker;
|
|
|
|
};
|
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
class imgStatusTrackerObserver : public imgDecoderObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgStatusTrackerObserver(imgStatusTracker* aTracker)
|
|
|
|
: mTracker(aTracker) {}
|
|
|
|
|
|
|
|
virtual ~imgStatusTrackerObserver() {}
|
|
|
|
|
|
|
|
void SetTracker(imgStatusTracker* aTracker) {
|
|
|
|
mTracker = aTracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** imgDecoderObserver methods **/
|
|
|
|
|
|
|
|
virtual void OnStartDecode() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartDecode");
|
|
|
|
mTracker->RecordStartDecode();
|
|
|
|
if (!mTracker->IsMultipart()) {
|
|
|
|
mTracker->RecordBlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartRequest() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("imgStatusTrackerObserver(imgDecoderObserver)::OnStartRequest");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartContainer() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartContainer");
|
|
|
|
mTracker->RecordStartContainer(mTracker->GetImage());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStartFrame() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStartFrame");
|
|
|
|
mTracker->RecordStartFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FrameChanged(const nsIntRect* dirtyRect) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::FrameChanged");
|
|
|
|
mTracker->RecordFrameChanged(dirtyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStopFrame() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStopFrame");
|
|
|
|
mTracker->RecordStopFrame();
|
|
|
|
mTracker->RecordUnblockOnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnStopDecode(nsresult aStatus) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnStopDecode");
|
|
|
|
mTracker->RecordStopDecode(aStatus);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
mTracker->RecordUnblockOnload();
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
mTracker->RecordStopRequest(aLastPart, aStatus);
|
2013-01-02 09:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDiscard() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnDiscard");
|
|
|
|
mTracker->RecordDiscard();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnUnlockedDraw() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnUnlockedDraw");
|
|
|
|
NS_ABORT_IF_FALSE(mTracker->GetImage(),
|
|
|
|
"OnUnlockedDraw callback before we've created our image");
|
|
|
|
mTracker->RecordUnlockedDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnImageIsAnimated() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnImageIsAnimated");
|
|
|
|
mTracker->RecordImageIsAnimated();
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:34 -08:00
|
|
|
virtual void OnError() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnError");
|
|
|
|
mTracker->RecordError();
|
|
|
|
}
|
|
|
|
|
2013-01-02 09:00:50 -08:00
|
|
|
private:
|
|
|
|
imgStatusTracker* mTracker;
|
|
|
|
};
|
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()
|
|
|
|
{}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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:
|
2012-12-19 13:28:54 -08:00
|
|
|
imgRequestNotifyRunnable(imgStatusTracker* aTracker, imgRequestProxy* aRequestProxy)
|
|
|
|
: mTracker(aTracker)
|
2010-08-12 08:59:28 -07:00
|
|
|
{
|
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()
|
|
|
|
{
|
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
|
|
|
{
|
2010-07-28 14:52:34 -07:00
|
|
|
#ifdef PR_LOGGING
|
2012-12-19 13:28:54 -08:00
|
|
|
if (GetImage() && GetImage()->GetURI()) {
|
|
|
|
nsCOMPtr<nsIURI> uri(GetImage()->GetURI());
|
|
|
|
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:
|
2010-08-12 08:59:28 -07:00
|
|
|
imgStatusNotifyRunnable(imgStatusTracker& status,
|
2010-07-28 14:52:14 -07:00
|
|
|
imgRequestProxy* requestproxy)
|
|
|
|
: mStatus(status), mImage(status.mImage), mProxy(requestproxy)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mProxy->SetNotificationsDeferred(false);
|
2010-07-28 14:52:14 -07:00
|
|
|
|
|
|
|
mStatus.SyncNotify(mProxy);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
imgStatusTracker mStatus;
|
|
|
|
// 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
|
|
|
{
|
2010-07-28 14:52:34 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
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
|
2010-07-28 14:52:14 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new imgStatusNotifyRunnable(*this, proxy);
|
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
#define NOTIFY_IMAGE_OBSERVERS(func) \
|
|
|
|
do { \
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(proxies); \
|
|
|
|
while (iter.HasMore()) { \
|
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext(); \
|
|
|
|
if (!proxy->NotificationsDeferred()) { \
|
|
|
|
proxy->func; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (false);
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
/* static */ void
|
2013-01-18 13:47:18 -08:00
|
|
|
imgStatusTracker::SyncNotifyState(nsTObserverArray<imgRequestProxy*>& proxies,
|
|
|
|
bool hasImage, uint32_t state,
|
|
|
|
nsIntRect& dirtyRect, bool hadLastPart)
|
2010-07-28 14:52:14 -07:00
|
|
|
{
|
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-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;
|
|
|
|
MOZ_ASSERT(!mHadLastPart || aOther->mHadLastPart, "mHadLastPart should be monotonic");
|
|
|
|
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
|
|
|
{
|
|
|
|
LOG_SCOPE(GetImgLog(), "imgStatusTracker::SyncNotifyDifference");
|
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
nsIntRect invalidRect = mInvalidRect.Union(diff.invalidRect);
|
|
|
|
mInvalidRect.SetEmpty();
|
|
|
|
SyncNotifyState(mConsumers, !!mImage, diff.diffState, invalidRect, mHadLastPart);
|
2013-03-01 15:17:24 -08:00
|
|
|
|
2013-08-28 15:39:04 -07:00
|
|
|
if (diff.unblockedOnload) {
|
2013-01-18 13:47:18 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
// Hold on to a reference to this proxy, since notifying the state can
|
|
|
|
// cause it to disappear.
|
|
|
|
nsRefPtr<imgRequestProxy> proxy = iter.GetNext();
|
|
|
|
|
|
|
|
if (!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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
imgStatusTracker*
|
|
|
|
imgStatusTracker::CloneForRecording()
|
|
|
|
{
|
|
|
|
imgStatusTracker* clone = new imgStatusTracker(*this);
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:17 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::SyncNotify(imgRequestProxy* proxy)
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
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-01-18 13:47:18 -08:00
|
|
|
nsTObserverArray<imgRequestProxy*> array;
|
|
|
|
array.AppendElement(proxy);
|
|
|
|
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
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
mConsumers.AppendElementUnlessExists(aConsumer);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
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
|
|
|
{
|
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
|
|
|
{
|
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-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
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
if (!aProxy->NotificationsDeferred())
|
|
|
|
aProxy->OnUnlockedDraw();
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnUnlockedDraw()
|
|
|
|
{
|
|
|
|
RecordUnlockedDraw();
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendUnlockedDraw(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
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()
|
|
|
|
{
|
|
|
|
RecordStartRequest();
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendStartRequest(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
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
|
|
|
{
|
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 */
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator srIter(mConsumers);
|
|
|
|
while (srIter.HasMore()) {
|
|
|
|
SendStopRequest(srIter.GetNext(), aLastPart, aStatus);
|
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
RecordDiscard();
|
|
|
|
|
|
|
|
/* notify the kids */
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendDiscard(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::FrameChanged(const nsIntRect* aDirtyRect)
|
|
|
|
{
|
|
|
|
RecordFrameChanged(aDirtyRect);
|
|
|
|
|
|
|
|
/* notify the kids */
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendFrameChanged(iter.GetNext(), aDirtyRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:34:20 -08:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnStopFrame()
|
|
|
|
{
|
|
|
|
RecordStopFrame();
|
|
|
|
|
|
|
|
/* notify the kids */
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendStopFrame(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:21 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::OnDataAvailable()
|
|
|
|
{
|
|
|
|
// Notify any imgRequestProxys that are observing us that we have an Image.
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
iter.GetNext()->SetHasImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 15:58:53 -07:00
|
|
|
void
|
|
|
|
imgStatusTracker::RecordBlockOnload()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!(mState & stateBlockingOnload));
|
|
|
|
mState |= stateBlockingOnload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendBlockOnload(imgRequestProxy* aProxy)
|
|
|
|
{
|
|
|
|
if (!aProxy->NotificationsDeferred()) {
|
|
|
|
aProxy->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::RecordUnblockOnload()
|
|
|
|
{
|
|
|
|
mState &= ~stateBlockingOnload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::SendUnblockOnload(imgRequestProxy* aProxy)
|
|
|
|
{
|
|
|
|
if (!aProxy->NotificationsDeferred()) {
|
|
|
|
aProxy->UnblockOnload();
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 09:11:21 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
imgStatusTracker::MaybeUnblockOnload()
|
|
|
|
{
|
2012-12-20 08:49:26 -08:00
|
|
|
if (!(mState & stateBlockingOnload)) {
|
2012-10-12 09:11:21 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecordUnblockOnload();
|
|
|
|
|
|
|
|
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
SendUnblockOnload(iter.GetNext());
|
|
|
|
}
|
|
|
|
}
|
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-02-01 17:06:34 -08:00
|
|
|
if (GetImage()) {
|
|
|
|
nsCOMPtr<nsIURI> uri = GetImage()->GetURI();
|
|
|
|
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
|
|
|
}
|