Oh, never mind. I got it now:

function Foo() {
    this.wrappedJSObject = this;
    ...
}

Foo.prototype._findWindow = function() {
    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
        .getService(Components.interfaces.nsIWindowMediator);
    var e = wm.getEnumerator("navigator:browser");
    while (e.hasMoreElements()) {
        var w = e.getNext();
        var tabBrowsers = w.document.getElementById("content");
        var browsers = tabBrowsers.browsers;
        for (var i = 0; i < browsers.length; i++) {
            var browser = browsers[i];
            var window = browser.docShell.DOMWindow;
            var foo = window.foo;
            if (foo.wrappedJSObject == this) {
                return window;
            }
        }
    }
    return null;
};

Thanks anyhow.

David


David Huynh wrote:
I have a follow-up question. So, I'm now able to let Web pages' script access my own custom object, window.foo. Now I need window.foo to know which "window" it is attached to (as there can be many windows and many tabs). Getting the top-most window would not work, as a Web page's script does not always access window.foo while the page's window is top-most. I'm trying to dig into the Javascript runtime stuff and somehow get the outer context of the call to createInstance() but haven't found anything.

Any suggestion?

Many thanks!

David

Mook wrote:

David Huynh wrote:

Hi all,

I'm trying to write a Firefox extension that adds an extra property to the "window" object that Web pages' scripts have access to. As you know, currently, scripts in Web pages can access such objects as

    window
    window.document
    window.navigator
    window.netscape
    ...

I'd like to add my own property onto this window object that all Web pages' scripts can access

    window.foo

I will provide the implementation of foo as necessary. I'm hoping that someone here can tell me how to do this. I've tried a number of methods (such as overloading the <browser> XBL binding), but I don't see how to do this cleanly from within an extension.

The major issue is probably security. And I can't require every Web page that wants to use this object to be signed so that it can request privileges.

Many thanks in advance!

David




(I'm ignoring the .jseng copy of this exact same message)

One options is to do what window.sidebar does it at http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/browser/components/sidebar/src/nsSidebar.js&rev=1.11#228 I think. I'm hoping whatever window.sidebar does is secure - so you probably need to look at its nsIClassInfo impl too :)

_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to