Changes

Jump to: navigation, search

WebExtensions/Hacking

3,683 bytes added, 02:47, 7 January 2016
Add some more skeleton code layout docs
# Make sure that $OBJDIR points to the objdir of your current build.
./toolkit/components/extensions/test_coverage.sh $OBJDIR
 
== Code layout ==
 
WebExtension code lives in several different parts of the tree, depending on its purpose:
 
;Generic APIs
: These are the base APIs which don't rely on a browser UI.
: They are defined in files matching <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ toolkit/components/extensions/ext-*.js]</code>
: Each of these APIs also has a schema definition file, located in <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/schemas/ toolkit/components/extensions/schemas/]</code>
;Content Script APIs
: These are a very simple set of APIs which are available to content scripts, and run in the content process.
: They are all defined in a single file, <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ExtensionContent.jsm toolkit/components/extensions/ExtensionContent.jsm]</code>
;Firefox Desktop APIs
: These are APIs which are specific to desktop Firefox, and generally deal directly with the browser UI.
: They are defined in files matching <code>[https://dxr.mozilla.org/mozilla-central/source/browser/components/extensions/ browser/components/extensions/ext-*.js]</code>
: Each of these APIs also has a schema definition file, located in <code>[https://dxr.mozilla.org/mozilla-central/source/browser/components/extensions/schemas/ browser/components/extensions/schemas/]</code>
;Low-level helper modules
: These modules deal with some of the low-level functionality required by WebExtension code, including match pattern handling and web request monitoring.
: They live in <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/modules/addons/ toolkit/modules/addons/]</code>
;Core WebExtension modules
: These deal with the core functionality of WebExtensions, including initializing and tearing down extension instances.
: They live in files matching <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ toolkit/components/extensions/*.jsm]</code>
;XPCOM components
: These are primarily stub interfaces to allow native code to interact with WebExtension management code.
: They are currently all defined in a single file, <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/utils/simpleServices.js toolkit/components/utils/simpleServices.js]</code>
 
=== API modules ===
 
All API modules are loaded into a single module, <code>[https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/Extension.jsm toolkit/components/extensions/Extension.jsm]</code>, and share the same global namespace. All global variables in the <code>Extension.jsm</code> module are automatically available to code in the <code>ext-*.js</code> files. Code in these files may make variables available to other modules by defining them as properties of the <code>global</code> object. For instance, if one module defines <code>global.FooBar = {}</code>, other modules may access it as simply <code>FooBar</code>.
 
Each API module must be explicitly registered, in order to be loaded. It must also register a schema if it exports any APIs to extensions.
 
Generic APIs are registered in <code>Extension.jsm</code> as follows:
 
ExtensionManagement.registerScript("chrome://extensions/content/ext-foobar.js");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/foobar.json");
 
Firefox desktop APIs are registered in [https://dxr.mozilla.org/mozilla-central/source/browser/components/nsBrowserGlue.js nsBrowserGlue.js]:
 
ExtensionManagement.registerScript("chrome://browser/content/ext-bazquux.js");
ExtensionManagement.registerSchema("chrome://browser/content/schemas/bazquux.json");
Accountapprovers, confirm
126
edits

Navigation menu