Skip to content

Commit

Permalink
Bug 614339 - move documents for SDK developers to Internals section, …
Browse files Browse the repository at this point in the history
…Bug 614340 - move documents for experimental features/processes to Experimental section
  • Loading branch information
Will Bamberg authored and toolness committed Nov 24, 2010
1 parent fcad865 commit 28013e9
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 166 deletions.
50 changes: 30 additions & 20 deletions static-files/index.html
Expand Up @@ -19,39 +19,49 @@
<div id="left-column">
<h1>Add-on SDK Docs</h1>
<h2 id="dev-guide-header">Developer Guide <a id="hide-dev-guide-toc">hide</a></h2>

<div id="dev-guide-toc">
<div class="section">Tutorial</div>

<div class="section" id="tutorial-header">Tutorial</div>
<ol id="tutorials">
<li id="getting-started">Getting Started</li>
<li id="packaging">Packaging</li>
<li id="programs">Programs</li>
<li id="events">Working with Events</li>
<li id="web-content">Working with Content Scripts</li>
</ol>
<div class="section">How-to</div>
<ol id="tutorials">
<li id="xul-extensions">Using the SDK with XUL extensions</li>
</ol>
<div class="section">Philosophy</div>
<ol id="appendices">
<li id="best-practices">Low-Level Module Best Practices</li>
</ol>
<div class="section">Reference</div>
<ol id="appendices">
<li id="globals">Globals</li>
<li id="chrome">Chrome Authority / Manifest Generation</li>
<li id="xpi">XPI Generation</li>
<li id="cfx-tool">cfx Tool</li>
<li id="package-spec">Package Specification</li>
<li id="glossary">Glossary</li>
<li id="troubleshooting">Troubleshooting</li>
</ol>
<div class="section">Appendices</div>

<div class="section" id="experimental-header">Experimental</div>
<ol id="experimental">
<li id="xul-extensions">Using the SDK with XUL extensions</li>
</ol>

<div class="section" id="internals-header">Internals</div>
<ol id="internals">
<li id="best-practices">Low-Level Module Best Practices</li>
<li id="chrome">Chrome Authority / Manifest Generation</li>
<li id="xpi">XPI Generation</li>
<li id="internal-globals">Internal Globals</li>
</ol>

<div class="section" id="reference-header">Reference</div>
<ol id="reference">
<li id="globals">Globals</li>
<li id="cfx-tool">cfx Tool</li>
<li id="package-spec">Package Specification</li>
<li id="glossary">Glossary</li>
<li id="program-id">Program ID</li>
<li id="troubleshooting">Troubleshooting</li>
</ol>

<div class="section" id="appendices-header">Appendices</div>
<ol id="appendices">
<li><a href="https://wiki.mozilla.org/Labs/Jetpack/Release_Notes">Release Notes</a></li>
<li id="credits">Credits</li>
</ol>

</div>

<h2 id="package-reference">Package Reference</h2>
<div id="more-packages">More...</div>
</div>
Expand Down
99 changes: 8 additions & 91 deletions static-files/md/dev-guide/globals.md
@@ -1,3 +1,6 @@

## JavaScript Globals ##

By default, all code is executed as [JavaScript 1.8.1] and has access
to all the globals defined by it, such as `Math`, `Array`, and `JSON`. Each
module has its own set of these objects; this means that if, for
Expand All @@ -9,25 +12,21 @@ For an introduction to CommonJS modules, see the
[Packaging](#guide/packaging) tutorial.
</span>

## CommonJS Globals ##

Code also has access to the `require` and `exports` globals
as specified by version 1.0 of the [CommonJS Module Specification].

## HTML5 Globals ##

At the time of this writing, code does *not* have access to
any globals defined by the [HTML5] specification, such as `window`,
`document`, or `localStorage`.

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

I wonder if it'd be useful to point readers to the page-worker module in an aside here, since they may want to know how they can get access to these HTML5 globals from an addon.

To access the infamous and powerful `Components` object, see the
[Chrome Authority](#guide/chrome) documentation.

## Unprivileged Globals ##
## SDK Globals ##

These globals are available regardless of the security context of the code.

<code>**\_\_url\_\_**</code>

The `__url__` global is a string identifying the URL from which the code has
been retrieved. If the code has no identifiable URL, this value may be `null`.

<code>**console**</code>

`console` is an object with the following methods:
Expand Down Expand Up @@ -64,88 +63,6 @@ about the exception's stack traceback if one is available.

Inserts a stack trace into the console at the point this function is called.

<span class="aside">
For more information on packaging, see the [Package Specification] appendix.
</span>

<code>**packaging**</code>

The `packaging` global contains methods and metadata related to
the packages available in the current environment.

<code>packaging.**getURLForData**(*path*)</code>

Given a unix-style path relative to the calling package's `data`
directory, returns an absolute URL to the file or directory.

By "calling package", we mean the package in which the caller's source
code resides.

Thus, for example, if a package contains a resource at
`data/mydata.dat` and a module at `lib/foo.js`, the module at
`lib/foo.js` may make the following call to retrieve an absolute url
to `data/mydata.dat`:

var mydata = packaging.getURLForData("/mydata.dat");

If the calling package has no `data` directory, an exception is
thrown.

<code>**memory**</code>

`memory` is an object that exposes functionality to track
objects of interest and help diagnose and prevent memory leaks.

<code>memory.**track**(*object*, [*bin*])</code>

Marks *object* for being tracked, and categorizes it with the given
bin name. If *bin* isn't specified, the memory tracker attempts to
infer a bin name by first checking the object's
`constructor.name`; if that fails or results in the generic
`Object`, the stack is inspected and the name of the current
function being executed&mdash;which is assumed to be a constructor
function&mdash;is used. If that fails, then the object is placed in a
bin named `generic`.

<code>memory.**getObjects**([*bin*])</code>

Returns an `Array` containing information about tracked objects
that have been categorized with the given bin name. If *bin* isn't
provided, information about all live tracked objects are returned.

Each element of the array is an object with the following keys:

<table>
<tr>
<td><code>weakref</code></td>
<td>A weak reference to the object being tracked. Call
<code>get()</code> on this object to retrieve its strong reference; if
a strong reference to the object no longer exists, <code>get()</code>
will return <code>null</code>.</td>
</tr>
<tr>
<td><code>created</code></td>
<td>A <code>Date</code> representing the date and time that
<code>memory.track()</code> was called on the object being
tracked.</td>
</tr>
<tr>
<td><code>filename</code></td>
<td>The name of the file that called <code>memory.track()</code> on
the object being tracked.</td>
</tr>
<tr>
<td><code>lineNo</code></td>
<td>The line number of the file that called
<code>memory.track()</code> on the object being tracked.</td>
</tr>
</table>

<code>memory.**getBins**()</code>

Returns an `Array` containing the names of all bins that aren't
currently empty.

[Components object]: https://developer.mozilla.org/en/Components_object
[Security Roadmap]: #guide/security-roadmap

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

We should actually remove the link to the Security Roadmap from this document and any others, since it no longer exists.

[HTML5]: http://dev.w3.org/html5/spec/Overview.html
Expand Down
97 changes: 97 additions & 0 deletions static-files/md/dev-guide/internal-globals.md
@@ -0,0 +1,97 @@

Globals in this section are subject to change in the future and/or are likely
to be of interest to SDK module developers, rather than add-on developers.

## Components ##

To access the infamous and powerful `Components` object, see the
[Chrome Authority](#guide/chrome) documentation.

## \_\_url\_\_ ##

The `__url__` global is a string identifying the URL from which the code has
been retrieved. If the code has no identifiable URL, this value may be `null`.

## packaging ##

<span class="aside">
For more information on packaging, see the [Package Specification] appendix.
</span>

The `packaging` global contains methods and metadata related to
the packages available in the current environment.

<code>packaging.**getURLForData**(*path*)</code>

Given a unix-style path relative to the calling package's `data`
directory, returns an absolute URL to the file or directory.

By "calling package", we mean the package in which the caller's source
code resides.

Thus, for example, if a package contains a resource at
`data/mydata.dat` and a module at `lib/foo.js`, the module at
`lib/foo.js` may make the following call to retrieve an absolute url
to `data/mydata.dat`:

var mydata = packaging.getURLForData("/mydata.dat");

If the calling package has no `data` directory, an exception is
thrown.

## memory ##

`memory` is an object that exposes functionality to track
objects of interest and help diagnose and prevent memory leaks.

<code>memory.**track**(*object*, [*bin*])</code>

Marks *object* for being tracked, and categorizes it with the given
bin name. If *bin* isn't specified, the memory tracker attempts to
infer a bin name by first checking the object's
`constructor.name`; if that fails or results in the generic
`Object`, the stack is inspected and the name of the current
function being executed&mdash;which is assumed to be a constructor
function&mdash;is used. If that fails, then the object is placed in a
bin named `generic`.

<code>memory.**getObjects**([*bin*])</code>

Returns an `Array` containing information about tracked objects
that have been categorized with the given bin name. If *bin* isn't
provided, information about all live tracked objects are returned.

Each element of the array is an object with the following keys:

<table>
<tr>
<td><code>weakref</code></td>
<td>A weak reference to the object being tracked. Call
<code>get()</code> on this object to retrieve its strong reference; if
a strong reference to the object no longer exists, <code>get()</code>
will return <code>null</code>.</td>
</tr>
<tr>
<td><code>created</code></td>
<td>A <code>Date</code> representing the date and time that
<code>memory.track()</code> was called on the object being
tracked.</td>
</tr>
<tr>
<td><code>filename</code></td>
<td>The name of the file that called <code>memory.track()</code> on
the object being tracked.</td>
</tr>
<tr>
<td><code>lineNo</code></td>
<td>The line number of the file that called
<code>memory.track()</code> on the object being tracked.</td>
</tr>
</table>

<code>memory.**getBins**()</code>

Returns an `Array` containing the names of all bins that aren't
currently empty.

[Package Specification]: #guide/package-spec
39 changes: 39 additions & 0 deletions static-files/md/dev-guide/program-id.md
@@ -0,0 +1,39 @@

The Program ID is a unique identifier for your add-on and is used for a variety
of purposes. For example: [addons.mozilla.org](http://addons.mozilla.org) uses
it to distinguish between new add-ons and updates to existing add-ons, and the
[`simple-storage`](#module/addon-kit/simple-storage) module uses it to figure
out which stored data belongs to which add-on.

<span class="aside">
where is it on Windows?
</span>

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

Is this a TODO disguised as an aside or something? We should probably actually address this, regardless.

The program ID is the public part of a cryptographic key pair. When `cfx`
generates a program ID it actually generates a pair of related keys: one half
(the public key) is embedded in package.json as the program ID while the other
half (the private key) gets stored in a file in ~/.jetpack/keys.

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

Should we put backticks around ~/.jetpack/keys and other occurrences of it in this file to make it monospaced?


When the XPI file is generated it is signed with the private key. Then the
browser, or some other tool, can use the public key to verify that the XPI file
was actually signed by the author.

The private key is very important! If you lose it, you will not be able to
upgrade your add-on: you'll have to create a new add-on ID, and your users will
have to manually uninstall the old one and install the new one. If somebody
else gets a copy of your private key, they will be able to write add-ons that
could impersonate and displace your own.

The add-on's private key needs to be available (in ~/.jetpack/keys/) on any
computer that you use to build that add-on. When you copy the add-on source
code to a new machine, you also need to copy the private key (`cfx xpi` will
remind you of this). The best idea is to just copy the whole ~/.jetpack
directory to a USB flash drive that you can carry with you. It is not stored
in your package source tree, so that you can show your code to somebody else
without also giving them the ability to create forged upgrades for your add-on.

If you start your add-on work by copying somebody else's source code, you'll
need to remove their Program ID from the package.json file before you can build
your own XPIs. Again, `cfx xpi` will remind you of this, and your options, when
you attempt to build an XPI from a package.json that references a private key
that you don't have in ~/.jetpack/keys/.
35 changes: 27 additions & 8 deletions static-files/md/dev-guide/programs.md
Expand Up @@ -116,12 +116,27 @@ This is a global accessible by any module and is very useful for debugging.
### Running It ###

To run your program, navigate to the root of your package directory
in your shell and run:
in your shell and type:

cfx run

That will load an instance of Firefox (or your default application)
with your program installed.
The first time you do this, you'll see a message like this:

No 'id' in package.json: creating a new keypair for you.
package.json modified: please re-run 'cfx run'

Run it again, and it will run an instance of Firefox (or your default
application) with your add-on installed.

The ID that `cfx` generated the first time you executed `cfx run` is called the
**Program ID** and it is important. It is a unique identifier for your add-on
and is used for a variety of purposes. For example: mozilla.addons.org uses it

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

Hmm, I think we mean addons.mozilla.org here. We should also hyperlink to the URL like we do in other places throughout the docs when we mention a domain name.

to distinguish between new add-ons and updates to existing add-ons, and the
[`simple-storage`](#module/addon-kit/simple-storage) module uses it to figure
out which stored data belongs to which add-on.

To learn more about the Program ID refer to the [Program ID](#guide/program-id)
document.

### Trying It Out ###

Expand All @@ -139,11 +154,6 @@ Your program is packaged like any other extension for a Mozilla-based
application, as a XPI file. The Add-on SDK simplifies the packaging
process by generating this file for you.

<span class="aside"> Each program (such as an add-on) gets a
separate cryptographic keypair. Your program is signed by the private
key, and the public key is used as the "ID". See
[XPI Generation](#guide/xpi) for more details.</span>

To package your program as a XPI, navigate to the root of your package
directory in your shell and run `cfx xpi`. The first time you do this,
you'll see a message about generating a keypair and modifying your
Expand All @@ -155,6 +165,15 @@ When you re-run it, you should see a message:
The my-first-package.xpi file can be found in the directory in which you ran
the command.

#### The Program ID ####

The ID that `cfx` generated the first time you executed `cfx run` is called the
**Program ID** and it is important. It is a unique identifier for your add-on
and is used for a variety of purposes. For example: mozilla.addons.org uses it
to distinguish between new add-ons and updates to existing add-ons, and the

This comment has been minimized.

Copy link
@toolness

toolness Nov 24, 2010

Owner

I think we mean addons.mozilla.org here too... but isn't this whole paragraph kind of a deja vu from a few paragraphs earlier, around line 131?

[`simple-storage`](#module/addon-kit/simple-storage) module uses it to figure
out which stored data belongs to which add-on.

### Checking the Package ###

Test that the package installs correctly by adding it to your own Firefox
Expand Down

0 comments on commit 28013e9

Please sign in to comment.