Closed Bug 1163898 Opened 9 years ago Closed 9 years ago

Expose mozAnon constructor js binding to system scopes

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla41
Tracking Status
firefox41 --- fixed

People

(Reporter: Mardak, Assigned: bzbarsky)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Looks like MozXMLHttpRequestParameters to set {mozAnon: true} is only usable from a window context.

http://mxr.mozilla.org/mozilla-central/source/dom/webidl/XMLHttpRequest.webidl#35

There isn't a good way to set mozAnon from a javascript module because there's no constructor and the mozAnon attribute is readonly.

http://mxr.mozilla.org/mozilla-central/source/dom/base/nsIXMLHttpRequest.idl#322
Cu.importGlobalProperties("XMLHttpRequest") should work, I would think, and then you can just use the constructor.

I wonder whether we should just expose that constructor to system scopes unconditionally...
Flags: needinfo?(bobbyholley)
Er, I meant Cu.importGlobalProperties(["XMLHttpRequest"])
Just making sure if I'm trying this correctly:

Cu.importGlobalProperties(["XMLHttpRequest"]);

let x = new XMLHttpRequest({mozAnon: true, mozSystem: false});
dump([x.mozAnon, x.mozSystem]); // "false,true"

let x = new XMLHttpRequest({mozAnon: true});
dump([x.mozAnon, x.mozSystem]); // "false,true"

let x = new XMLHttpRequest();
dump([x.mozAnon, x.mozSystem]); // "false,true"
Oh.  That's dumb.  The issue is that nsXMLHttpRequest::InitParameters tries to do stuff with windows.  Fix coming up.
Assignee: nobody → bzbarsky
Oh, and mozSystem will continue to test true, since the XHR has a system principal, of course.
Comment on attachment 8604701 [details] [diff] [review]
part 1.  Give DOMEventTargetHelper a sane accessor for getting its nsIGlobalObject

Shouldn't nsWindowRoot::GetOwnerGlobal() return the current inner window.

nsIGlobalObject* GetParentObject() const {
{ goes to the next line.
Attachment #8604701 - Flags: review?(bugs) → review+
> Shouldn't nsWindowRoot::GetOwnerGlobal() return the current inner window.

Yes!  Good catch.

> { goes to the next line.

I followed the existing style of GetParentObject.  I guess I can change both.
Attachment #8604702 - Flags: review?(bugs) → review+
Flags: needinfo?(bobbyholley)
This seems to have caused mochitest-1 failure:

https://treeherder.mozilla.org/logviewer.html#?job_id=9790367&repo=mozilla-inbound

13:55:32 INFO - 1011 INFO TEST-START | dom/base/test/test_bug927196.html
13:55:32 INFO - 1012 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon
13:55:32 INFO - 1013 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should not be mozSystem
13:55:32 INFO - 1014 INFO TEST-UNEXPECTED-FAIL | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon - got true, expected false
13:55:32 INFO - 1015 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should not be mozSystem
13:55:32 INFO - 1016 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon
13:55:32 INFO - 1017 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon
13:55:32 INFO - 1018 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should not be mozSystem
13:55:32 INFO - 1019 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon
13:55:32 INFO - 1020 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozSystem
13:55:32 INFO - 1021 INFO TEST-PASS | dom/base/test/test_bug927196.html | XMLHttpRequest should be mozAnon 

http://mxr.mozilla.org/mozilla-central/source/dom/base/test/test_bug927196.html?force=1#47

46 req = new XMLHttpRequest({mozAnon: true, mozSystem: true});
47 is(req.mozAnon, false, "XMLHttpRequest should be mozAnon");

Not sure why "should be mozAnon" is checking false..
> Not sure why "should be mozAnon" is checking false..

Because the existing code was buggy and the test was written around the bug without even noticing it.  The patches here fix that bug.  Anyway, test fix pushed.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: