Skip to content

Commit

Permalink
Bug 1013510 - Uplift Add-on SDK to Firefox r=me
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvold committed May 21, 2014
1 parent 76cc54b commit 8fe5289
Show file tree
Hide file tree
Showing 30 changed files with 945 additions and 698 deletions.
1 change: 1 addition & 0 deletions addon-sdk/source/app-extension/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<em:creator>Mozilla Corporation</em:creator>
<em:homepageURL></em:homepageURL>
<em:optionsType></em:optionsType>
<em:optionsURL></em:optionsURL>
<em:updateURL></em:updateURL>
</Description>
</RDF>
48 changes: 34 additions & 14 deletions addon-sdk/source/lib/sdk/addon/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { once } = require('../system/events');
const { exit, env, staticArgs } = require('../system');
const { when: unload } = require('../system/unload');
const { loadReason } = require('../self');
const { rootURI } = require("@loader/options");
const { rootURI, metadata: { preferences } } = require("@loader/options");
const globals = require('../system/globals');
const xulApp = require('../system/xul-app');
const appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
Expand Down Expand Up @@ -129,20 +129,40 @@ function run(options) {
catch(error) {
console.exception(error);
}
// Initialize inline options localization, without preventing addon to be
// run in case of error
try {
require('../l10n/prefs');
}
catch(error) {
console.exception(error);
}

// TODO: When bug 564675 is implemented this will no longer be needed
// Always set the default prefs, because they disappear on restart
if (options.prefsURI) {
// Only set if `prefsURI` specified
setDefaultPrefs(options.prefsURI);
// native-options does stuff directly with preferences key from package.json
if (preferences && preferences.length > 0) {
try {
require('../preferences/native-options').enable(preferences);
}
catch (error) {
console.exception(error);
}
}
else {
// keeping support for addons packaged with older SDK versions,
// when cfx didn't include the 'preferences' key in @loader/options

// Initialize inline options localization, without preventing addon to be
// run in case of error
try {
require('../l10n/prefs').enable();
}
catch(error) {
console.exception(error);
}

// TODO: When bug 564675 is implemented this will no longer be needed
// Always set the default prefs, because they disappear on restart
if (options.prefsURI) {
// Only set if `prefsURI` specified
try {
setDefaultPrefs(options.prefsURI);
}
catch (err) {
// cfx bootstrap always passes prefsURI, even in addons without prefs
}
}
}

// this is where the addon's main.js finally run.
Expand Down
2 changes: 1 addition & 1 deletion addon-sdk/source/lib/sdk/event/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.metadata = {
};

const { on, once, off, setListeners } = require('./core');
const { method, chainable } = require('../lang/functional');
const { method, chainable } = require('../lang/functional/core');
const { Class } = require('../core/heritage');

/**
Expand Down
13 changes: 11 additions & 2 deletions addon-sdk/source/lib/sdk/l10n/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

const { on } = require("../system/events");
const core = require("./core");
const { id: jetpackId} = require('../self');
const { id: jetpackId } = require('../self');

const OPTIONS_DISPLAYED = "addon-options-displayed";

function enable() {
on(OPTIONS_DISPLAYED, onOptionsDisplayed);
}
exports.enable = enable;

function onOptionsDisplayed({ subject: document, data: addonId }) {
if (addonId !== jetpackId)
return;
localizeInlineOptions(document);
}

function localizeInlineOptions(document) {
let query = 'setting[data-jetpack-id="' + jetpackId + '"][pref-name], ' +
'button[data-jetpack-id="' + jetpackId + '"][pref-name]';
let nodes = document.querySelectorAll(query);
Expand Down Expand Up @@ -39,4 +48,4 @@ function onOptionsDisplayed({ subject: document, data: addonId }) {
}
}
}
on(OPTIONS_DISPLAYED, onOptionsDisplayed);
exports.localizeInlineOptions = localizeInlineOptions;
Loading

0 comments on commit 8fe5289

Please sign in to comment.