Bug 756277 - XMLHttpRequest started from Cc['@mozilla.org/xmlextras/xmlhttprequest;1'] ends up bound to some random window, r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 08 Jun 2012 23:45:13 +0300
changeset 100974 95d1bb200f4e15f340abb59a883713a2edc55861
parent 100973 227b4a4c3c4676a9bbe316a58d56ab790629854a
child 100975 f50bb5a8ecadcc73ff6297584d847f8b40d22cf4
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs756277
milestone16.0a1
first release with
nightly linux32
95d1bb200f4e / 16.0a1 / 20120609030536 / files
nightly linux64
95d1bb200f4e / 16.0a1 / 20120609030536 / files
nightly mac
95d1bb200f4e / 16.0a1 / 20120609030536 / files
nightly win32
95d1bb200f4e / 16.0a1 / 20120609030536 / files
nightly win64
95d1bb200f4e / 16.0a1 / 20120609030536 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 756277 - XMLHttpRequest started from Cc['@mozilla.org/xmlextras/xmlhttprequest;1'] ends up bound to some random window, r=bz
content/base/src/nsXMLHttpRequest.cpp
content/base/test/TestNativeXMLHttpRequest.cpp
dom/base/nsDOMClassInfo.cpp
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
testing/mochitest/tests/test_SpecialPowersExtension.html
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -489,51 +489,26 @@ nsXMLHttpRequest::RootResultArrayBuffer(
 }
 
 /**
  * This Init method is called from the factory constructor.
  */
 nsresult
 nsXMLHttpRequest::Init()
 {
-  // Set the original mPrincipal, if available.
-  // Get JSContext from stack.
-  nsCOMPtr<nsIJSContextStack> stack =
-    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
-
-  if (!stack) {
-    return NS_OK;
-  }
-
-  JSContext *cx;
-
-  if (NS_FAILED(stack->Peek(&cx)) || !cx) {
-    return NS_OK;
-  }
-
-  nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
+  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
   nsCOMPtr<nsIPrincipal> subjectPrincipal;
   if (secMan) {
-    nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
-    NS_ENSURE_SUCCESS(rv, rv);
+    secMan->GetSystemPrincipal(getter_AddRefs(subjectPrincipal));
   }
   NS_ENSURE_STATE(subjectPrincipal);
-
-  nsIScriptContext* context = GetScriptContextFromJSContext(cx);
-  nsCOMPtr<nsPIDOMWindow> window;
-  if (context) {
-    window = do_QueryInterface(context->GetGlobalObject());
-    if (window) {
-      window = window->GetCurrentInnerWindow();
-    }
-  }
-
-  Construct(subjectPrincipal, window);
+  Construct(subjectPrincipal, nsnull);
   return NS_OK;
 }
+
 /**
  * This Init method should only be called by C++ consumers.
  */
 NS_IMETHODIMP
 nsXMLHttpRequest::Init(nsIPrincipal* aPrincipal,
                        nsIScriptContext* aScriptContext,
                        nsPIDOMWindow* aOwnerWindow,
                        nsIURI* aBaseURI)
--- a/content/base/test/TestNativeXMLHttpRequest.cpp
+++ b/content/base/test/TestNativeXMLHttpRequest.cpp
@@ -38,21 +38,16 @@ nsresult TestNativeXMLHttpRequest()
 
   nsCOMPtr<nsIXMLHttpRequest> xhr =
     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->Open(getString, testURL, false, empty, empty);
-  printf("*** End of expected warning output.\n");
-  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!");
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1680,17 +1680,16 @@ struct nsContractIDMapData
   { eDOMClassInfo_##_class##_id, _contract_id },
 
 static const nsContractIDMapData kConstructorMap[] =
 {
   NS_DEFINE_CONSTRUCTOR_DATA(DOMParser, NS_DOMPARSER_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(FileReader, NS_FILEREADER_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(FormData, NS_FORMDATA_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(XMLSerializer, NS_XMLSERIALIZER_CONTRACTID)
-  NS_DEFINE_CONSTRUCTOR_DATA(XMLHttpRequest, NS_XMLHTTPREQUEST_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(WebSocket, NS_WEBSOCKET_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(XSLTProcessor,
                              "@mozilla.org/document-transformer;1?type=xslt")
   NS_DEFINE_CONSTRUCTOR_DATA(EventSource, NS_EVENTSOURCE_CONTRACTID)
   NS_DEFINE_CONSTRUCTOR_DATA(MutationObserver, NS_DOMMUTATIONOBSERVER_CONTRACTID)
 };
 
@@ -1719,16 +1718,23 @@ NS_DEFINE_EVENT_CTOR(UserProximityEvent)
 
 nsresult
 NS_DOMStorageEventCtor(nsISupports** aInstancePtrResult)
 {
   nsDOMStorageEvent* e = new nsDOMStorageEvent();
   return CallQueryInterface(e, aInstancePtrResult);
 }
 
+nsresult
+NS_XMLHttpRequestCtor(nsISupports** aInstancePtrResult)
+{
+  nsXMLHttpRequest* xhr = new nsXMLHttpRequest();
+  return CallQueryInterface(xhr, aInstancePtrResult);
+}
+
 struct nsConstructorFuncMapData
 {
   PRInt32 mDOMClassInfoID;
   nsDOMConstructorFunc mConstructorFunc;
 };
 
 #define NS_DEFINE_CONSTRUCTOR_FUNC_DATA(_class, _func)                        \
   { eDOMClassInfo_##_class##_id, _func },
@@ -1750,16 +1756,17 @@ static const nsConstructorFuncMapData kC
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozSettingsEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(UIEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MouseEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(DeviceProximityEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(UserProximityEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(DeviceLightEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(StorageEvent)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter)
+  NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XMLHttpRequest, NS_XMLHttpRequestCtor)
 };
 
 nsIXPConnect *nsDOMClassInfo::sXPConnect = nsnull;
 nsIScriptSecurityManager *nsDOMClassInfo::sSecMan = nsnull;
 bool nsDOMClassInfo::sIsInitialized = false;
 bool nsDOMClassInfo::sDisableDocumentAllSupport = false;
 bool nsDOMClassInfo::sDisableGlobalScopePollutionSupport = false;
 
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -766,18 +766,17 @@ SpecialPowersAPI.prototype = {
   getTextZoom: function(window) {
     return this._getMUDV(window).textZoom;
   },
   setTextZoom: function(window, zoom) {
     this._getMUDV(window).textZoom = zoom;
   },
 
   createSystemXHR: function() {
-    return Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
-             .createInstance(Ci.nsIXMLHttpRequest);
+    return this.wrap(Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest));
   },
 
   snapshotWindow: function (win, withCaret) {
     var el = this.window.get().document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
     el.width = win.innerWidth;
     el.height = win.innerHeight;
     var ctx = el.getContext("2d");
     var flags = 0;
--- a/testing/mochitest/tests/test_SpecialPowersExtension.html
+++ b/testing/mochitest/tests/test_SpecialPowersExtension.html
@@ -91,17 +91,16 @@ function starttest(){
   SpecialPowers.gc();
 
   //
   // Test the SpecialPowers wrapper.
   //
 
   // Try some basic stuff with XHR.
   var xhr2 = SpecialPowers.wrap(Components).classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
-  is(xhr2.toString(), SpecialPowers.unwrap(xhr2).toString(), "toString should be transparently delegated");
   is(xhr.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects");
   var testURI = SpecialPowers.wrap(Components).classes['@mozilla.org/network/standard-url;1']
                                               .createInstance(Components.interfaces.nsIURI);
   testURI.spec = "http://www.foobar.org/";
   is(testURI.spec, "http://www.foobar.org/", "Getters/Setters should work correctly");
   is(SpecialPowers.wrap(document).getElementsByTagName('details').length, 0, "Should work with proxy-based DOM bindings.");
 
   // Play with the window object.