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

OK to store ext variables in browser and document objects?

11 views
Skip to first unread message

Al Johnson

unread,
May 6, 2013, 6:21:16 PM5/6/13
to dev-ext...@lists.mozilla.org
Hi,

I don't know for sure if it's OK to attach variables of an extension to XUL elements, such as a document object or browser (tab) object.  If so, are my variables protected from other extensions or js code?  If not, what's the best way to manage extension data that is associated with particular documents and tabs?

Thanks,
al

Neil

unread,
May 7, 2013, 6:18:34 AM5/7/13
to
Al Johnson wrote:

>I don't know for sure if it's OK to attach variables of an extension to XUL elements, such as a document object or browser (tab) object. If so, are my variables protected from other extensions or js code? If not, what's the best way to manage extension data that is associated with particular documents and tabs?
>
>
I'm going to call these expandos as that's the technical term for them.

If you set expandos on a browser or tab object, then they are
inaccessible from content, but of course other extensions could still
access them, so you would probably be best off using a JS object named
after your extension and then setting subproperties as necessary.

If you set expandos on a wrapped content object then my understanding is
that there used to be a risk that the wrapper may get unexpectedly
garbage collected, but I'm not sure whether that's still the case.

If you set expandos on an unwrapped content object then content script
will know that they are there and I believe they can access them if they
are simple types, arrays or functions, but the properties of a JS object
will be hidden by default.

--
Warning: May contain traces of nuts.

Al Johnson

unread,
May 7, 2013, 10:40:10 PM5/7/13
to Neil, dev-ext...@lists.mozilla.org
Thanks Neil; that confirms my suspicions.  For wrappers, are you referring to the XPCOM wrapped objects? 

________________________________
From: Neil <ne...@parkwaycc.co.uk>
To: dev-ext...@lists.mozilla.org
Sent: Tuesday, May 7, 2013 4:18 AM
Subject: Re: OK to store ext variables in browser and document objects?

Al Johnson wrote:

_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

Neil

unread,
May 8, 2013, 11:26:19 AM5/8/13
to
Al Johnson wrote:

>Thanks Neil; that confirms my suspicions. For wrappers, are you referring to the XPCOM wrapped objects?
>
No, I'm talking about Xray wrappers, still documented under their old
name: https://developer.mozilla.org/en/docs/XPCNativeWrapper

In general, you can't set expandos on other XPCOM wrapped objects
(nsIBoxObject is the only exception that I can think of offhand, but
again you might run into garbage collection issues).
0 new messages