Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Constructor called too late

7 views
Skip to first unread message

Jeferson Hultmann

unread,
Jun 3, 2009, 10:00:29 PM6/3/09
to dev-te...@lists.mozilla.org
Hi all

I need to override document.cookie property. The idea is to implement
(Firefox) the very useful IE8 feature "File > New Session".

CSS:
html, head, script {
-moz-binding: url(binding.xml#cookie) !important;
}

binding.xml snippet:
<binding id="cookie">
<implementation>
<constructor>
<![CDATA[
document.__defineSetter__("cookie", function(v) {});
]]>
</constructor>
</implementation>
</binding>

It works. However, the constructor runs only after <body> starts. All
document.cookie calls inside <head> are missed!

So my question is: how do I make my code run before any <script> is executed?

Thanks!

--
Jeferson

Boris Zbarsky

unread,
Jun 3, 2009, 10:44:50 PM6/3/09
to
Jeferson Hultmann wrote:
> So my question is: how do I make my code run before any <script> is executed?

With XBL1 (what Gecko currently has)? With great pain. You need to run
some of your own script, after the page has started loading but before
any page script runs, and have it touch the <html> node. Note that this
assumes your CSS and XBL are both chrome:// and hence loaded
synchronously; if that's not the case then you just lose.

Also note that if you can run such script it can just call
__defineSetter__ directly so you don't need the XBL hack.

-Boris

Jeferson Hultmann

unread,
Jun 4, 2009, 12:11:58 AM6/4/09
to dev-te...@lists.mozilla.org
On Wed, Jun 3, 2009 at 23:44, Boris Zbarsky <bzba...@mit.edu> wrote:
> With XBL1 (what Gecko currently has)?  With great pain.  You need to run
> some of your own script, after the page has started loading but before any
> page script runs, and have it touch the <html> node.  Note that this assumes
> your CSS and XBL are both chrome:// and hence loaded synchronously; if
> that's not the case then you just lose.


CSS and XBL are both chrome:// (CSS is loaded with "style-sheet-service"...)

If I add a progress listener:

onLocationChange: function(aWebProgress, aRequest, aLocation) {
var dummy = aWebProgress.DOMWindow.document.getElementsByTagName("head")[0];
}

Then XBL is applied exactly how I need!

Unfortunately it looks like iframes are invisible to progress listener. :-|

All I need is an equivalent event for iframes.

maybe a hack with setTimeout?


--
Jeferson

Jeferson Hultmann

unread,
Jun 4, 2009, 11:16:43 PM6/4/09
to dev-te...@lists.mozilla.org
On Thu, Jun 4, 2009 at 01:11, Jeferson Hultmann<hult...@gmail.com> wrote:
> onLocationChange: function(aWebProgress, aRequest, aLocation) {
>  var dummy = aWebProgress.DOMWindow.document.getElementsByTagName("head")[0];
> }
>
> Then XBL is applied exactly how I need!
>
> Unfortunately it looks like iframes are invisible to progress listener. :-|


hmmm...

I could force my XBL to be applied at nsIScriptLoaderObserver.scriptAvailable

But... how can I get a nsIScriptLoader instance from JavaScript? I
couldn't find any example.

Thanks,

--
Jeferson

Boris Zbarsky

unread,
Jun 5, 2009, 12:18:42 AM6/5/09
to
Jeferson Hultmann wrote:
> I could force my XBL to be applied at nsIScriptLoaderObserver.scriptAvailable
>
> But... how can I get a nsIScriptLoader instance from JavaScript? I
> couldn't find any example.

You can't. It's not scriptable.

But again, if you can run js anyway at the right time, why do you need
xbl? Just attach your getter or setter directly....

-Boris

Jeferson Hultmann

unread,
Jun 5, 2009, 1:01:55 AM6/5/09
to dev-te...@lists.mozilla.org

I can't because of xpcnativewrapper (__defineSetter__ is not
defined...). I can fix it (Firefox 3) by setting xpcnativewrappers=no
in chrome.manifest, but it doesn't seem to have effect in Firefox 3.5.

Also there is a security issue when content tries to access
document.cookie defined by my extension.

well, as DOMNodeInserted events don't fire during page load, I don't
know what else I can do to install my document.cookie. Maybe JS
debugger API?


--
Jeferson

Boris Zbarsky

unread,
Jun 5, 2009, 1:29:55 AM6/5/09
to
Jeferson Hultmann wrote:
> I can't because of xpcnativewrapper (__defineSetter__ is not
> defined...). I can fix it (Firefox 3) by setting xpcnativewrappers=no
> in chrome.manifest, but it doesn't seem to have effect in Firefox 3.5.

doing it to the wrappedJSObject doesn't work?

> Also there is a security issue when content tries to access
> document.cookie defined by my extension.

Ah, true. You could inject a <script> into the page.... That's what
Firebug does, iirc.

-Boris

0 new messages