Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / image / ScriptedNotificationObserver.cpp
bloba12af3257ef8fa4adba965d28a28c09a35992bb9
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 NS_IMETHODIMP
30 ScriptedNotificationObserver::Notify(imgIRequest* aRequest, int32_t aType,
31 const nsIntRect* /*aUnused*/) {
32 // For now, we block (other) scripts from running to preserve the historical
33 // behavior from when ScriptedNotificationObserver::Notify was called as part
34 // of the observers list in nsImageLoadingContent::Notify. Now each
35 // ScriptedNotificationObserver has its own imgRequestProxy and thus gets
36 // Notify called directly by imagelib.
37 nsAutoScriptBlocker scriptBlocker;
39 if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
40 return mInner->SizeAvailable(aRequest);
42 if (aType == imgINotificationObserver::FRAME_UPDATE) {
43 return mInner->FrameUpdate(aRequest);
45 if (aType == imgINotificationObserver::FRAME_COMPLETE) {
46 return mInner->FrameComplete(aRequest);
48 if (aType == imgINotificationObserver::DECODE_COMPLETE) {
49 return mInner->DecodeComplete(aRequest);
51 if (aType == imgINotificationObserver::LOAD_COMPLETE) {
52 return mInner->LoadComplete(aRequest);
54 if (aType == imgINotificationObserver::DISCARD) {
55 return mInner->Discard(aRequest);
57 if (aType == imgINotificationObserver::IS_ANIMATED) {
58 return mInner->IsAnimated(aRequest);
60 if (aType == imgINotificationObserver::HAS_TRANSPARENCY) {
61 return mInner->HasTransparency(aRequest);
63 return NS_OK;
66 } // namespace image
67 } // namespace mozilla