Export XPCOM component to javascript on web page

I would like to write an XPCOM component that will display as a javascript object on a web page. Something like Google Gears is what I'm looking for. That is, after installing the Google Gears Firefox extension, the javascript object "google.gears" is available for any web page that wants to use it. I found a lot of mozilla documentation for developing XPCOM, but didn't show anything to the javascript component running on the web page. Is this possible with XPCOM? Do I need to write a Firefox plugin instead of an extension?

+3
source share
5 answers

I do just that with the new API in Firefox 4 - nsiDOMGlobalPropertyInitializer - which allows you to create a JS object to lazily attach to all windows. This creates a new web console in Firefox 4.

Your component should have the following QI property:

QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]),

Here is an example of a complete implementation in an extension:

https://github.com/daviddahl/domcrypt/blob/master/extension/domcrypt/components/domcrypt.js

SO is basically QI in Ci.nsIDOMGlobalPropertyInitializer, then make sure your manifest has a line, for example:

category JavaScript-global-property crypt @droplettr.com/domcrypt;1

see https://github.com/daviddahl/domcrypt/blob/master/extension/domcrypt/components/domcrypt.manifest

+7
source

This article seems promising:

, (, -) XPCOM, . , - DOM , , XPCOM . , , , Mozilla, , . nsISecurityCheckedComponent , .

: http://weblogs.mozillazine.org/weirdal/archives/017211.html

+1

3.x - "JavaScript global property". ( 4.x, "JavaScript-global-property", .) nsIClassInfo, , . , , script .

+1

, XPCOM. , , , .

. , - .

0

You can do this with web extensions, I read and will no longer support

0
source

Source: https://habr.com/ru/post/1795301/


All Articles