gecko-dev/image/ScriptedNotificationObserver.cpp
Timothy Nikkel 3428a70b8d Bug 1324642. Move assert from bug 1323207 from nsImageLoadingContent::Notify to ScriptedNotificationObserver. r=continuation
nsImageLoadingContent::Notify is where all image notifications for things like <img> elements go through. The vast majority being implemented in C++. Any image observers implemented in JS must go through ScriptedNotificationObserver.

We only use ScriptedNotificationObserver in tests. The addon repository only has six hits, and four of them seem to be different versions of the same addon. And they don't seem to be among the more popular addons.

The original location of the assert only caught some images anyway. Things like CSS background images don't go through nsImageLoadingContent. ProgressTracker is the origin of all image notifications.
2016-12-20 13:49:31 -06:00

66 lines
2.2 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/. */
#include "ScriptedNotificationObserver.h"
#include "imgIScriptedNotificationObserver.h"
#include "nsCycleCollectionParticipant.h"
namespace mozilla {
namespace image {
NS_IMPL_CYCLE_COLLECTION(ScriptedNotificationObserver, mInner)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptedNotificationObserver)
NS_INTERFACE_MAP_ENTRY(imgINotificationObserver)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptedNotificationObserver)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptedNotificationObserver)
ScriptedNotificationObserver::ScriptedNotificationObserver(
imgIScriptedNotificationObserver* aInner)
: mInner(aInner)
{ }
NS_IMETHODIMP
ScriptedNotificationObserver::Notify(imgIRequest* aRequest,
int32_t aType,
const nsIntRect* /*aUnused*/)
{
MOZ_RELEASE_ASSERT(js::AllowGCBarriers(CycleCollectedJSContext::Get()->Context()),
"sending image notification to JS observer during painting. See bug 1311841");
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
return mInner->SizeAvailable(aRequest);
}
if (aType == imgINotificationObserver::FRAME_UPDATE) {
return mInner->FrameUpdate(aRequest);
}
if (aType == imgINotificationObserver::FRAME_COMPLETE) {
return mInner->FrameComplete(aRequest);
}
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
return mInner->DecodeComplete(aRequest);
}
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
return mInner->LoadComplete(aRequest);
}
if (aType == imgINotificationObserver::DISCARD) {
return mInner->Discard(aRequest);
}
if (aType == imgINotificationObserver::IS_ANIMATED) {
return mInner->IsAnimated(aRequest);
}
if (aType == imgINotificationObserver::HAS_TRANSPARENCY) {
return mInner->HasTransparency(aRequest);
}
return NS_OK;
}
} // namespace image
} // namespace mozilla