Closed Bug 517803 Opened 17 years ago Closed 17 years ago

Can't QueryInterface wrapped objects

Categories

(Mozilla Labs :: Jetpack Prototype, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: adw, Unassigned)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch test case (obsolete) — — Splinter Review
This is causing some righteous errors in my menu code. My code doesn't QI, but somewhere down the line a XULElement object is QI'ed, producing an error like this: [ERROR] : [Exception... "Could not convert JavaScript argument arg 0 [nsISupports.QueryInterface]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: chrome://jetpack/content/js/secure-membrane.js :: call :: line 285" data: no] chrome://jetpack/content/js/secure-membrane.js:L285 |wrappee| is QueryInterface, |thisObj| is a XULElement, and the wrappee of |wrappedArgs[0]| is Ci.nsISupports. The XULElement is either a XUL menupopup or menuitem that I create or the browser's content context menu, not sure what exactly since it's difficult to debug. QI is expecting an interface, not a wrapped interface, so this error makes sense, no? In fact when I s/wrappedArgs/[Ci.nsISupports]/, the attached test case works as expected. jetpack.menu won't work without a workaround for this.
Attachment #401757 - Flags: review?(avarma)
Attached patch test case v2 — — Splinter Review
Fixed typo.
Attachment #401757 - Attachment is obsolete: true
Attachment #401758 - Flags: review?(avarma)
Attachment #401757 - Flags: review?(avarma)
Thanks drew, committed your test case: http://hg.mozilla.org/labs/jetpack/rev/8cb289dcc232 Working on fixing this now.
Status: NEW → ASSIGNED
Er, wait a minute--the actual functionality being tested here is a bit funky, because it implies that QueryInterface is being called from untrusted code, which is odd, since ostensibly jetpack.menu (or whatever our chrome "facade" is) should be doing any necessary calls to QI internally. Are you keeping your jetpack.menu code in a public repository? Is there a way I can take a look at it?
I attached a WIP patch to bug 494651. (Sorry for the mess!) The error is triggered by line 422 of menu.js: elt.appendChild(m); m is a XUL menupopup element created from context.ownerDocument, where context is the contentAreaContextMenu in browser.xul. (i.e., the doc is the browser window's XUL doc.) elt is a XUL menu element created from the same doc. The error happens only when I run some test code in Bespin. When I do the same thing in a chrome HTML doc (extensions/context/XXXadw.html is what I've been using to test my code), there's no error. secure-membrane.js fails at line 282: result = wrappee.apply(wrappedArgs[0], realArray); wrappedArgs[0] is a menupopup (so it must be m), wrappee is QueryInterface, and realArray[0] is nsISupports. I had to wrap that line in a try-catch-dump-error to see the error. Is the question, why is m untrusted?
Oh, the failing test code in Bespin: jetpack.menu.context.page.add({ label: "From Bespin", menu: new jetpack.Menu(["Foo", "Bar", "Baz", "Qux"]) });
Thanks! Hmm. So on the Bespin code snippet you included, I open a new blank tab and right-click and get this: Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" location: "file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js Line: 422"] Which isn't the same thing as the error you mentioned... Am I doing something wrong? I'm running FF 3.5.3. Yeah, the question is why is "m" untrusted... if it's a menupopup that originated in chrome code, it should get wrapped with a TrustedWrapper as it leaves chrome space and goes to Jetpack code, but then as it goes from Jetpack code back to chrome space, it should get unwrapped. Definitely funky that it is wrapped in an UntrustedWrapper. I'll take a closer look and get back to you.
Sorry, should have mentioned the appendChild() call causes that error. If you wrap line 282 of secure-membrane.js in a try-catch that dumps the error and rethrows it (comment 4), you'll see the error in comment 0. AFAICT the error originates at that line, propagates back up to appendChild(), which then throws the unhelpful error you mention.
The chain of events that eventually calls appendChild() is started by a popupshowing event listener on the content context menu. Would that matter? The stack would look something like this: obj.onPopupshowing, line 568 set._transforms.applyToXul(aPopup), line 588 Transforms_proto_applyToXul, line 135 this._apply("xul", aXulMenupopup), line 140 Transforms_proto__apply, line 144 tp.impl[transform.name][aType].apply(tp, args), line 149 Transforms_proto_impl_add_xul, line 102 item._makeXulElt(aXulMenupopup.ownerDocument), line 105 Menuitem_proto__makeXulElt, line 384 elt.appendChild(m), line 422
Thanks Drew. I think I've tracked down the problem to the fact that the "this.menu" property of a Menuitem object erroneously has an UntrustedMembrane around it--when it's in fact an instance of Menu and should have no such wrapper. A stack trace at Menuitem._initWithObject() yields this: Menuitem_proto__initWithObject([object FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:390 Menuitem_proto__init([object FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:381 Menuitem([object FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:366 ([object FlexibleWrapper],0,[object Array])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:650 boxMenuitems([object FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:646 Transforms_proto_impl_add_xul([object XULElement],[object FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:124 ([object Object],0,[object Array])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:171 Transforms_proto__apply("xul",[object XULElement])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:169 Transforms_proto_applyToXul([object XULElement])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:162 ([object Object],0,[object Array])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:617 onPopupshowing([object MouseEvent])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:609 Looks like the first place a FlexibleWrapper appears in the stack is at menu.js:124. Hopefully that should help us figure things out... An important side note: because of the fact that the menu code is being called from across a trust boundary, using closures to protect private data actually matters here. For instance, a Jetpack can call Menu._setXulElt(), which may or may not actually be a security risk, but the mere fact that semi-trusted code can access implementation-specific functions increases the potential surface area of attack. Not your fault since I never wrote a "how to write secure chrome code that gives functionality to Jetpack" or anything, and anyways we'll be using COWs eventually to expose such code to Jetpack Features which should protect us from this kind of leakage regardless. [1] https://wiki.mozilla.org/XPConnect_Chrome_Object_Wrappers
(In reply to comment #9) > Transforms_proto_impl_add_xul([object XULElement],[object > FlexibleWrapper])@file:///Users/varmaa/Documents/jetpack/extension/modules/menu.js:124 > Looks like the first place a FlexibleWrapper appears in the stack is at > menu.js:124. Hopefully that should help us figure things out... That makes sense, the second arg is a simple object representing a menuitem that the feature has passed in. In the Bespin test code of comment 5, it's the object passed to add(). The same object is passed to Menuitem._initWithObject(), which iterates over its keys and vals and sets them on |this|, including this.menu.
Closing as invalid, Atul backed out the test in http://hg.mozilla.org/labs/jetpack/rev/234e57a7dfd8
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → INVALID
Attachment #401758 - Flags: review?(avarma)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: