Bug 1298243 part 3. Restrict mutation of a DataTransferItem's kind to codepaths that are actually changing its data. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 10 Oct 2016 21:07:47 -0400
changeset 317333 1873ffaafd2598b605658031b389baca35df2aa5
parent 317332 9a4c0703e8251bd951f97919d8370de2926e2f07
child 317334 5725d27a0bf144266dcc7a98062c935fe8e536bf
push id82629
push userbzbarsky@mozilla.com
push dateTue, 11 Oct 2016 01:38:11 +0000
treeherdermozilla-inbound@0c1078ea4e6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1298243
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 1298243 part 3. Restrict mutation of a DataTransferItem's kind to codepaths that are actually changing its data. r=mystor
dom/events/DataTransfer.cpp
dom/events/DataTransferItem.h
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1470,18 +1470,18 @@ DataTransfer::FillAllExternalData()
   }
 }
 
 void
 DataTransfer::FillInExternalCustomTypes(uint32_t aIndex,
                                         nsIPrincipal* aPrincipal)
 {
   RefPtr<DataTransferItem> item = new DataTransferItem(this,
-                                                       NS_LITERAL_STRING(kCustomTypesMime));
-  item->SetKind(DataTransferItem::KIND_STRING);
+                                                       NS_LITERAL_STRING(kCustomTypesMime),
+                                                       DataTransferItem::KIND_STRING);
   item->SetIndex(aIndex);
 
   nsCOMPtr<nsIVariant> variant = item->DataNoSecurityCheck();
   if (!variant) {
     return;
   }
 
   FillInExternalCustomTypes(variant, aIndex, aPrincipal);
--- a/dom/events/DataTransferItem.h
+++ b/dom/events/DataTransferItem.h
@@ -30,20 +30,21 @@ public:
   // we can have other kinds then just FILE and STRING. These others are simply
   // marked as "other" and can only be produced throug the Moz* APIs.
   enum eKind {
     KIND_FILE,
     KIND_STRING,
     KIND_OTHER,
   };
 
-  DataTransferItem(DataTransfer* aDataTransfer, const nsAString& aType)
+  DataTransferItem(DataTransfer* aDataTransfer, const nsAString& aType,
+                   eKind aKind = KIND_OTHER)
     : mIndex(0)
     , mChromeOnly(false)
-    , mKind(KIND_OTHER)
+    , mKind(aKind)
     , mType(aType)
     , mDataTransfer(aDataTransfer)
   {
     MOZ_ASSERT(mDataTransfer, "Must be associated with a DataTransfer");
   }
 
   already_AddRefed<DataTransferItem> Clone(DataTransfer* aDataTransfer) const;
 
@@ -73,20 +74,16 @@ public:
   {
     aType = mType;
   }
 
   eKind Kind() const
   {
     return mKind;
   }
-  void SetKind(eKind aKind)
-  {
-    mKind = aKind;
-  }
 
   already_AddRefed<File>
   GetAsFile(const Maybe<nsIPrincipal*>& aSubjectPrincipal, ErrorResult& aRv);
 
   already_AddRefed<FileSystemEntry>
   GetAsEntry(const Maybe<nsIPrincipal*>& aSubjectPrincipal, ErrorResult& aRv);
 
   DataTransfer* GetParentObject() const
@@ -100,16 +97,19 @@ public:
   }
   void SetPrincipal(nsIPrincipal* aPrincipal)
   {
     mPrincipal = aPrincipal;
   }
 
   already_AddRefed<nsIVariant> DataNoSecurityCheck();
   already_AddRefed<nsIVariant> Data(nsIPrincipal* aPrincipal, ErrorResult& aRv);
+
+  // Note: This can modify the mKind.  Callers of this method must let the
+  // relevant DataTransfer know, because its types list can change as a result.
   void SetData(nsIVariant* aData);
 
   uint32_t Index() const
   {
     return mIndex;
   }
   void SetIndex(uint32_t aIndex)
   {