Bug 644476 Part 1: Remove nsIXMLHttpRequest.openRequest now that it's equivalent to nsIXMLHttpRequest.open. r=smaug
authorJonas Sicking <jonas@sicking.cc>
Mon, 28 Mar 2011 13:05:52 -0700
changeset 64068 bcbbe188032f1b0996ca3b0193ed1d053020a046
parent 64067 df9338ea288b674249918e4f6605cc15ab8d3435
child 64069 c92bc89edaee63e083a66c22a4e4e0a7fd39bd59
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs644476
milestone2.2a1pre
Bug 644476 Part 1: Remove nsIXMLHttpRequest.openRequest now that it's equivalent to nsIXMLHttpRequest.open. r=smaug
content/base/public/nsIXMLHttpRequest.idl
content/base/src/nsXMLHttpRequest.cpp
content/base/test/TestGetURL.cpp
content/base/test/TestNativeXMLHttpRequest.cpp
content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
dom/src/threads/nsDOMWorkerXHR.cpp
dom/src/threads/nsDOMWorkerXHRProxiedFunctions.h
dom/src/threads/nsDOMWorkerXHRProxy.cpp
dom/src/threads/nsDOMWorkerXHRProxy.h
--- a/content/base/public/nsIXMLHttpRequest.idl
+++ b/content/base/public/nsIXMLHttpRequest.idl
@@ -104,17 +104,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(6bb91106-85f0-4d93-8cb4-e57b3d0624f2)]
+[scriptable, uuid(af62a870-820c-4981-96a3-28ab17b779e1)]
 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.
    *
@@ -182,52 +182,29 @@ interface nsIXMLHttpRequest : nsISupport
    *
    * @param header The name of the header to retrieve
    * @returns A string containing the text of the header specified.
    *          NULL if the response has not yet been received or the
    *          header does not exist in the response.
    */
   ACString getResponseHeader(in AUTF8String header);
 
-  /**
-   * Native (non-script) method to initialize a request. Note that
-   * the request is not sent until the <code>send</code> method
-   * is invoked.
-   *
-   * If there is an "active" request (that is, if open() or openRequest() has
-   * been called already), this is equivalent to calling abort().
-   *
-   * @param method The HTTP method, for example "POST" or "GET". Ignored
-   *               if the URL is not a HTTP(S) URL.
-   * @param url The URL to which to send the request.
-   * @param async Whether the request is synchronous or asynchronous
-   *              i.e. whether send returns only after the response
-   *              is received or if it returns immediately after
-   *              sending the request. In the latter case, notification
-   *              of completion is sent through the event listeners.
-   *              This argument must be true if the multipart
-   *              attribute has been set to true, or an exception will
-   *              be thrown.
-   * @param user A username for authentication if necessary.
-   * @param password A password for authentication if necessary.
-   */
-  [noscript] void   openRequest(in AUTF8String method,
-                                in AUTF8String url,
-                                in boolean async,
-                                in AString user,
-                                in AString password);
-
+%{C++
+  // note this is NOT virtual so this won't muck with the vtable!
+  inline nsresult Open(const nsACString& method, const nsACString& url,
+                       PRBool async, const nsAString& user,
+                       const nsAString& password) {
+    return Open(method, url, async, user, password, 3);
+  }
+%}
   /**
    * Meant to be a script-only method for initializing a request.
-   * The parameters are similar to the ones detailed in the
-   * description of <code>openRequest</code>, but the last
-   * 3 are optional.
    *
-   * If there is an "active" request (that is, if open() or openRequest() has
-   * been called already), this is equivalent to calling abort().
+   * If there is an "active" request (that is, if open() has been called
+   * already), this is equivalent to calling abort() and then open().
    *
    * @param method The HTTP method - either "POST" or "GET". Ignored
    *               if the URL is not a HTTP URL.
    * @param url The URL to which to send the request.
    * @param async (optional) Whether the request is synchronous or
    *              asynchronous i.e. whether send returns only after
    *              the response is received or if it returns immediately after
    *              sending the request. In the latter case, notification
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1384,17 +1384,17 @@ nsXMLHttpRequest::Abort()
     if (mUpload && !mUploadComplete) {
       mUploadComplete = PR_TRUE;
       DispatchProgressEvent(mUpload, abortStr, PR_TRUE, mUploadTransferred,
                             mUploadTotal);
     }
   }
 
   // The ChangeState call above calls onreadystatechange handlers which
-  // if they load a new url will cause nsXMLHttpRequest::OpenRequest to clear
+  // if they load a new url will cause nsXMLHttpRequest::Open to clear
   // the abort state bit. If this occurs we're not uninitialized (bug 361773).
   if (mState & XML_HTTP_REQUEST_ABORTED) {
     ChangeState(XML_HTTP_REQUEST_UNINITIALIZED, PR_FALSE);  // IE seems to do it
   }
 
   mState &= ~XML_HTTP_REQUEST_SYNCLOOPING;
 
   return NS_OK;
@@ -1661,26 +1661,28 @@ nsXMLHttpRequest::CheckChannelForCrossSi
        !method.LowerCaseEqualsLiteral("post") &&
        !method.LowerCaseEqualsLiteral("head"))) {
     mState |= XML_HTTP_REQUEST_NEED_AC_PREFLIGHT;
   }
 
   return NS_OK;
 }
 
-/* noscript void openRequest (in AUTF8String method, in AUTF8String url, in boolean async, in AString user, in AString password); */
 NS_IMETHODIMP
-nsXMLHttpRequest::OpenRequest(const nsACString& method,
-                              const nsACString& url,
-                              PRBool async,
-                              const nsAString& user,
-                              const nsAString& password)
+nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url,
+                       PRBool async, const nsAString& user,
+                       const nsAString& password, PRUint8 optional_argc)
 {
   NS_ENSURE_ARG(!method.IsEmpty());
 
+  if (!optional_argc) {
+    // No optional arguments were passed in. Default async to true.
+    async = PR_TRUE;
+  }
+
   NS_ENSURE_TRUE(mPrincipal, NS_ERROR_NOT_INITIALIZED);
 
   // Disallow HTTP/1.1 TRACE method (see bug 302489)
   // and MS IIS equivalent TRACK (see bug 381264)
   if (method.LowerCaseEqualsLiteral("trace") ||
       method.LowerCaseEqualsLiteral("track")) {
     return NS_ERROR_INVALID_ARG;
   }
@@ -1800,30 +1802,16 @@ nsXMLHttpRequest::OpenRequest(const nsAC
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   ChangeState(XML_HTTP_REQUEST_OPENED);
 
   return rv;
 }
 
-/* void open (in AUTF8String method, in AUTF8String url); */
-NS_IMETHODIMP
-nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url,
-                       PRBool async, const nsAString& user,
-                       const nsAString& password, PRUint8 optional_argc)
-{
-  if (!optional_argc) {
-    // No optional arguments were passed in. Default async to true.
-    async = PR_TRUE;
-  }
-
-  return OpenRequest(method, url, async, user, password);
-}
-
 /*
  * "Copy" from a stream.
  */
 NS_METHOD
 nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
                                    void* closure,
                                    const char* fromRawSegment,
                                    PRUint32 toOffset,
--- a/content/base/test/TestGetURL.cpp
+++ b/content/base/test/TestGetURL.cpp
@@ -71,17 +71,17 @@ nsresult TestGetURL(const nsCString& aUR
 
   nsCOMPtr<nsIPrincipal> systemPrincipal;
   rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
   TEST_ENSURE_SUCCESS(rv, "Couldn't get system principal!");
 
   rv = xhr->Init(systemPrincipal, nsnull, nsnull, nsnull);
   TEST_ENSURE_SUCCESS(rv, "Couldn't initialize the XHR!");
 
-  rv = xhr->OpenRequest(getString, aURL, PR_FALSE, empty, empty);
+  rv = xhr->Open(getString, aURL, PR_FALSE, empty, empty);
   TEST_ENSURE_SUCCESS(rv, "OpenRequest failed!");
 
   rv = xhr->Send(nsnull);
   TEST_ENSURE_SUCCESS(rv, "Send failed!");
 
   nsAutoString response;
   rv = xhr->GetResponseText(response);
   TEST_ENSURE_SUCCESS(rv, "GetResponse failed!");
--- a/content/base/test/TestNativeXMLHttpRequest.cpp
+++ b/content/base/test/TestNativeXMLHttpRequest.cpp
@@ -72,33 +72,33 @@ nsresult TestNativeXMLHttpRequest()
     do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
   TEST_ENSURE_SUCCESS(rv, "Couldn't create nsIXMLHttpRequest instance!");
 
   NS_NAMED_LITERAL_CSTRING(getString, "GET");
   NS_NAMED_LITERAL_CSTRING(testURL, TEST_URL);
   const nsAString& empty = EmptyString();
   
   printf("*** About to see an expected warning about mPrincipal:\n");
-  rv = xhr->OpenRequest(getString, testURL, PR_FALSE, empty, empty);
+  rv = xhr->Open(getString, testURL, PR_FALSE, empty, empty);
   printf("*** End of expected warning output.\n");
-  TEST_ENSURE_FAILED(rv, "OpenRequest should have failed!");
+  TEST_ENSURE_FAILED(rv, "Open should have failed!");
 
   nsCOMPtr<nsIScriptSecurityManager> secman =
     do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
   TEST_ENSURE_SUCCESS(rv, "Couldn't get script security manager!");
 
   nsCOMPtr<nsIPrincipal> systemPrincipal;
   rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
   TEST_ENSURE_SUCCESS(rv, "Couldn't get system principal!");
 
   rv = xhr->Init(systemPrincipal, nsnull, nsnull, nsnull);
   TEST_ENSURE_SUCCESS(rv, "Couldn't initialize the XHR!");
 
-  rv = xhr->OpenRequest(getString, testURL, PR_FALSE, empty, empty);
-  TEST_ENSURE_SUCCESS(rv, "OpenRequest failed!");
+  rv = xhr->Open(getString, testURL, PR_FALSE, empty, empty);
+  TEST_ENSURE_SUCCESS(rv, "Open failed!");
 
   rv = xhr->Send(nsnull);
   TEST_ENSURE_SUCCESS(rv, "Send failed!");
 
   nsAutoString response;
   rv = xhr->GetResponseText(response);
   TEST_ENSURE_SUCCESS(rv, "GetResponse failed!");
 
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp
@@ -212,18 +212,18 @@ nsXULTemplateQueryProcessorXML::GetDatas
 
     nsCOMPtr<nsIXMLHttpRequest> req =
         do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsPIDOMWindow> owner = do_QueryInterface(scriptObject);
     req->Init(docPrincipal, context, owner, nsnull);
 
-    rv = req->OpenRequest(NS_LITERAL_CSTRING("GET"), uriStr, PR_TRUE,
-                          EmptyString(), EmptyString());
+    rv = req->Open(NS_LITERAL_CSTRING("GET"), uriStr, PR_TRUE,
+                   EmptyString(), EmptyString());
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(req));
     rv = target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = target->AddEventListener(NS_LITERAL_STRING("error"), this, PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/src/threads/nsDOMWorkerXHR.cpp
+++ b/dom/src/threads/nsDOMWorkerXHR.cpp
@@ -635,50 +635,34 @@ nsDOMWorkerXHR::GetResponseHeader(const 
 
   nsresult rv = mXHRProxy->GetResponseHeader(aHeader, _retval);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWorkerXHR::OpenRequest(const nsACString& aMethod,
-                            const nsACString& aUrl,
-                            PRBool aAsync,
-                            const nsAString& aUser,
-                            const nsAString& aPassword)
-{
-  NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
-
-  if (mCanceled) {
-    return NS_ERROR_ABORT;
-  }
-
-  nsresult rv = mXHRProxy->OpenRequest(aMethod, aUrl, aAsync, aUser, aPassword);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMWorkerXHR::Open(const nsACString& aMethod, const nsACString& aUrl,
                      PRBool aAsync, const nsAString& aUser,
                      const nsAString& aPassword, PRUint8 optional_argc)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
 
   if (mCanceled) {
     return NS_ERROR_ABORT;
   }
 
   if (!optional_argc) {
       aAsync = PR_TRUE;
   }
 
-  return OpenRequest(aMethod, aUrl, aAsync, aUser, aPassword);
+  nsresult rv = mXHRProxy->Open(aMethod, aUrl, aAsync, aUser, aPassword);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWorkerXHR::Send(nsIVariant* aBody)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
 
   if (mCanceled) {
--- a/dom/src/threads/nsDOMWorkerXHRProxiedFunctions.h
+++ b/dom/src/threads/nsDOMWorkerXHRProxiedFunctions.h
@@ -131,27 +131,27 @@ namespace nsDOMWorkerProxiedXHRFunctions
   class Abort : public SyncEventCapturingRunnable
   {
   public:
     virtual nsresult RunInternal() {
       return mXHR->Abort();
     }
   };
 
-  class OpenRequest : public SyncEventCapturingRunnable
+  class Open : public SyncEventCapturingRunnable
   {
   public:
-    OpenRequest(const nsACString& aMethod, const nsACString& aUrl,
-                PRBool aAsync, const nsAString& aUser,
-                const nsAString& aPassword)
+    Open(const nsACString& aMethod, const nsACString& aUrl,
+         PRBool aAsync, const nsAString& aUser,
+         const nsAString& aPassword)
     : mMethod(aMethod), mUrl(aUrl), mAsync(aAsync), mUser(aUser),
       mPassword(aPassword) { }
   
     virtual nsresult RunInternal() {
-      return mXHR->OpenRequest(mMethod, mUrl, mAsync, mUser, mPassword);
+      return mXHR->Open(mMethod, mUrl, mAsync, mUser, mPassword);
     }
 
   private:
     nsCString mMethod;
     nsCString mUrl;
     PRBool mAsync;
     nsString mUser;
     nsString mPassword;
--- a/dom/src/threads/nsDOMWorkerXHRProxy.cpp
+++ b/dom/src/threads/nsDOMWorkerXHRProxy.cpp
@@ -678,32 +678,32 @@ nsDOMWorkerXHRProxy::DispatchPrematureAb
   state->readyState = 4; // COMPLETED, from nsXMLHttpRequest
   mXHR->GetStatusText(state->statusText);
   mXHR->GetStatus(&state->status);
 
   return HandleEventRunnable(xhrEvent);
 }
 
 nsresult
-nsDOMWorkerXHRProxy::MaybeDispatchPrematureAbortEvents(PRBool aFromOpenRequest)
+nsDOMWorkerXHRProxy::MaybeDispatchPrematureAbortEvents(PRBool aFromOpen)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   nsresult rv;
   nsIDOMEventTarget* target;
 
   if (mDownloadProgressInfo) {
     target = static_cast<nsDOMWorkerMessageHandler*>(mWorkerXHR);
     NS_ASSERTION(target, "Must have target here!");
 
     rv = DispatchPrematureAbortEvents(LISTENER_TYPE_READYSTATECHANGE, target,
                                       nsnull);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (aFromOpenRequest) {
+    if (aFromOpen) {
       rv = DispatchPrematureAbortEvents(LISTENER_TYPE_ABORT, target,
                                         mDownloadProgressInfo);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   if (mUploadProgressInfo) {
     target = static_cast<nsDOMWorkerMessageHandler*>(mWorkerXHR->mUpload);
@@ -861,44 +861,44 @@ nsDOMWorkerXHRProxy::HandleEventRunnable
     rv = nsDOMThreadService::get()->Dispatch(mWorkerXHR->mWorker, aRunnable);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult
-nsDOMWorkerXHRProxy::OpenRequest(const nsACString& aMethod,
-                                 const nsACString& aUrl,
-                                 PRBool aAsync,
-                                 const nsAString& aUser,
-                                 const nsAString& aPassword)
+nsDOMWorkerXHRProxy::Open(const nsACString& aMethod,
+                          const nsACString& aUrl,
+                          PRBool aAsync,
+                          const nsAString& aUser,
+                          const nsAString& aPassword)
 {
   if (!NS_IsMainThread()) {
     mSyncRequest = !aAsync;
 
     // Always do async behind the scenes!
-    RUN_PROXIED_FUNCTION(OpenRequest,
+    RUN_PROXIED_FUNCTION(Open,
                          (aMethod, aUrl, PR_TRUE, aUser, aPassword));
     return NS_OK;
   }
 
   if (mCanceled) {
     return NS_ERROR_ABORT;
   }
 
   nsresult rv = MaybeDispatchPrematureAbortEvents(PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = mXHR->OpenRequest(aMethod, aUrl, aAsync, aUser, aPassword);
+  rv = mXHR->Open(aMethod, aUrl, aAsync, aUser, aPassword);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // Do this after OpenRequest is called so that we will continue to run events
-  // from the old channel if OpenRequest fails. Any events generated by the
-  // OpenRequest method will always run regardless of channel ID.
+  // Do this after Open is called so that we will continue to run events
+  // from the old channel if Open fails. Any events generated by the
+  // Open method will always run regardless of channel ID.
   mChannelID++;
 
   return NS_OK;
 }
 
 nsresult
 nsDOMWorkerXHRProxy::Abort()
 {
--- a/dom/src/threads/nsDOMWorkerXHRProxy.h
+++ b/dom/src/threads/nsDOMWorkerXHRProxy.h
@@ -87,21 +87,21 @@ public:
 
   nsDOMWorkerXHRProxy(nsDOMWorkerXHR* aWorkerXHR);
   virtual ~nsDOMWorkerXHRProxy();
 
   nsresult Init();
 
   nsIXMLHttpRequest* GetXMLHttpRequest();
 
-  nsresult OpenRequest(const nsACString& aMethod,
-                       const nsACString& aUrl,
-                       PRBool aAsync,
-                       const nsAString& aUser,
-                       const nsAString& aPassword);
+  nsresult Open(const nsACString& aMethod,
+                const nsACString& aUrl,
+                PRBool aAsync,
+                const nsAString& aUser,
+                const nsAString& aPassword);
 
   nsresult Abort();
 
   SyncEventQueue* SetSyncEventQueue(SyncEventQueue* aQueue);
 
   PRInt32 ChannelID() {
     return mChannelID;
   }