author | Ms2ger <ms2ger@gmail.com> |
Thu, 21 Jun 2012 09:21:55 +0200 | |
changeset 101940 | d341aed9218c2dfd9b8c90a2829f15e1e9245834 |
parent 101939 | 829ce8dbcf65a943c008b464bb52a48787ff3c04 |
child 101941 | f02a28f83eddf3ad5f64e0ef970477c0e6c15f62 |
push id | 1316 |
push user | akeybl@mozilla.com |
push date | Mon, 27 Aug 2012 22:37:00 +0000 |
treeherder | mozilla-beta@db4b09302ee2 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bz |
bugs | 765468 |
milestone | 16.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
|
--- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -548,38 +548,46 @@ nsXMLHttpRequest::Initialize(nsISupports nsresult nsXMLHttpRequest::InitParameters(JSContext* aCx, const jsval* aParams) { XMLHttpRequestParameters params; nsresult rv = params.Init(aCx, aParams); NS_ENSURE_SUCCESS(rv, rv); + InitParameters(params.mozAnon, params.mozSystem); + return NS_OK; +} + +void +nsXMLHttpRequest::InitParameters(bool aAnon, bool aSystem) +{ // Check for permissions. nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetOwner()); - NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK); + if (!window || !window->GetDocShell()) { + return; + } // Chrome is always allowed access, so do the permission check only // for non-chrome pages. if (!nsContentUtils::IsCallerChrome()) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(window->GetExtantDocument()); - NS_ENSURE_TRUE(doc, NS_OK); + if (!doc) { + return; + } nsCOMPtr<nsIURI> uri; doc->NodePrincipal()->GetURI(getter_AddRefs(uri)); - if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.systemXHR.whitelist")) { - return NS_OK; + return; } } - mIsAnon = params.mozAnon; - mIsSystem = params.mozSystem; - - return NS_OK; + mIsAnon = aAnon; + mIsSystem = aSystem; } void nsXMLHttpRequest::ResetResponse() { mResponseXML = nsnull; mResponseBody.Truncate(); mResponseText.Truncate();
--- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -177,34 +177,31 @@ public: { return GetOwner(); } // The WebIDL constructor. static already_AddRefed<nsXMLHttpRequest> Constructor(JSContext* aCx, nsISupports* aGlobal, - const mozilla::dom::Optional<jsval>& aParams, + const mozilla::dom::Nullable<mozilla::dom::MozXMLHttpRequestParameters>& aParams, ErrorResult& aRv) { nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal); nsCOMPtr<nsIScriptObjectPrincipal> principal = do_QueryInterface(aGlobal); if (!window || ! principal) { aRv.Throw(NS_ERROR_FAILURE); return NULL; } nsRefPtr<nsXMLHttpRequest> req = new nsXMLHttpRequest(); req->Construct(principal->GetPrincipal(), window); - if (aParams.WasPassed()) { - nsresult rv = req->InitParameters(aCx, &aParams.Value()); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - return req.forget(); - } + if (!aParams.IsNull()) { + const mozilla::dom::MozXMLHttpRequestParameters& params = aParams.Value(); + req->InitParameters(params.mozAnon, params.mozSystem); } return req.forget(); } void Construct(nsIPrincipal* aPrincipal, nsPIDOMWindow* aOwnerWindow, nsIURI* aBaseURI = NULL) { @@ -212,16 +209,17 @@ public: MOZ_ASSERT_IF(aOwnerWindow, aOwnerWindow->IsInnerWindow()); mPrincipal = aPrincipal; BindToOwner(aOwnerWindow); mBaseURI = aBaseURI; } // Initialize XMLHttpRequestParameter object. nsresult InitParameters(JSContext* aCx, const jsval* aParams); + void InitParameters(bool aAnon, bool aSystem); NS_DECL_ISUPPORTS_INHERITED // nsIXMLHttpRequest NS_DECL_NSIXMLHTTPREQUEST // nsIJSXMLHttpRequest NS_IMETHOD GetOnuploadprogress(nsIDOMEventListener** aOnuploadprogress);
--- a/content/base/test/test_XHR_parameters.html +++ b/content/base/test/test_XHR_parameters.html @@ -16,27 +16,33 @@ </div> <pre id="test"> <script class="testbody" type="application/javascript;version=1.8"> function runTests() { SimpleTest.waitForExplicitFinish(); let validParameters = [ + undefined, + null, {}, {mozSystem: ""}, {mozSystem: 0}, {mozAnon: 1}, {mozAnon: []}, {get mozAnon() { return true; }}, ]; let invalidParameters = [ - undefined, - null, + 0, + 7, + Math.PI, + "string", + true, + false, {get mozSystem() { throw "Bla"; } }, ]; let havePrivileges = false; function testValidParameter(value) { let xhr; try {
--- a/dom/webidl/XMLHttpRequest.webidl +++ b/dom/webidl/XMLHttpRequest.webidl @@ -26,17 +26,37 @@ enum XMLHttpRequestResponseType { "text", // Mozilla-specific stuff "moz-chunked-text", "moz-chunked-arraybuffer", "moz-blob" }; -[Constructor(optional any params)] +/** + * Parameters for instantiating an XMLHttpRequest. They are passed as an + * optional argument to the constructor: + * + * new XMLHttpRequest({anon: true, system: true}); + */ +dictionary MozXMLHttpRequestParameters +{ + /** + * If true, the request will be sent without cookie and authentication + * headers. + */ + boolean mozAnon = false; + + /** + * If true, the same origin policy will not be enforced on the request. + */ + boolean mozSystem = false; +}; + +[Constructor(optional MozXMLHttpRequestParameters? params = null)] interface XMLHttpRequest : XMLHttpRequestEventTarget { // event handler [TreatNonCallableAsNull] attribute Function? onreadystatechange; // states const unsigned short UNSENT = 0; const unsigned short OPENED = 1; const unsigned short HEADERS_RECEIVED = 2;
--- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -1461,17 +1461,17 @@ XMLHttpRequest::_finalize(JSFreeOp* aFop ReleaseProxy(XHRIsGoingAway); XMLHttpRequestEventTarget::_finalize(aFop); } // static XMLHttpRequest* XMLHttpRequest::Constructor(JSContext* aCx, JSObject* aGlobal, - const Optional<jsval>& aParams, + const Nullable<MozXMLHttpRequestParametersWorkers>& aParams, ErrorResult& aRv) { WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); MOZ_ASSERT(workerPrivate); nsRefPtr<XMLHttpRequest> xhr = new XMLHttpRequest(aCx, workerPrivate); if (!Wrap(aCx, aGlobal, xhr)) {
--- a/dom/workers/XMLHttpRequest.h +++ b/dom/workers/XMLHttpRequest.h @@ -67,17 +67,18 @@ public: virtual void _trace(JSTracer* aTrc) MOZ_OVERRIDE; virtual void _finalize(JSFreeOp* aFop) MOZ_OVERRIDE; static XMLHttpRequest* Constructor(JSContext* aCx, JSObject* aGlobal, - const Optional<jsval>& aParams, ErrorResult& aRv); + const Nullable<MozXMLHttpRequestParametersWorkers>& aParams, + ErrorResult& aRv); void Unpin(); bool Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE; #define IMPL_GETTER_AND_SETTER(_type) \ JSObject* \