Bug 800386. Fix getInterface from JS on XMLHttpRequest objects to actually work. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 15 Oct 2012 23:12:03 -0400
changeset 110372 c317ac04497a6e9ade1d6650f746d72aa6a61035
parent 110371 2297babdb84d22a4ae731d3592658350a1c0794d
child 110373 fb167937d25b7f274230d714482c332137c22d0a
push id23680
push useremorley@mozilla.com
push dateTue, 16 Oct 2012 08:09:24 +0000
treeherdermozilla-central@8f145599e4bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs800386
milestone19.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 800386. Fix getInterface from JS on XMLHttpRequest objects to actually work. r=khuey
content/base/src/nsXMLHttpRequest.cpp
content/base/src/nsXMLHttpRequest.h
content/base/test/chrome/Makefile.in
content/base/test/chrome/test_bug800386.xul
dom/bindings/Bindings.conf
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -3898,17 +3898,17 @@ nsXMLHttpRequest::GetInterface(const nsI
     *aResult = static_cast<nsITimerCallback*>(EnsureXPCOMifier().get());
     return NS_OK;
   }
 
   return QueryInterface(aIID, aResult);
 }
 
 JS::Value
-nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSIID* aIID, ErrorResult& aRv)
+nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aRv)
 {
   const nsID* iid = aIID->GetID();
   nsCOMPtr<nsISupports> result;
   JS::Value v = JSVAL_NULL;
   aRv = GetInterface(*iid, getter_AddRefs(result));
   NS_ENSURE_FALSE(aRv.Failed(), JSVAL_NULL);
 
   JSObject* global = JS_GetGlobalForObject(aCx, GetWrapper());
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -443,17 +443,17 @@ public:
   bool MozSystem();
 
   nsIChannel* GetChannel()
   {
     return mChannel;
   }
 
   // We need a GetInterface callable from JS for chrome JS
-  JS::Value GetInterface(JSContext* aCx, nsIJSIID* aIID, ErrorResult& aRv);
+  JS::Value GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aRv);
 
   // This creates a trusted readystatechange event, which is not cancelable and
   // doesn't bubble.
   static nsresult CreateReadystatechangeEvent(nsIDOMEvent** aDOMEvent);
   // For backwards compatibility aPosition should contain the headers for upload
   // and aTotalSize is UINT64_MAX when unknown. Both those values are
   // used by nsXMLHttpProgressEvent. Normal progress event should not use
   // headers in aLoaded and aTotal is 0 when unknown.
--- a/content/base/test/chrome/Makefile.in
+++ b/content/base/test/chrome/Makefile.in
@@ -42,11 +42,12 @@ MOCHITEST_CHROME_FILES = \
     test_bug650784.html \
     test_bug750096.html \
     test_bug752226-3.xul \
     test_bug752226-4.xul \
     test_bug682305.html \
     test_bug780199.xul \
     test_bug780529.xul \
     test_csp_bug768029.html \
+    test_bug800386.xul \
     $(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/content/base/test/chrome/test_bug800386.xul
@@ -0,0 +1,66 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=800386
+-->
+<window title="Mozilla Bug 800386"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=800386"
+     target="_blank">Mozilla Bug 800386</a>
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+  /** Test for Bug 800386 **/
+  Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+  SimpleTest.waitForExplicitFinish();
+
+  var triedForwarding = false;
+  var forwardFailed = false;
+
+  var xhr = new XMLHttpRequest;
+  var eventSink = xhr.getInterface(Components.interfaces.nsIProgressEventSink);
+  isnot(eventSink, null, "Should get event sink directly!");
+
+  // Now jump through some hoops to get us a getInterface call from C++
+
+  var requestor = {
+    getInterface: function(aIID) {
+      if (aIID.equals(Components.interfaces.nsIProgressEventSink)) {
+        triedForwarding = true;
+        try {
+          return xhr.getInterface(aIID);
+        } catch (e) {
+          forwardFailed = true;
+        }
+      }
+      throw Components.results.NS_ERROR_NO_INTERFACE;
+    },
+
+    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
+                                           Components.interfaces.nsIInterfaceRequestor])
+  };
+
+  // HTTP URI so that we get progress callbacks
+  xhr.open("GET", "http://mochi.test:8888/", false);
+  xhr.channel.notificationCallbacks = requestor;
+  xhr.onreadystatechange = function() {
+    if (xhr.readyState == 4) {
+      ok(triedForwarding,
+         "Should have had an attempt to treat us as a progress event sink");
+      ok(!forwardFailed,
+         "Should have been able to forward getInterface on to the XHR");
+      SimpleTest.finish();
+    }
+  }
+  xhr.send();
+  ]]>
+  </script>
+</window>
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -226,17 +226,17 @@ DOMInterfaces = {
 {
     'headerFile': 'HTMLPropertiesCollection.h',
     'prefable': True,
     'resultNotAddRefed': [ 'item', 'namedItem', 'names' ]
 }],
 
 'IID': [
 {
-    'nativeType': 'nsIJSIID',
+    'nativeType': 'nsIJSID',
     'headerFile': 'xpcjsid.h',
 },
 {
     'workers': True,
 }],
 
 'InputStream': [
 {