Bug 814001 - Less surprising serializeToStream callback calls on content. r=bz, a=lsblakk
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 15 Dec 2012 03:41:03 +0200
changeset 82103 f5ea6386c682d91063683346a945fefe7fd0e538
parent 82102 453fe2d875f6d25b4f449079255c016371e112a2
child 82104 a68f770eb7969ed9b27049be24c30886bc84c604
push id353
push useropettay@mozilla.com
push dateSat, 15 Dec 2012 01:58:12 +0000
reviewersbz, lsblakk
bugs814001
milestone10.0.11esrpre
Bug 814001 - Less surprising serializeToStream callback calls on content. r=bz, a=lsblakk
content/base/src/nsDocumentEncoder.cpp
content/base/src/nsXMLHttpRequest.cpp
--- a/content/base/src/nsDocumentEncoder.cpp
+++ b/content/base/src/nsDocumentEncoder.cpp
@@ -1147,22 +1147,28 @@ nsDocumentEncoder::EncodeToStream(nsIOut
                                                    getter_AddRefs(mUnicodeEncoder));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mMimeType.LowerCaseEqualsLiteral("text/plain")) {
     rv = mUnicodeEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  mStream = aStream;
-
+  bool chromeCaller = nsContentUtils::IsCallerChrome();
+  if (chromeCaller) {
+    mStream = aStream;
+  }
   nsAutoString buf;
 
   rv = EncodeToString(buf);
 
+  if (!chromeCaller) {
+    mStream = aStream;
+  }
+
   // Force a flush of the last chunk of data.
   FlushText(buf, true);
 
   mStream = nsnull;
   mUnicodeEncoder = nsnull;
 
   return rv;
 }
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -2200,18 +2200,22 @@ GetRequestBody(nsIVariant* aBody, nsIInp
                                getter_AddRefs(storStream));
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIOutputStream> output;
       rv = storStream->GetOutputStream(0, getter_AddRefs(output));
       NS_ENSURE_SUCCESS(rv, rv);
 
       // Make sure to use the encoding we'll send
-      rv = serializer->SerializeToStream(doc, output, aCharset);
-      NS_ENSURE_SUCCESS(rv, rv);
+      {
+        nsCxPusher pusher;
+        pusher.PushNull();
+        rv = serializer->SerializeToStream(doc, output, aCharset);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
 
       output->Close();
 
       return storStream->NewInputStream(0, aResult);
     }
 
     // nsISupportsString?
     nsCOMPtr<nsISupportsString> wstr = do_QueryInterface(supports);