Bug 756277 - XMLHttpRequest started from Cc['@mozilla.org/xmlextras/xmlhttprequest;1'] ends up bound to some random window, r=bz

--HG--
extra : rebase_source : 480dbf41846fee3362697cb0bf537281f35845e0
This commit is contained in:
Olli Pettay 2012-06-08 23:45:13 +03:00
parent cae964f9a0
commit 4fb227aead
5 changed files with 13 additions and 38 deletions

View File

@ -494,41 +494,16 @@ nsXMLHttpRequest::RootResultArrayBuffer()
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.
*/

View File

@ -43,11 +43,6 @@ nsresult TestNativeXMLHttpRequest()
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);

View File

@ -1685,7 +1685,6 @@ static const nsContractIDMapData kConstructorMap[] =
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,
@ -1724,6 +1723,13 @@ NS_DOMStorageEventCtor(nsISupports** aInstancePtrResult)
return CallQueryInterface(e, aInstancePtrResult);
}
nsresult
NS_XMLHttpRequestCtor(nsISupports** aInstancePtrResult)
{
nsXMLHttpRequest* xhr = new nsXMLHttpRequest();
return CallQueryInterface(xhr, aInstancePtrResult);
}
struct nsConstructorFuncMapData
{
PRInt32 mDOMClassInfoID;
@ -1755,6 +1761,7 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
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;

View File

@ -771,8 +771,7 @@ SpecialPowersAPI.prototype = {
},
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) {

View File

@ -96,7 +96,6 @@ function starttest(){
// 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);