Bug 1254980 - Ensure that text/html is still written to the clipboard. r=enndeakin a=ritu
authorJorg K
Tue, 22 Mar 2016 11:47:00 -0400
changeset 323696 5be27e14eef45f7e6e9517af427bbacb33d0b7da
parent 323695 c46b441ec89f41b7e76deecd4624b477923cb7c6
child 323697 0e6e693a2ab26340b0f79fbd8b03f31a29e34b7f
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin, ritu
bugs1254980
milestone47.0a2
Bug 1254980 - Ensure that text/html is still written to the clipboard. r=enndeakin a=ritu MozReview-Commit-ID: Dz6tGtCfxgJ
widget/windows/nsClipboard.cpp
widget/windows/nsClipboard.h
widget/windows/nsDragService.cpp
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -83,17 +83,17 @@ nsClipboard::Observe(nsISupports *aSubje
   // This will be called on shutdown.
   ::OleFlushClipboard();
   ::CloseClipboard();
 
   return NS_OK;
 }
 
 //-------------------------------------------------------------------------
-UINT nsClipboard::GetFormat(const char* aMimeStr)
+UINT nsClipboard::GetFormat(const char* aMimeStr, bool aMapHTMLMime)
 {
   UINT format;
 
   if (strcmp(aMimeStr, kTextMime) == 0)
     format = CF_TEXT;
   else if (strcmp(aMimeStr, kUnicodeMime) == 0)
     format = CF_UNICODETEXT;
   else if (strcmp(aMimeStr, kRTFMime) == 0)
@@ -101,17 +101,17 @@ UINT nsClipboard::GetFormat(const char* 
   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 ||
-           strcmp(aMimeStr, kHTMLMime) == 0)
+           aMapHTMLMime && strcmp(aMimeStr, kHTMLMime) == 0)
     format = CF_HTML;
   else
     format = ::RegisterClipboardFormatW(NS_ConvertASCIItoUTF16(aMimeStr).get());
 
   return format;
 }
 
 //-------------------------------------------------------------------------
@@ -164,17 +164,19 @@ nsresult nsClipboard::SetupNativeDataObj
   dfList->Count(&cnt);
   for (i=0;i<cnt;i++) {
     nsCOMPtr<nsISupports> genericFlavor;
     dfList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
     nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
     if ( currentFlavor ) {
       nsXPIDLCString flavorStr;
       currentFlavor->ToString(getter_Copies(flavorStr));
-      UINT format = GetFormat(flavorStr);
+      // When putting data onto the clipboard, we want to maintain kHTMLMime
+      // ("text/html") and not map it to CF_HTML here since this will be done below.
+      UINT format = GetFormat(flavorStr, false);
 
       // Now tell the native IDataObject about both our mime type and 
       // the native data format
       FORMATETC fe;
       SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
       dObj->AddDataFlavor(flavorStr, &fe);
       
       // Do various things internal to the implementation, like map one
--- a/widget/windows/nsClipboard.h
+++ b/widget/windows/nsClipboard.h
@@ -46,17 +46,23 @@ public:
                                         IDataObject * aDataObj);
   static nsresult GetDataFromDataObject(IDataObject     * aDataObject,
                                         UINT              anIndex,
                                         nsIWidget       * aWindow,
                                         nsITransferable * aTransferable);
   static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aIndex, UINT aFormat, void ** aData, uint32_t * aLen);
   static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, UINT aFormat, const char * aMIMEImageFormat, void ** aData, uint32_t * aLen);
   static nsresult GetGlobalData(HGLOBAL aHGBL, void ** aData, uint32_t * aLen);
-  static UINT     GetFormat(const char* aMimeStr);
+
+  // This function returns the internal Windows clipboard format identifier
+  // for a given Mime string. The default is to map kHTMLMime ("text/html")
+  // to the clipboard format CF_HTML ("HTLM Format"), but it can also be
+  // registered as clipboard format "text/html" to support previous versions
+  // of Gecko.
+  static UINT     GetFormat(const char* aMimeStr, bool aMapHTMLMime = true);
 
   static UINT     CF_HTML;
   
 protected:
   NS_IMETHOD SetNativeClipboardData ( int32_t aWhichClipboard ) override;
   NS_IMETHOD GetNativeClipboardData ( nsITransferable * aTransferable, int32_t aWhichClipboard ) override;
   
   static bool IsInternetShortcut ( const nsAString& inFileName ) ;
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -536,24 +536,16 @@ nsDragService::IsDataFlavorSupported(con
         // 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)
           *_retval = true;                 // found it!
       }
-      else if (strcmp(aDataFlavor, kHTMLMime) == 0) {
-        // 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 (mDataObject->QueryGetData(&fe) == S_OK)
-          *_retval = true;                 // found it!
-      }
     } // else try again
   }
 
   return NS_OK;
 }
 
 
 //