Bug 1288302 - Part 1: Make css::ImageValue constructable OMT. r=xidorn
authorCameron McCormack <cam@mcc.id.au>
Thu, 20 Oct 2016 08:36:14 +0800
changeset 318615 a0488e9c00247c438cd5de57f83b4ef28747d402
parent 318614 99bf3401b43f4f621c91facce91f729688941317
child 318616 4bf6ad58821973d8071516784eb22876abf973b5
push id82973
push usercmccormack@mozilla.com
push dateThu, 20 Oct 2016 00:44:30 +0000
treeherdermozilla-inbound@6861f02dadfa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1288302
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1288302 - Part 1: Make css::ImageValue constructable OMT. r=xidorn MozReview-Commit-ID: 9J2E7VrCWJ1
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2862,32 +2862,53 @@ css::ImageValue::ImageValue(nsIURI* aURI
                             nsIPrincipal* aOriginPrincipal,
                             nsIDocument* aDocument)
   : URLValueData(do_AddRef(new PtrHolder<nsIURI>(aURI)),
                  aString,
                  do_AddRef(new PtrHolder<nsIURI>(aBaseURI, false)),
                  do_AddRef(new PtrHolder<nsIURI>(aReferrer)),
                  do_AddRef(new PtrHolder<nsIPrincipal>(aOriginPrincipal)))
 {
+  Initialize(aDocument);
+}
+
+css::ImageValue::ImageValue(
+    nsStringBuffer* aString,
+    already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
+    already_AddRefed<PtrHolder<nsIURI>> aReferrer,
+    already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal)
+  : URLValueData(aString, Move(aBaseURI), Move(aReferrer),
+                 Move(aOriginPrincipal))
+{
+}
+
+void
+css::ImageValue::Initialize(nsIDocument* aDocument)
+{
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!mInitialized);
 
   // NB: If aDocument is not the original document, we may not be able to load
   // images from aDocument.  Instead we do the image load from the original doc
   // and clone it to aDocument.
   nsIDocument* loadingDoc = aDocument->GetOriginalDocument();
   if (!loadingDoc) {
     loadingDoc = aDocument;
   }
 
-  loadingDoc->StyleImageLoader()->LoadImage(aURI, aOriginPrincipal, aReferrer,
-                                            this);
+  loadingDoc->StyleImageLoader()->LoadImage(GetURI(), mOriginPrincipal,
+                                            mReferrer, this);
 
   if (loadingDoc != aDocument) {
     aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this);
   }
+
+#ifdef DEBUG
+  mInitialized = true;
+#endif
 }
 
 css::ImageValue::~ImageValue()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
     nsIDocument* doc = iter.Key();
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -203,28 +203,42 @@ struct ImageValue final : public URLValu
   // this header is included all over.
   // aString must not be null.
   //
   // This constructor is only safe to call from the main thread.
   ImageValue(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aBaseURI,
              nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal,
              nsIDocument* aDocument);
 
+  // This constructor is safe to call from any thread, but Initialize
+  // must be called later for the object to be useful.
+  ImageValue(nsStringBuffer* aString,
+             already_AddRefed<PtrHolder<nsIURI>> aBaseURI,
+             already_AddRefed<PtrHolder<nsIURI>> aReferrer,
+             already_AddRefed<PtrHolder<nsIPrincipal>> aOriginPrincipal);
+
   ImageValue(const ImageValue&) = delete;
   ImageValue& operator=(const ImageValue&) = delete;
 
+  void Initialize(nsIDocument* aDocument);
+
   // XXXheycam We should have our own SizeOfIncludingThis method.
 
 protected:
   ~ImageValue();
 
 public:
   // Inherit Equals from URLValueData
 
   nsRefPtrHashtable<nsPtrHashKey<nsIDocument>, imgRequestProxy> mRequests;
+
+private:
+#ifdef DEBUG
+  bool mInitialized = false;
+#endif
 };
 
 struct GridNamedArea {
   nsString mName;
   uint32_t mColumnStart;
   uint32_t mColumnEnd;
   uint32_t mRowStart;
   uint32_t mRowEnd;