image/ScriptedNotificationObserver.cpp
author Timothy Nikkel <tnikkel@gmail.com>
Tue, 20 Dec 2016 13:49:31 -0600
changeset 373935 0f0a59cbeb48948c972e7cdbb2800ab9c03f5afd
parent 276648 7701abd924856d65acbf9927629cf27dd2335ec1
child 376307 335c5d74c1a1be434be18cb38230b13ddbbd342e
permissions -rw-r--r--
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.

/* -*- 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