Backout revision 12536e9936b2 (bug 490879) because of unknown potential problems for Thunderbird 3.next
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Sun, 03 May 2009 22:03:40 +0430
changeset 27960 0cb354f894d1ca1c72edf04893250e2d2513021c
parent 27959 8e514fe5b14b0e3f81841a5ab62b091e7e90b587
child 27961 dc6e0568a058b176e8c6afd01b0b1027251fc22d
push id6805
push userehsan.akhgari@gmail.com
push dateSun, 03 May 2009 18:02:56 +0000
treeherdermozilla-central@0cb354f894d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs490879
milestone1.9.2a1pre
backs out12536e9936b2c43538eb5803937d5314ec3c4cf8
Backout revision 12536e9936b2 (bug 490879) because of unknown potential problems for Thunderbird 3.next
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/tests/Makefile.in
editor/libeditor/html/tests/green.png
editor/libeditor/html/tests/test_bug490879.xul
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -126,19 +126,16 @@
 
 // Misc
 #include "TextEditorTest.h"
 #include "nsEditorUtils.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIContentFilter.h"
 #include "nsEventDispatcher.h"
-#include "plbase64.h"
-#include "prmem.h"
-#include "nsStreamUtils.h"
 
 const PRUnichar nbsp = 160;
 
 static NS_DEFINE_CID(kCParserCID,     NS_PARSER_CID);
 
 // private clipboard data flavors for html copy/paste
 #define kHTMLContext   "text/_moz_htmlcontext"
 #define kHTMLInfo      "text/_moz_htmlinfo"
@@ -1414,35 +1411,70 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTr
     }
     else if (0 == nsCRT::strcmp(bestFlavor, kJPEGImageMime) ||
              0 == nsCRT::strcmp(bestFlavor, kPNGImageMime) ||
              0 == nsCRT::strcmp(bestFlavor, kGIFImageMime))
     {
       nsCOMPtr<nsIInputStream> imageStream(do_QueryInterface(genericDataObj));
       NS_ENSURE_TRUE(imageStream, NS_ERROR_FAILURE);
 
-      nsCString imageData;
-      rv = NS_ConsumeStream(imageStream, PR_UINT32_MAX, imageData);
+      nsCOMPtr<nsIFile> fileToUse;
+      NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(fileToUse));
+
+      if (0 == nsCRT::strcmp(bestFlavor, kJPEGImageMime))
+        fileToUse->Append(NS_LITERAL_STRING("moz-screenshot.jpg"));
+      else if (0 == nsCRT::strcmp(bestFlavor, kPNGImageMime))
+        fileToUse->Append(NS_LITERAL_STRING("moz-screenshot.png"));
+      else if (0 == nsCRT::strcmp(bestFlavor, kGIFImageMime))
+        fileToUse->Append(NS_LITERAL_STRING("moz-screenshot.gif"));
+
+      nsCOMPtr<nsILocalFile> path = do_QueryInterface(fileToUse);
+      path->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
+
+      nsCOMPtr<nsIOutputStream> outputStream;
+      rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), fileToUse);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      PRUint32 length;
+      imageStream->Available(&length);
+
+      nsCOMPtr<nsIOutputStream> bufferedOutputStream;
+      rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream), outputStream, length);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      char * base64 = PL_Base64Encode(imageData.get(), imageData.Length(), nsnull);
-      NS_ENSURE_TRUE(base64, NS_ERROR_OUT_OF_MEMORY);
+      PRUint32 numWritten;
+      rv = bufferedOutputStream->WriteFrom(imageStream, length, &numWritten);
+      NS_ENSURE_SUCCESS(rv, rv);
 
-      stuffToPaste.AssignLiteral("<IMG src=\"data:");
-      AppendUTF8toUTF16(bestFlavor, stuffToPaste);
-      stuffToPaste.AppendLiteral(";base64,");
-      AppendUTF8toUTF16(base64, stuffToPaste);
-      stuffToPaste.AppendLiteral("\" alt=\"\" >");
-      nsAutoEditBatch beginBatching(this);
-      rv = InsertHTMLWithContext(stuffToPaste, EmptyString(), EmptyString(), 
-                                 NS_LITERAL_STRING(kFileMime),
-                                 aSourceDoc,
-                                 aDestinationNode, aDestOffset,
-                                 aDoDeleteSelection);
-      PR_Free(base64);
+      // force the stream close before we try to insert the image
+      // into the document.
+      rv = bufferedOutputStream->Close();
+      NS_ENSURE_SUCCESS(rv, rv);
+      
+      nsCOMPtr<nsIURI> uri;
+      rv = NS_NewFileURI(getter_AddRefs(uri), fileToUse);
+      NS_ENSURE_SUCCESS(rv, rv);
+      nsCOMPtr<nsIURL> fileURL(do_QueryInterface(uri));
+      if (fileURL)
+      {
+        nsCAutoString urltext;
+        rv = fileURL->GetSpec(urltext);
+        if (NS_SUCCEEDED(rv) && !urltext.IsEmpty())
+        {
+          stuffToPaste.AssignLiteral("<IMG src=\"");
+          AppendUTF8toUTF16(urltext, stuffToPaste);
+          stuffToPaste.AppendLiteral("\" alt=\"\" >");
+          nsAutoEditBatch beginBatching(this);
+          rv = InsertHTMLWithContext(stuffToPaste, EmptyString(), EmptyString(), 
+                                     NS_LITERAL_STRING(kFileMime),
+                                     aSourceDoc,
+                                     aDestinationNode, aDestOffset,
+                                     aDoDeleteSelection);
+        }
+      }
     }
   }
       
   // Try to scroll the selection into view if the paste/drop succeeded
 
   // After ScrollSelectionIntoView(), the pending notifications might be
   // flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
   if (NS_SUCCEEDED(rv))
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -48,19 +48,11 @@ include $(topsrcdir)/config/rules.mk
 		test_bug366682.html \
 		test_bug432225.html \
 		test_bug455992.html \
 		test_bug456244.html \
 		test_bug478725.html \
 		test_bug480972.html \
 		$(NULL)
 
-_CHROME_TEST_FILES = \
-		test_bug490879.xul \
-		green.png \
-		$(NULL)
-
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
-libs:: $(_CHROME_TEST_FILES)
-	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
deleted file mode 100644
index 0aaec20932a3238bb9530e526049a56fbc363d20..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/editor/libeditor/html/tests/test_bug490879.xul
+++ /dev/null
@@ -1,73 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin"
-                 type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
-                 type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=490879
--->
-<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        title="Mozilla Bug 490879" onload="runTest();">
-  <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
-
-  <body xmlns="http://www.w3.org/1999/xhtml">
-  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=490879"
-     target="_blank">Mozilla Bug 490879</a>
-  <p/>
-  <iframe id="i1" width="200" height="100" src="about:blank" /><br />
-  <img id="i" src="green.png" />
-  <p/>
-  <pre id="test">
-  </pre>
-  </body>
-  <script class="testbody" type="application/javascript">
-  <![CDATA[
-
-function runTest() {
-  function verifyContent() {
-    const kExpectedImgSpec = "data:image/png;base64,";
-    var e = document.getElementById('i1');
-    var doc = e.contentDocument;
-    is(doc.getElementsByTagName("img")[0].src.substring(0, kExpectedImgSpec.length),
-       kExpectedImgSpec, "The pasted image is a base64-encoded data: URI");
-  }
-
-  function pasteInto() {
-    var e = document.getElementById('i1');
-    var doc = e.contentDocument;
-    doc.designMode = "on";
-    doc.defaultView.focus();
-    var selection = doc.defaultView.getSelection();
-    selection.removeAllRanges();
-    selection.selectAllChildren(doc.body);
-    selection.collapseToEnd();
-    doc.execCommand("paste", false, null);
-  }
-
-  function copyToClipBoard() {
-    var tmpNode = document.popupNode;
-    document.popupNode = document.getElementById("i");
-
-    const kCmd = "cmd_copyImageContents";
-    var controller = top.document.commandDispatcher
-                     .getControllerForCommand(kCmd);
-    ok((controller && controller.isCommandEnabled(kCmd)), "have copy command");
-    controller.doCommand(kCmd);
-
-    document.popupNode = tmpNode;
-  }
-
-  copyToClipBoard();
-  pasteInto();
-  verifyContent();
-
-  SimpleTest.finish();
-}
-
-SimpleTest.waitForExplicitFinish();
-]]>
-</script>
-</window>