Skip to content

Commit

Permalink
merge master into stabilization to start the 1.7 release cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Wes Kocher committed Apr 3, 2012
2 parents 6ed75d9 + 21181c0 commit df3d9d2
Show file tree
Hide file tree
Showing 98 changed files with 4,330 additions and 633 deletions.
1 change: 1 addition & 0 deletions doc/dev-guide-source/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ We'd like to thank our many Jetpack project contributors! They include:
* Drew Willcoxon
* Piotr Zalewa
* [David Guo](https://github.com/dglol)
* [Nils Maier](https://github.com/nmaier)
4 changes: 3 additions & 1 deletion doc/dev-guide-source/guides/commonjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ modules fall roughly into three categories:
want to use modules from this category.

* building blocks for higher level modules, such as
[base](packages/api-utils/base.html) and
[event/core](packages/api-utils/event/core.html),
[event/target](packages/api-utils/event/target.html),
[base](packages/api-utils/base.html), and
[namespace](packages/api-utils/namespace.html). You're more
likely to use these if you are building your own modules that
implement new APIs, thus extending the SDK itself.
Expand Down
3 changes: 3 additions & 0 deletions doc/dev-guide-source/guides/firefox-compatibility.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

# Firefox Compatibility #

Expand Down
4 changes: 4 additions & 0 deletions doc/dev-guide-source/package-spec.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

# Package Specification #

A *package* is a directory that, at minimum, contains a JSON file
Expand Down
5 changes: 3 additions & 2 deletions doc/dev-guide-source/tutorials/adding-menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ be aware of:

* our support for third party packages is still fairly immature. One
consequence of this is that it's not always obvious where to find third-party
packages, although some are collected in the
[Jetpack Wiki](https://wiki.mozilla.org/Jetpack/Modules)
packages, although the
[Community Developed Modules](https://github.com/mozilla/addon-sdk/wiki/Community-developed-modules)
page in the SDK's GitHub Wiki lists a number of packages.

* because third party modules typically use low-level APIs, they may be broken
by new releases of Firefox.
4 changes: 4 additions & 0 deletions doc/dev-guide-source/tutorials/mobile.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<div class="warning">Developing add-ons for Firefox Mobile is still
an experimental feature of the SDK. Although the SDK modules used are
stable, the setup instructions and cfx commands are likely to change.
Expand Down
4 changes: 4 additions & 0 deletions doc/static-files/css/footer.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#footer {
clear: both;
color: #476fbe;
Expand Down
4 changes: 4 additions & 0 deletions doc/static-files/css/sdk-docs.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

html, body {
min-width: 510px; /* 2 x sidebar fullwidth + main-content padding */
height: 100%;
Expand Down
4 changes: 4 additions & 0 deletions examples/library-detector/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

This is a port to the SDK of the
[Library Detector add-on](https://addons.mozilla.org/en-US/firefox/addon/library-detector/).
The original Library Detector is written by
Expand Down
1 change: 1 addition & 0 deletions packages/addon-kit/data/pagemod-css-include-file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div { border: 10px solid black; }
22 changes: 13 additions & 9 deletions packages/addon-kit/docs/context-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ are not current, then your context listener is never called.
This example takes advantage of that fact. The listener can be assured that
`node` will always be an image:

require("context-menu").Item({
var cm = require("context-menu");
cm.Item({
label: "A Mozilla Image",
context: contextMenu.SelectorContext("img"),
context: cm.SelectorContext("img"),
contentScript: 'self.on("context", function (node) {' +
' return /mozilla/.test(node.src);' +
'});'
Expand Down Expand Up @@ -238,9 +239,10 @@ associated with the content script, the content script can call the
JSON-able data. The menu item's `"message"` event listener will be called with
that data.

require("context-menu").Item({
var cm = require("context-menu");
cm.Item({
label: "Edit Image",
context: contextMenu.SelectorContext("img"),
context: cm.SelectorContext("img"),
contentScript: 'self.on("click", function (node, data) {' +
' self.postMessage(node.src);' +
'});',
Expand Down Expand Up @@ -333,9 +335,10 @@ part of the page:

Show an "Edit Image" item when the menu is invoked on an image:

require("context-menu").Item({
var cm = require("context-menu");
cm.Item({
label: "Edit Image",
context: contextMenu.SelectorContext("img"),
context: cm.SelectorContext("img"),
contentScript: 'self.on("click", function (node, data) {' +
' self.postMessage(node.src);' +
'});',
Expand Down Expand Up @@ -364,10 +367,11 @@ mozilla.org or mozilla.com page:

Show an "Edit Page Images" item when the page contains at least one image:

require("context-menu").Item({
var cm = require("context-menu");
cm.Item({
label: "Edit Page Images",
// This ensures the item only appears during the page context.
context: contextMenu.PageContext(),
context: cm.PageContext(),
contentScript: 'self.on("context", function (node) {' +
' var pageHasImgs = !!document.querySelector("img");' +
' return pageHasImgs;' +
Expand Down Expand Up @@ -398,7 +402,7 @@ Google or Wikipedia with the text contained in the anchor:
});
var searchMenu = cm.Menu({
label: "Search With",
context: contextMenu.SelectorContext("a[href]"),
context: cm.SelectorContext("a[href]"),
contentScript: 'self.on("click", function (node, data) {' +
' var searchURL = data + node.textContent;' +
' window.location.href = searchURL;' +
Expand Down
36 changes: 34 additions & 2 deletions packages/addon-kit/docs/page-mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ file in your `data` directory as "myScript.js", you would assign it using
code like:

var data = require("self").data;

var pageMod = require("page-mod");
pageMod.PageMod({
include: "*.org",
Expand All @@ -98,6 +98,28 @@ have problems getting your add-on approved on AMO.</p>
secure, debug and review.</p>
</div>

### Styling web pages ###

Sometimes adding a script to web pages is not enough, you also want to styling
them. `PageMod` provides an easy way to do that through options' `contentStyle`
and `contentStyleFile` properties:

var data = require("self").data;
var pageMod = require("page-mod");

pageMod.PageMod({
include: "*.org",

contentStyleFile: data.url("my-page-mod.css"),
contentStyle: [
"div { padding: 10px; border: 1px solid silver}",
"img { display: none}"
]
})

It's important to note that `PageMod` will add these styles as
[user style sheet](https://developer.mozilla.org/en/CSS/Getting_Started/Cascading_and_inheritance).

## Communicating With Content Scripts ##

When a matching page is loaded the `PageMod` will call the function that the
Expand Down Expand Up @@ -331,6 +353,15 @@ Creates a PageMod.

This property is optional and defaults to "end".

@prop [contentStyleFile] {string,array}
The local file URLs of stylesheet to load. Content style specified by this
option are loaded *before* those specified by the `contentStyle` option.
Optional.
@prop [contentStyle] {string,array}
The texts of stylesheet rules to add. Content styles specified by this
option are loaded *after* those specified by the `contentStyleFile` option.
Optional.

@prop [onAttach] {function}
A function to call when the PageMod attaches content scripts to
a matching page. The function will be called with one argument, a `worker`
Expand All @@ -353,7 +384,8 @@ description of match patterns. Rules can be added to the list by calling its
@method
Stops the page mod from making any more modifications. Once destroyed the page
mod can no longer be used. Note that modifications already made to open pages
will not be undone.
will not be undone, except for any stylesheet added by `contentStyle` or
`contentStyleFile`, that are unregistered immediately.
</api>

<api name="attach">
Expand Down
27 changes: 17 additions & 10 deletions packages/addon-kit/docs/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ The `request` module lets you make simple yet powerful network requests.

<api name="Request">
@class
The `Request` object is used to make `GET` or `POST` network requests. It is
constructed with a URL to which the request is sent. Optionally the user may
specify a collection of headers and content to send alongside the request and
a callback which will be executed once the request completes.
The `Request` object is used to make `GET`, `POST` or `PUT` network requests.
It is constructed with a URL to which the request is sent. Optionally the user
may specify a collection of headers and content to send alongside the request
and a callback which will be executed once the request completes.

Once a `Request` object has been created a `GET` request can be executed by
calling its `get()` method, or a `POST` request by calling its `post()` method.
calling its `get()` method, a `POST` request by calling its `post()` method,
or a `PUT` request by calling its `put()` method.

When the server completes the request, the `Request` object emits a "complete"
event. Registered event listeners are passed a `Response` object.

Each `Request` object is designed to be used once. Once `GET` or `POST` are
called, attempting to call either will throw an error.
Each `Request` object is designed to be used once. Once `GET`, `POST` or `PUT`
are called, attempting to call either will throw an error.

Since the request is not being made by any particular website, requests made
here are not subject to the same-domain restriction that requests made in web
Expand Down Expand Up @@ -79,8 +80,8 @@ set several properties on the resulting `Request`.
encode safely.

For `GET` requests, the query string (`content`) will be appended to the
URL. For `POST` requests, the query string will be sent as the body of the
request.
URL. For `POST` and `PUT` requests, the query string will be sent as the body
of the request.

@prop [contentType] {string}
The type of content to send to the server. This explicitly sets the
Expand Down Expand Up @@ -142,6 +143,12 @@ Make a `POST` request.
@returns {Request}
</api>

<api name="put">
@method
Make a `PUT` request.
@returns {Request}
</api>

<api name="complete">
@event
The `Request` object emits this event when the request has completed and a
Expand All @@ -157,7 +164,7 @@ Listener functions are passed the response to the request as a `Response` object
<api name="Response">
@class
The Response object contains the response to a network request issued using a
`Request` object. It is returned by the `get()` or `post()` method of a
`Request` object. It is returned by the `get()`, `post()` or `put()` method of a
`Request` object.

All members of a `Response` object are read-only.
Expand Down
1 change: 1 addition & 0 deletions packages/addon-kit/docs/simple-prefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define the preferences in your `package.json`, like so:
"preferences": [{
"name": "somePreference",
"title": "Some preference title",
"description": "Some short description for the preference",
"type": "string",
"value": "this is the default string value"
}]
Expand Down
4 changes: 4 additions & 0 deletions packages/addon-kit/docs/widget.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- contributed by Dietrich Ayala [dietrich@mozilla.com] -->
<!-- contributed by Drew Willcoxon [adw@mozilla.com] -->
<!-- edited by Noelle Murata [fiveinchpixie@gmail.com] -->
Expand Down
7 changes: 4 additions & 3 deletions packages/addon-kit/lib/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { EventEmitterTrait: EventEmitter } = require("api-utils/events");
const observerServ = require("api-utils/observer-service");
const jpSelf = require("self");
const winUtils = require("api-utils/window-utils");
const { getInnerId } = require("api-utils/window/utils");
const { Trait } = require("api-utils/light-traits");
const { Cortex } = require("api-utils/cortex");
const timer = require("timer");
Expand Down Expand Up @@ -682,7 +683,7 @@ WorkerRegistry.prototype = {

// Registers a content window, creating a worker for it if it needs one.
registerContentWin: function WR_registerContentWin(win) {
let innerWinID = winUtils.getInnerId(win);
let innerWinID = getInnerId(win);
if ((innerWinID in this.winWorkers) ||
(innerWinID in this.winsWithoutWorkers))
return;
Expand Down Expand Up @@ -725,7 +726,7 @@ WorkerRegistry.prototype = {

// Returns the worker for the item-window pair or null if none exists.
find: function WR_find(contentWin) {
let innerWinID = winUtils.getInnerId(contentWin);
let innerWinID = getInnerId(contentWin);
return (innerWinID in this.winWorkers) ?
this.winWorkers[innerWinID].worker :
null;
Expand Down Expand Up @@ -870,7 +871,7 @@ let browserManager = {
// Stores the given content window with the manager and registers it with each
// top-level item's worker registry.
_registerContentWin: function BM__registerContentWin(win) {
let innerID = winUtils.getInnerId(win);
let innerID = getInnerId(win);

// It's an error to call this method for the same window more than once, but
// we allow it in one case: when onTrack races _onDocGlobalCreated. (See
Expand Down
31 changes: 26 additions & 5 deletions packages/addon-kit/lib/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

const { Cc, Ci } = require("chrome");
const { getPreferedLocales, findClosestLocale } = require("api-utils/l10n/locale");
const { getRulesForLocale } = require("api-utils/l10n/plural-rules");

// Get URI for the addon root folder:
const { rootURI } = require("@packaging");

let globalHash = {};
let pluralMappingFunction = getRulesForLocale("en");

exports.get = function get(k) {

Expand Down Expand Up @@ -38,11 +40,26 @@ exports.get = function get(k) {
// // Identifier of a key stored in properties file
// _("downloadNumber", 0);
let n = arguments[1];
let pluralForm = "other";
// TODO: Make this rule specific to each language
if (n <= 1)
pluralForm = "one";
localized = localized[pluralForm];

// First handle simple universal forms that may not be mandatory
// for each language, (i.e. not different than 'other' form,
// but still usefull for better phrasing)
// For example 0 in english is the same form than 'other'
// but we accept 'zero' form if specified in localization file
if (n === 0 && "zero" in localized)
localized = localized["zero"];
else if (n === 1 && "one" in localized)
localized = localized["one"];
else if (n === 2 && "two" in localized)
localized = localized["two"];
else {
let pluralForm = pluralMappingFunction(n);
if (pluralForm in localized)
localized = localized[pluralForm];
else // Fallback in case of error: missing plural form
localized = localized["other"];
}

// Simulate a string with one placeholder:
args = [null, n];
}
Expand Down Expand Up @@ -110,6 +127,10 @@ function getBestLocaleFile() {
if (!bestMatchingLocale)
return null;

// Retrieve the related plural mapping function
let shortLocaleCode = bestMatchingLocale.split("-")[0].toLowerCase();
pluralMappingFunction = getRulesForLocale(shortLocaleCode);

return rootURI + "locale/" + bestMatchingLocale + ".json";
}

Expand Down
Loading

0 comments on commit df3d9d2

Please sign in to comment.