1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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/. */ 6 7 #include "ScriptedNotificationObserver.h" 8 #include "imgIScriptedNotificationObserver.h" 9 #include "nsCycleCollectionParticipant.h" 10 #include "nsContentUtils.h" // for nsAutoScriptBlocker 11 12 namespace mozilla { 13 namespace image { 14 NS_IMPL_CYCLE_COLLECTION(ScriptedNotificationObserver,mInner)15NS_IMPL_CYCLE_COLLECTION(ScriptedNotificationObserver, mInner) 16 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 21 22 NS_IMPL_CYCLE_COLLECTING_ADDREF(ScriptedNotificationObserver) 23 NS_IMPL_CYCLE_COLLECTING_RELEASE(ScriptedNotificationObserver) 24 25 ScriptedNotificationObserver::ScriptedNotificationObserver( 26 imgIScriptedNotificationObserver* aInner) 27 : mInner(aInner) {} 28 Notify(imgIRequest * aRequest,int32_t aType,const nsIntRect *)29void 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; 37 38 if (aType == imgINotificationObserver::SIZE_AVAILABLE) { 39 mInner->SizeAvailable(aRequest); 40 return; 41 } 42 if (aType == imgINotificationObserver::FRAME_UPDATE) { 43 mInner->FrameUpdate(aRequest); 44 return; 45 } 46 if (aType == imgINotificationObserver::FRAME_COMPLETE) { 47 mInner->FrameComplete(aRequest); 48 return; 49 } 50 if (aType == imgINotificationObserver::DECODE_COMPLETE) { 51 mInner->DecodeComplete(aRequest); 52 return; 53 } 54 if (aType == imgINotificationObserver::LOAD_COMPLETE) { 55 mInner->LoadComplete(aRequest); 56 return; 57 } 58 if (aType == imgINotificationObserver::DISCARD) { 59 mInner->Discard(aRequest); 60 return; 61 } 62 if (aType == imgINotificationObserver::IS_ANIMATED) { 63 mInner->IsAnimated(aRequest); 64 return; 65 } 66 if (aType == imgINotificationObserver::HAS_TRANSPARENCY) { 67 mInner->HasTransparency(aRequest); 68 return; 69 } 70 } 71 72 } // namespace image 73 } // namespace mozilla 74