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

window.external in Firefox

34 views
Skip to first unread message

Brian King

unread,
Oct 9, 2007, 11:51:35 AM10/9/07
to dev-ext...@lists.mozilla.org
Hi,

I always thought that window.external was IE only, but it seems Firefox
has support for it. For example,
window.external.AddSearchProvider(engineURL) can be called from a web
page[1].

Question: Is it possible, from a chrome extension, to add another
function to the window.external object that can be called from random
web pages? It is not clear from the code[2] how AddSearchProvider does it.

[1]
http://developer.mozilla.org/en/docs/Adding_search_engines_from_web_pages
[2]
http://lxr.mozilla.org/mozilla/source/browser/components/sidebar/src/nsSidebar.js#193

My goal is for onclick handlers on link elements in web pages to call
custom functions in my chrome extension.

--
Brian King
www.mozdev.org - free project hosting for the Mozilla community

Nickolay Ponomarev

unread,
Oct 9, 2007, 11:55:41 AM10/9/07
to Brian King, dev-ext...@lists.mozilla.org
On 10/9/07, Brian King <br...@mozdev.org> wrote:
> Hi,
>
> I always thought that window.external was IE only, but it seems Firefox
> has support for it. For example,
> window.external.AddSearchProvider(engineURL) can be called from a web
> page[1].
>
> Question: Is it possible, from a chrome extension, to add another
> function to the window.external object that can be called from random
> web pages? It is not clear from the code[2] how AddSearchProvider does it.
>
> [1]
> http://developer.mozilla.org/en/docs/Adding_search_engines_from_web_pages
> [2]
> http://lxr.mozilla.org/mozilla/source/browser/components/sidebar/src/nsSidebar.js#193
>
http://lxr.mozilla.org/mozilla/source/browser/components/sidebar/src/nsSidebar.js#309

309 catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
310 "external",
311 SIDEBAR_CONTRACTID,

So no, "external" is reserved after nsSidebar. You can register your
own implementation, overwriting the nsSidebar one and forward calls to
already implemented methods appropriately.

> My goal is for onclick handlers on link elements in web pages to call
> custom functions in my chrome extension.
>

You could instead use the DOM events:
http://developer.mozilla.org/en/docs/Code_snippets:Interaction_between_privileged_and_non-privileged_pages

Nickolay

Neil

unread,
Oct 9, 2007, 12:20:19 PM10/9/07
to
Nickolay Ponomarev wrote:

>On 10/9/07, Brian King <br...@mozdev.org> wrote:
>
>
>>Question: Is it possible, from a chrome extension, to add another function to the window.external object that can be called from random web pages?
>>

>http://lxr.mozilla.org/mozilla/source/browser/components/sidebar/src/nsSidebar.js#309
>
>309 catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
>310 "external",
>311 SIDEBAR_CONTRACTID,
>
>So no, "external" is reserved after nsSidebar. You can register your own implementation, overwriting the nsSidebar one and forward calls to already implemented methods appropriately.
>
>

Better still, just register your own global property.

--
Warning: May contain traces of nuts.

Brian King

unread,
Oct 9, 2007, 2:19:21 PM10/9/07
to
Nickolay Ponomarev wrote:
> http://lxr.mozilla.org/mozilla/source/browser/components/sidebar/src/nsSidebar.js#309
>
> 309 catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
> 310 "external",
> 311 SIDEBAR_CONTRACTID,
>
> So no, "external" is reserved after nsSidebar. You can register your
> own implementation, overwriting the nsSidebar one and forward calls to
> already implemented methods appropriately.

Sounds too risky stomping on the sidebar code.

>> My goal is for onclick handlers on link elements in web pages to call
>> custom functions in my chrome extension.
>>
> You could instead use the DOM events:
> http://developer.mozilla.org/en/docs/Code_snippets:Interaction_between_privileged_and_non-privileged_pages

Yes. I already have something like this going where I register a click
handler on the sidebar (where the pages will be loaded) and read
attributes based on the event target. Seems like custom DOM events are a
more reliable option though.

Brian King

unread,
Oct 9, 2007, 2:21:26 PM10/9/07
to
Neil wrote:
>> 309 catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
>> 310 "external",
>> 311 SIDEBAR_CONTRACTID,
>>
>> So no, "external" is reserved after nsSidebar. You can register your
>> own implementation, overwriting the nsSidebar one and forward calls to
>> already implemented methods appropriately.
>>
>>
> Better still, just register your own global property.

Well, the reason I wanted to use 'external' is because the code could
work in IE and Firefox (there is an IE version of the extension also).

Michael Vincent van Rantwijk, MultiZilla

unread,
Oct 11, 2007, 7:56:17 AM10/11/07
to

Please note that this most likely breaks the (X)HTML validation because
you (can) add unknown; or should I say "invalid attributes".


--
Michael Vincent van Rantwijk
- MultiZilla Project Team Lead
- XUL Boot Camp Staff member (ActiveState Training Partner)
- iPhone Application Developer

Nickolay Ponomarev

unread,
Oct 11, 2007, 8:27:35 AM10/11/07
to mv_van_...@yahoo.com, dev-ext...@lists.mozilla.org
On 10/11/07, Michael Vincent van Rantwijk, MultiZilla

<mv_van_...@yahoo.com> wrote:
> > You could instead use the DOM events:
> > http://developer.mozilla.org/en/docs/Code_snippets:Interaction_between_privileged_and_non-privileged_pages
> >
> > Nickolay
>
> Please note that this most likely breaks the (X)HTML validation because
> you (can) add unknown; or should I say "invalid attributes".
>
You can always add the new attributes in your own namespace. Not that
"XHTML validation" in this context should bother anyone.

Nickolay

Michael Vincent van Rantwijk, MultiZilla

unread,
Oct 11, 2007, 9:32:42 AM10/11/07
to
Nickolay Ponomarev wrote:
> On 10/11/07, Michael Vincent van Rantwijk, MultiZilla
> <mv_van_...@yahoo.com> wrote:
>>> You could instead use the DOM events:
>>> http://developer.mozilla.org/en/docs/Code_snippets:Interaction_between_privileged_and_non-privileged_pages
>>>
>>> Nickolay
>> Please note that this most likely breaks the (X)HTML validation because
>> you (can) add unknown; or should I say "invalid attributes".
>>
> You can always add the new attributes in your own namespace.

Eh, which name space are you referring to here?

> Not that
> "XHTML validation" in this context should bother anyone.

I think it should, simply because you most likely end up making the same
kind of mistakes when you work on several (large) projects where one or
more projects require dynamic (X)HTML insertion (people copy other
peoples code time after time you know).

Nickolay Ponomarev

unread,
Oct 11, 2007, 10:04:58 AM10/11/07
to mv_van_...@yahoo.com, dev-ext...@lists.mozilla.org
On 10/11/07, Michael Vincent van Rantwijk, MultiZilla
<mv_van_...@yahoo.com> wrote:
> > You can always add the new attributes in your own namespace.
>
> Eh, which name space are you referring to here?
>
Any made-up namespace. Attributes can be in any namespace, you know.

> > Not that
> > "XHTML validation" in this context should bother anyone.
>
> I think it should, simply because you most likely end up making the same
> kind of mistakes when you work on several (large) projects where one or
> more projects require dynamic (X)HTML insertion (people copy other
> peoples code time after time you know).
>

Not going to argue because I don't care.

Nickolay

0 new messages