Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / image / ScriptedNotificationObserver.cpp
blob4797b182c3bd7f45e1ac9fe0e68fcda731b14c5e
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) {}
29 void ScriptedNotificationObserver::Notify(imgIRequest* aRequest, int32_t aType,
30 const nsIntRect* /*aUnused*/) {
31 // For now, we block (other) scripts from running to preserve the historical
32 // behavior from when ScriptedNotificationObserver::Notify was called as part
33 // of the observers list in nsImageLoadingContent::Notify. Now each
34 // ScriptedNotificationObserver has its own imgRequestProxy and thus gets
35 // Notify called directly by imagelib.
36 nsAutoScriptBlocker scriptBlocker;
38 if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
39 mInner->SizeAvailable(aRequest);
40 return;
42 if (aType == imgINotificationObserver::FRAME_UPDATE) {
43 mInner->FrameUpdate(aRequest);
44 return;
46 if (aType == imgINotificationObserver::FRAME_COMPLETE) {
47 mInner->FrameComplete(aRequest);
48 return;
50 if (aType == imgINotificationObserver::DECODE_COMPLETE) {
51 mInner->DecodeComplete(aRequest);
52 return;
54 if (aType == imgINotificationObserver::LOAD_COMPLETE) {
55 mInner->LoadComplete(aRequest);
56 return;
58 if (aType == imgINotificationObserver::DISCARD) {
59 mInner->Discard(aRequest);
60 return;
62 if (aType == imgINotificationObserver::IS_ANIMATED) {
63 mInner->IsAnimated(aRequest);
64 return;
66 if (aType == imgINotificationObserver::HAS_TRANSPARENCY) {
67 mInner->HasTransparency(aRequest);
68 return;
72 } // namespace image
73 } // namespace mozilla