Bug 853162 - Remove XMLHttpRequest.sendAsBinary() interface. r=smaug
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Sun, 08 Feb 2015 17:01:44 +0100
changeset 230700 0ccbd75a97c77c8e2607d8862835b6a40071db74
parent 230699 4f2bdb9b4d5e35183eacb18afe3b46356b5483b8
child 230701 ff091bb244178c18862316fee7ea4fcbeb5b235e
push id28334
push userkwierso@gmail.com
push dateThu, 26 Feb 2015 01:18:38 +0000
treeherdermozilla-central@b11c67d6d2f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs853162
milestone39.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 853162 - Remove XMLHttpRequest.sendAsBinary() interface. r=smaug Should use send(Blob) instead. Thanks to Ms2ger for help fixing test failures.
dom/base/nsDeprecatedOperationList.h
dom/base/nsIXMLHttpRequest.idl
dom/base/nsXMLHttpRequest.cpp
dom/base/nsXMLHttpRequest.h
dom/base/test/test_xhr_progressevents.html
dom/locales/en-US/chrome/dom/dom.properties
dom/webidl/XMLHttpRequest.webidl
dom/workers/XMLHttpRequest.cpp
dom/workers/XMLHttpRequest.h
--- a/dom/base/nsDeprecatedOperationList.h
+++ b/dom/base/nsDeprecatedOperationList.h
@@ -33,11 +33,10 @@ DEPRECATED_OPERATION(GetSetUserData)
 DEPRECATED_OPERATION(MozGetAsFile)
 DEPRECATED_OPERATION(UseOfCaptureEvents)
 DEPRECATED_OPERATION(UseOfReleaseEvents)
 DEPRECATED_OPERATION(UseOfDOM3LoadMethod)
 DEPRECATED_OPERATION(ShowModalDialog)
 DEPRECATED_OPERATION(Window_Content)
 DEPRECATED_OPERATION(SyncXMLHttpRequest)
 DEPRECATED_OPERATION(DataContainerEvent)
-DEPRECATED_OPERATION(SendAsBinary)
 DEPRECATED_OPERATION(Window_Controllers)
 DEPRECATED_OPERATION(ImportXULIntoContent)
--- a/dom/base/nsIXMLHttpRequest.idl
+++ b/dom/base/nsIXMLHttpRequest.idl
@@ -63,17 +63,17 @@ interface nsIXMLHttpRequestUpload : nsIX
  *   The 'onload', 'onerror', and 'onreadystatechange' attributes moved to
  *   nsIJSXMLHttpRequest, but if you're coding in C++ you should avoid using
  *   those.
  *
  * Conclusion: Do not use event listeners on XMLHttpRequest from C++, unless
  * you're aware of all the security implications.  And then think twice about
  * it.
  */
-[scriptable, uuid(704e91dc-a3f6-4e4d-9f5f-4bb85159aeb7)]
+[scriptable, uuid(6f54214c-7175-498d-9d2d-0429e38c2869)]
 interface nsIXMLHttpRequest : nsISupports
 {
   /**
    * The request uses a channel in order to perform the
    * request.  This attribute represents the channel used
    * for the request.  NULL if the channel has not yet been
    * created.
    *
@@ -206,25 +206,16 @@ interface nsIXMLHttpRequest : nsISupport
    *             treated as part of the message body.  The MIME type of
    *             the stream should be specified by setting the Content-
    *             Type header via the setRequestHeader method before
    *             calling send.
    */
   void   send([optional] in nsIVariant body);
 
   /**
-   * A variant of the send() method used to send binary data.
-   *
-   * @param body The request body as a DOM string.  The string data will be
-   *             converted to a single-byte string by truncation (i.e., the
-   *             high-order byte of each character will be discarded).
-   */
-  void   sendAsBinary(in DOMString body);
-
-  /**
    * Sets a HTTP request header for HTTP requests. You must call open
    * before setting the request headers.
    *
    * @param header The name of the header to set in the request.
    * @param value The body of the header.
    */
   void   setRequestHeader(in ACString header, in ACString value);
 
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -2345,70 +2345,16 @@ nsXMLHttpRequest::ChangeStateToDone()
     // for that and throw. Also calling the various status
     // methods/members will not throw.
     // This matches what IE does.
     mChannel = nullptr;
     mCORSPreflightChannel = nullptr;
   }
 }
 
-NS_IMETHODIMP
-nsXMLHttpRequest::SendAsBinary(const nsAString &aBody)
-{
-  ErrorResult rv;
-  SendAsBinary(aBody, rv);
-  return rv.ErrorCode();
-}
-
-void
-nsXMLHttpRequest::SendAsBinary(const nsAString &aBody,
-                               ErrorResult& aRv)
-{
-  char *data = static_cast<char*>(NS_Alloc(aBody.Length() + 1));
-  if (!data) {
-    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-    return;
-  }
-
-  if (GetOwner() && GetOwner()->GetExtantDoc()) {
-    GetOwner()->GetExtantDoc()->WarnOnceAbout(nsIDocument::eSendAsBinary);
-  }
-
-  nsAString::const_iterator iter, end;
-  aBody.BeginReading(iter);
-  aBody.EndReading(end);
-  char *p = data;
-  while (iter != end) {
-    if (*iter & 0xFF00) {
-      NS_Free(data);
-      aRv.Throw(NS_ERROR_DOM_INVALID_CHARACTER_ERR);
-      return;
-    }
-    *p++ = static_cast<char>(*iter++);
-  }
-  *p = '\0';
-
-  nsCOMPtr<nsIInputStream> stream;
-  aRv = NS_NewByteInputStream(getter_AddRefs(stream), data, aBody.Length(),
-                              NS_ASSIGNMENT_ADOPT);
-  if (aRv.Failed()) {
-    NS_Free(data);
-    return;
-  }
-
-  nsCOMPtr<nsIWritableVariant> variant = new nsVariant();
-
-  aRv = variant->SetAsISupports(stream);
-  if (aRv.Failed()) {
-    return;
-  }
-
-  aRv = Send(variant);
-}
-
 static nsresult
 GetRequestBody(nsIDOMDocument* aDoc, nsIInputStream** aResult,
                uint64_t* aContentLength, nsACString& aContentType,
                nsACString& aCharset)
 {
   aContentType.AssignLiteral("application/xml");
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDoc));
   NS_ENSURE_STATE(doc);
--- a/dom/base/nsXMLHttpRequest.h
+++ b/dom/base/nsXMLHttpRequest.h
@@ -483,17 +483,16 @@ public:
         Send(aCx, dataAsString, aRv);
       } else {
         aRv.Throw(NS_ERROR_FAILURE);
       }
       return;
     }
     aRv = Send(RequestBody(aStream));
   }
-  void SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
 
   void Abort();
 
   // response
   void GetResponseURL(nsAString& aUrl);
   uint32_t Status();
   void GetStatusText(nsCString& aStatusText);
   void GetResponseHeader(const nsACString& aHeader, nsACString& aResult,
--- a/dom/base/test/test_xhr_progressevents.html
+++ b/dom/base/test/test_xhr_progressevents.html
@@ -92,17 +92,23 @@ function updateProgress(e, data, testNam
   data.pendingBytes -= e.loaded - data.receivedBytes;
   data.receivedResult = response;
   data.receivedBytes = e.loaded;
 }
 
 function sendData(s) {
   var xhr = new XMLHttpRequest();
   xhr.open("POST", "progressserver.sjs?send");
-  xhr.sendAsBinary(s);
+  // The Blob constructor encodes String elements as UTF-8;
+  // for straight bytes, manually convert to ArrayBuffer first
+  var buffer = new Uint8Array(s.length);
+  for (var i = 0; i < s.length; ++i) {
+    buffer[i] = s.charCodeAt(i) & 0xff;
+  };
+  xhr.send(new Blob([buffer]));
 }
 
 function closeConn() {
   log("in closeConn");
   var xhr = new XMLHttpRequest();
   xhr.open("POST", "progressserver.sjs?close");
   xhr.send();
   return xhr;
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -148,18 +148,16 @@ UseOfDOM3LoadMethodWarning=Use of docume
 ShowModalDialogWarning=Use of window.showModalDialog() is deprecated. Use window.open() instead. For more help https://developer.mozilla.org/en-US/docs/Web/API/Window.open
 # LOCALIZATION NOTE: Do not translate "window._content" or "window.content"
 Window_ContentWarning=window._content is deprecated.  Please use window.content instead.
 # LOCALIZATION NOTE: Do not translate "XMLHttpRequest"
 SyncXMLHttpRequestWarning=Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/
 ImplicitMetaViewportTagFallback=No meta-viewport tag found. Please explicitly specify one to prevent unexpected behavioural changes in future versions. For more help https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag
 # LOCALIZATION NOTE: Do not translate "DataContainerEvent" or "CustomEvent"
 DataContainerEventWarning=Use of DataContainerEvent is deprecated. Use CustomEvent instead.
-# LOCALIZATION NOTE: Do not translate "sendAsBinary" or "send(Blob data)"
-SendAsBinaryWarning=The non-standard sendAsBinary method is deprecated and will soon be removed. Use the standard send(Blob data) method instead.
 # LOCALIZATION NOTE: Do not translate "window.controllers"
 Window_ControllersWarning=window.controllers is deprecated. Do not use it for UA detection.
 ImportXULIntoContentWarning=Importing XUL nodes into a content document is deprecated. This functionality may be removed soon.
 XMLDocumentLoadPrincipalMismatch=Use of document.load forbidden on Documents that come from other Windows. Only the Window in which a Document was created is allowed to call .load on that Document. Preferably, use XMLHttpRequest instead.
 # LOCALIZATION NOTE: Do not translate "IndexedDB".
 IndexedDBTransactionAbortNavigation=An IndexedDB transaction that was not yet complete has been aborted due to page navigation.
 # LOCALIZATION NOTE (WillChangeBudgetWarning): Do not translate Will-change, %1$S,%2$S,%3$S are numbers.
 WillChangeBudgetWarning=Will-change memory consumption is too high. Surface area covers %1$S pixels, budget is the document surface area multiplied by %2$S (%3$S pixels). All occurences of will-change in the document are ignored when over budget.
--- a/dom/webidl/XMLHttpRequest.webidl
+++ b/dom/webidl/XMLHttpRequest.webidl
@@ -135,16 +135,14 @@ interface XMLHttpRequest : XMLHttpReques
   // Mozilla-specific stuff
 
   [ChromeOnly, SetterThrows=Workers]
   attribute boolean mozBackgroundRequest;
 
   [ChromeOnly, Exposed=Window]
   readonly attribute MozChannel? channel;
 
-  [Throws]
-  void sendAsBinary(DOMString body);
   [Throws, ChromeOnly, Exposed=Window]
   any getInterface(IID iid);
 
   readonly attribute boolean mozAnon;
   readonly attribute boolean mozSystem;
 };
--- a/dom/workers/XMLHttpRequest.cpp
+++ b/dom/workers/XMLHttpRequest.cpp
@@ -2209,24 +2209,16 @@ XMLHttpRequest::Send(const ArrayBuffer& 
 void
 XMLHttpRequest::Send(const ArrayBufferView& aBody, ErrorResult& aRv)
 {
   JS::Rooted<JSObject*> obj(mWorkerPrivate->GetJSContext(), aBody.Obj());
   return Send(obj, aRv);
 }
 
 void
-XMLHttpRequest::SendAsBinary(const nsAString& aBody, ErrorResult& aRv)
-{
-  NS_NOTYETIMPLEMENTED("Implement me!");
-  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
-  return;
-}
-
-void
 XMLHttpRequest::Abort(ErrorResult& aRv)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
   if (mCanceled) {
     aRv.ThrowUncatchableException();
     return;
   }
--- a/dom/workers/XMLHttpRequest.h
+++ b/dom/workers/XMLHttpRequest.h
@@ -174,19 +174,16 @@ public:
 
   void
   Send(const ArrayBuffer& aBody, ErrorResult& aRv);
 
   void
   Send(const ArrayBufferView& aBody, ErrorResult& aRv);
 
   void
-  SendAsBinary(const nsAString& aBody, ErrorResult& aRv);
-
-  void
   Abort(ErrorResult& aRv);
 
   void
   GetResponseURL(nsAString& aUrl) const
   {
     aUrl = mStateData.mResponseURL;
   }