Bug 379929 - Lazy creation of nsProperties object for imgContainer
authorasqueella@gmail.com
Thu, 21 Jun 2007 13:45:49 -0700
changeset 2663 7be9684ce3a754b5aadcd028805e0ba5220172e0
parent 2662 eefebde94eeaa9949339de62cf4e2da4dcf87a1e
child 2664 656c650197199cb54ab21349c23059df283a785e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs379929
milestone1.9a6pre
Bug 379929 - Lazy creation of nsProperties object for imgContainer p=Alfred Kayser <alfredkayser@nl.ibm.com> r=stuart, sr=tor
modules/libpr0n/src/imgContainer.cpp
modules/libpr0n/src/imgContainer.h
--- a/modules/libpr0n/src/imgContainer.cpp
+++ b/modules/libpr0n/src/imgContainer.cpp
@@ -55,17 +55,16 @@ NS_IMPL_ISUPPORTS3(imgContainer, imgICon
 //******************************************************************************
 imgContainer::imgContainer() :
   mSize(0,0),
   mAnim(nsnull),
   mAnimationMode(kNormalAnimMode),
   mLoopCount(-1),
   mObserver(nsnull)
 {
-  mProperties = do_CreateInstance("@mozilla.org/properties;1");
 }
 
 //******************************************************************************
 imgContainer::~imgContainer()
 {
   if (mAnim)
     delete mAnim;
 }
@@ -822,8 +821,52 @@ PRBool imgContainer::CopyFrameImage(gfxI
   if (!img)
     return PR_FALSE;
   nsIntRect r;
   aDstFrame->GetRect(r);
   img->ImageUpdated(nsnull, nsImageUpdateFlags_kBitsChanged, &r);
 
   return PR_TRUE;
 }
+
+/********* Methods to implement lazy allocation of nsIProperties object *************/
+NS_IMETHODIMP imgContainer::Get(const char *prop, const nsIID & iid, void * *result)
+{
+  if (!mProperties)
+    return NS_ERROR_FAILURE;
+  return mProperties->Get(prop, iid, result);
+}
+
+NS_IMETHODIMP imgContainer::Set(const char *prop, nsISupports *value)
+{
+  if (!mProperties)
+    mProperties = do_CreateInstance("@mozilla.org/properties;1");
+  if (!mProperties)
+    return NS_ERROR_OUT_OF_MEMORY;
+  return mProperties->Set(prop, value);
+}
+
+NS_IMETHODIMP imgContainer::Has(const char *prop, PRBool *_retval)
+{
+  NS_ENSURE_ARG_POINTER(_retval);
+  if (!mProperties) {
+    *_retval = PR_FALSE;
+    return NS_OK;
+  }
+  return mProperties->Has(prop, _retval);
+}
+
+NS_IMETHODIMP imgContainer::Undefine(const char *prop)
+{
+  if (!mProperties)
+    return NS_ERROR_FAILURE;
+  return mProperties->Undefine(prop);
+}
+
+NS_IMETHODIMP imgContainer::GetKeys(PRUint32 *count, char ***keys)
+{
+  if (!mProperties) {
+    *count = 0;
+    *keys = nsnull;
+    return NS_OK;
+  }
+  return mProperties->GetKeys(count, keys);
+}
--- a/modules/libpr0n/src/imgContainer.h
+++ b/modules/libpr0n/src/imgContainer.h
@@ -132,17 +132,17 @@
 class imgContainer : public imgIContainer, 
                      public nsITimerCallback, 
                      public nsIProperties
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_IMGICONTAINER
   NS_DECL_NSITIMERCALLBACK
-  NS_FORWARD_SAFE_NSIPROPERTIES(mProperties)
+  NS_DECL_NSIPROPERTIES
 
   imgContainer();
   virtual ~imgContainer();
 
 private:
   friend class nsGIFDecoder2;
   
   struct Anim