Bug 586587 - Add support for drag and drop of HTML to Firefox. r=jimm
☠☠ backed out by 45f4f9b91b97 ☠ ☠
authorBen Davey <ben@ephox.com>
Wed, 23 Apr 2014 14:58:00 -0400
changeset 180059 d5a514b9a0db31234c541fb0bdf65d72a2afee9e
parent 180058 5c026fd7e73c1b8bfcda08deae60434a0d24ef61
child 180060 ace4dd4263499c5cc8592af910ae464ee212f87c
push id26653
push usercbook@mozilla.com
push dateFri, 25 Apr 2014 10:50:28 +0000
treeherdermozilla-central@2b02d933c39a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs586587
milestone31.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 586587 - Add support for drag and drop of HTML to Firefox. r=jimm
dom/events/DataTransfer.cpp
widget/windows/nsClipboard.cpp
widget/windows/nsDragService.cpp
widget/xpwidgets/nsPrimitiveHelpers.cpp
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1272,16 +1272,23 @@ DataTransfer::FillInExternalData(Transfe
 
     nsCOMPtr<nsISupportsString> supportsstr = do_QueryInterface(data);
     if (supportsstr) {
       nsAutoString str;
       supportsstr->GetData(str);
       variant->SetAsAString(str);
     }
     else {
-      variant->SetAsISupports(data);
+      nsCOMPtr<nsISupportsCString> supportscstr = do_QueryInterface(data);
+      if (supportscstr) {
+        nsAutoCString str;
+        supportscstr->GetData(str);
+        variant->SetAsACString(str);
+      } else {
+        variant->SetAsISupports(data);
+      }
     }
 
     aItem.mData = variant;
   }
 
 } // namespace dom
 } // namespace mozilla
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -98,17 +98,18 @@ UINT nsClipboard::GetFormat(const char* 
     format = CF_UNICODETEXT;
   else if (strcmp(aMimeStr, kJPEGImageMime) == 0 ||
            strcmp(aMimeStr, kJPGImageMime) == 0 ||
            strcmp(aMimeStr, kPNGImageMime) == 0)
     format = CF_DIBV5;
   else if (strcmp(aMimeStr, kFileMime) == 0 ||
            strcmp(aMimeStr, kFilePromiseMime) == 0)
     format = CF_HDROP;
-  else if (strcmp(aMimeStr, kNativeHTMLMime) == 0)
+  else if (strcmp(aMimeStr, kNativeHTMLMime) == 0 ||
+           strcmp(aMimeStr, kHTMLMime) == 0)
     format = CF_HTML;
   else
     format = ::RegisterClipboardFormatW(NS_ConvertASCIItoUTF16(aMimeStr).get());
 
   return format;
 }
 
 //-------------------------------------------------------------------------
@@ -636,17 +637,18 @@ nsresult nsClipboard::GetDataFromDataObj
           if ( strcmp(flavorStr, kFileMime) == 0 ) {
             // we have a file path in |data|. Create an nsLocalFile object.
             nsDependentString filepath(reinterpret_cast<char16_t*>(data));
             nsCOMPtr<nsIFile> file;
             if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, false, getter_AddRefs(file))) )
               genericDataWrapper = do_QueryInterface(file);
             nsMemory::Free(data);
           }
-        else if ( strcmp(flavorStr, kNativeHTMLMime) == 0) {
+        else if ( strcmp(flavorStr, kNativeHTMLMime) == 0 ||
+                  strcmp(flavorStr, kHTMLMime) == 0) {
           // the editor folks want CF_HTML exactly as it's on the clipboard, no conversions,
           // no fancy stuff. Pull it off the clipboard, stuff it into a wrapper and hand
           // it back to them.
           if ( FindPlatformHTML(aDataObject, anIndex, &data, &dataLen) )
             nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, data, dataLen, getter_AddRefs(genericDataWrapper) );
           else
           {
             nsMemory::Free(data);
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -512,40 +512,48 @@ nsDragService::IsDataFlavorSupported(con
   else {
     // Ok, so we have a single object. Check to see if has the correct
     // data type. Since this can come from an outside app, we also
     // need to see if we need to perform text->unicode conversion if
     // the client asked for unicode and it wasn't available.
     format = nsClipboard::GetFormat(aDataFlavor);
     SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
                   TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
-    if (mDataObject->QueryGetData(&fe) == S_OK)
+    if (SUCCEEDED(mDataObject->QueryGetData(&fe)))
       *_retval = true;                 // found it!
     else {
       // We haven't found the exact flavor the client asked for, but
       // maybe we can still find it from something else that's on the
       // clipboard
       if (strcmp(aDataFlavor, kUnicodeMime) == 0) {
         // client asked for unicode and it wasn't present, check if we
         // have CF_TEXT.  We'll handle the actual data substitution in
         // the data object.
         format = nsClipboard::GetFormat(kTextMime);
         SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
                       TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
-        if (mDataObject->QueryGetData(&fe) == S_OK)
+        if (SUCCEEDED(mDataObject->QueryGetData(&fe)))
           *_retval = true;                 // found it!
       }
       else if (strcmp(aDataFlavor, kURLMime) == 0) {
         // client asked for a url and it wasn't present, but if we
         // have a file, then we have a URL to give them (the path, or
         // the internal URL if an InternetShortcut).
         format = nsClipboard::GetFormat(kFileMime);
         SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
                       TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
-        if (mDataObject->QueryGetData(&fe) == S_OK)
+        if (SUCCEEDED(mDataObject->QueryGetData(&fe)))
+          *_retval = true;                 // found it!
+      }
+      else if (!strcmp(aDataFlavor, kHTMLMime)) {
+        // if the client wants html, maybe it's in "HTML Format"
+        format = nsClipboard::GetFormat(kHTMLMime);
+        SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
+                      TYMED_HGLOBAL);
+        if (SUCCEEDED(mDataObject->QueryGetData(&fe)))
           *_retval = true;                 // found it!
       }
     } // else try again
   }
 
   return NS_OK;
 }
 
--- a/widget/xpwidgets/nsPrimitiveHelpers.cpp
+++ b/widget/xpwidgets/nsPrimitiveHelpers.cpp
@@ -48,17 +48,19 @@
 //
 void
 nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void* aDataBuff,
                                                  uint32_t aDataLen, nsISupports** aPrimitive )
 {
   if ( !aPrimitive )
     return;
 
-  if ( strcmp(aFlavor,kTextMime) == 0 || strcmp(aFlavor,kNativeHTMLMime) == 0 ) {
+  if ( strcmp(aFlavor,kTextMime) == 0 ||
+       strcmp(aFlavor,kNativeHTMLMime) == 0 ||
+       strcmp(aFlavor,kHTMLMime) == 0) {
     nsCOMPtr<nsISupportsCString> primitive =
         do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID);
     if ( primitive ) {
       const char * start = reinterpret_cast<const char*>(aDataBuff);
       primitive->SetData(Substring(start, start + aDataLen));
       NS_ADDREF(*aPrimitive = primitive);
     }
   }