Bug 1324924 - ImageBitmap::ToCloneData should be const and return a UniquePtr. - r=mtseng draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 20 Dec 2016 14:59:51 -0800
changeset 451751 f86d440fce3aa97096ab7d9634895d2d41370e27
parent 451750 4ea7e4a23903a6bb9e819a94a64b37b25fe57974
child 451752 77b4efa9426f0d2f0aac051ab637a1c81bc159a2
push id39282
push userbmo:jgilbert@mozilla.com
push dateTue, 20 Dec 2016 23:12:57 +0000
reviewersmtseng
bugs1324924
milestone53.0a1
Bug 1324924 - ImageBitmap::ToCloneData should be const and return a UniquePtr. - r=mtseng MozReview-Commit-ID: JzcbzeFHyHn
dom/base/StructuredCloneHolder.cpp
dom/canvas/ImageBitmap.cpp
dom/canvas/ImageBitmap.h
--- a/dom/base/StructuredCloneHolder.cpp
+++ b/dom/base/StructuredCloneHolder.cpp
@@ -1291,17 +1291,17 @@ StructuredCloneHolder::CustomWriteTransf
       ImageBitmap* bitmap = nullptr;
       rv = UNWRAP_OBJECT(ImageBitmap, aObj, bitmap);
       if (NS_SUCCEEDED(rv)) {
         MOZ_ASSERT(bitmap);
 
         *aExtraData = 0;
         *aTag = SCTAG_DOM_IMAGEBITMAP;
         *aOwnership = JS::SCTAG_TMO_CUSTOM;
-        *aContent = bitmap->ToCloneData();
+        *aContent = bitmap->ToCloneData().release();
         MOZ_ASSERT(*aContent);
         bitmap->Close();
 
         return true;
       }
     }
   }
 
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -718,28 +718,28 @@ ImageBitmap::PrepareForDrawTarget(gfx::D
 already_AddRefed<layers::Image>
 ImageBitmap::TransferAsImage()
 {
   RefPtr<layers::Image> image = mData;
   Close();
   return image.forget();
 }
 
-ImageBitmapCloneData*
-ImageBitmap::ToCloneData()
+UniquePtr<ImageBitmapCloneData>
+ImageBitmap::ToCloneData() const
 {
-  ImageBitmapCloneData* result = new ImageBitmapCloneData();
+  UniquePtr<ImageBitmapCloneData> result(new ImageBitmapCloneData());
   result->mPictureRect = mPictureRect;
   result->mIsPremultipliedAlpha = mIsPremultipliedAlpha;
   result->mIsCroppingAreaOutSideOfSourceImage = mIsCroppingAreaOutSideOfSourceImage;
   RefPtr<SourceSurface> surface = mData->GetAsSourceSurface();
   result->mSurface = surface->GetDataSurface();
   MOZ_ASSERT(result->mSurface);
 
-  return result;
+  return Move(result);
 }
 
 /* static */ already_AddRefed<ImageBitmap>
 ImageBitmap::CreateFromCloneData(nsIGlobalObject* aGlobal,
                                  ImageBitmapCloneData* aData)
 {
   RefPtr<layers::Image> data = CreateImageFromSurface(aData->mSurface);
 
--- a/dom/canvas/ImageBitmap.h
+++ b/dom/canvas/ImageBitmap.h
@@ -7,16 +7,17 @@
 #ifndef mozilla_dom_ImageBitmap_h
 #define mozilla_dom_ImageBitmap_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/ImageBitmapSource.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/Maybe.h"
+#include "mozilla/UniquePtr.h"
 #include "nsCycleCollectionParticipant.h"
 
 struct JSContext;
 struct JSStructuredCloneReader;
 struct JSStructuredCloneWriter;
 
 class nsIGlobalObject;
 
@@ -110,18 +111,18 @@ public:
 
   /*
    * Transfer ownership of buffer to caller. So this function call
    * Close() implicitly.
    */
   already_AddRefed<layers::Image>
   TransferAsImage();
 
-  ImageBitmapCloneData*
-  ToCloneData();
+  UniquePtr<ImageBitmapCloneData>
+  ToCloneData() const;
 
   static already_AddRefed<ImageBitmap>
   CreateFromCloneData(nsIGlobalObject* aGlobal, ImageBitmapCloneData* aData);
 
   static already_AddRefed<ImageBitmap>
   CreateFromOffscreenCanvas(nsIGlobalObject* aGlobal,
                             OffscreenCanvas& aOffscreenCanvas,
                             ErrorResult& aRv);