Bug 1467571 [wpt PR 11385] - Make manifest's parsers quicker, a=testonly
[gecko.git] / image / ScriptedNotificationObserver.cpp
bloba8758978d24d30a1dd582c4b09f05065f21e3e80
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ScriptedNotificationObserver.h"
8 #include "imgIScriptedNotificationObserver.h"
9 #include "nsCycleCollectionParticipant.h"
10 #include "nsContentUtils.h" // for nsAutoScriptBlocker
12 namespace mozilla {
13 namespace image {
15 NS_IMPL_CYCLE_COLLECTION(ScriptedNotificationObserver, mInner)
17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptedNotificationObserver)
18 NS_INTERFACE_MAP_ENTRY(imgINotificationObserver)
19 NS_INTERFACE_MAP_ENTRY(nsISupports)
20 NS_INTERFACE_MAP_END
22 NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptedNotificationObserver)
23 NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptedNotificationObserver)
25 ScriptedNotificationObserver::ScriptedNotificationObserver(
26 imgIScriptedNotificationObserver* aInner)
27 : mInner(aInner)
28 { }
30 NS_IMETHODIMP
31 ScriptedNotificationObserver::Notify(imgIRequest* aRequest,
32 int32_t aType,
33 const nsIntRect* /*aUnused*/)
35 // For now, we block (other) scripts from running to preserve the historical
36 // behavior from when ScriptedNotificationObserver::Notify was called as part
37 // of the observers list in nsImageLoadingContent::Notify. Now each
38 // ScriptedNotificationObserver has its own imgRequestProxy and thus gets
39 // Notify called directly by imagelib.
40 nsAutoScriptBlocker scriptBlocker;
42 if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
43 return mInner->SizeAvailable(aRequest);
45 if (aType == imgINotificationObserver::FRAME_UPDATE) {
46 return mInner->FrameUpdate(aRequest);
48 if (aType == imgINotificationObserver::FRAME_COMPLETE) {
49 return mInner->FrameComplete(aRequest);
51 if (aType == imgINotificationObserver::DECODE_COMPLETE) {
52 return mInner->DecodeComplete(aRequest);
54 if (aType == imgINotificationObserver::LOAD_COMPLETE) {
55 return mInner->LoadComplete(aRequest);
57 if (aType == imgINotificationObserver::DISCARD) {
58 return mInner->Discard(aRequest);
60 if (aType == imgINotificationObserver::IS_ANIMATED) {
61 return mInner->IsAnimated(aRequest);
63 if (aType == imgINotificationObserver::HAS_TRANSPARENCY) {
64 return mInner->HasTransparency(aRequest);
66 return NS_OK;
69 } // namespace image
70 } // namespace mozilla