Bug 1062132 - Uplift Add-on SDK to Firefox r=me
authorErik Vold <evold@mozilla.com>
Wed, 03 Sep 2014 01:08:20 -0700
changeset 203237 4d07ea9dab6e7673cd121317c6c9a0ea47fcde39
parent 203236 b0c0a3322e3668ffd146954108e4fa443cf192cc
child 203238 72d19d0827dec0c850d1b0180aeb8e6816e42f74
push id27424
push userryanvm@gmail.com
push dateWed, 03 Sep 2014 19:35:53 +0000
treeherdermozilla-central@bfef88becbba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1062132
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1062132 - Uplift Add-on SDK to Firefox r=me
addon-sdk/source/lib/sdk/addon/runner.js
addon-sdk/source/python-lib/cuddlefish/prefs.py
addon-sdk/source/test/addons/author-email/main.js
addon-sdk/source/test/addons/author-email/package.json
addon-sdk/source/test/test-window-loader.js
--- a/addon-sdk/source/lib/sdk/addon/runner.js
+++ b/addon-sdk/source/lib/sdk/addon/runner.js
@@ -2,32 +2,37 @@
  * 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/. */
 
 module.metadata = {
   "stability": "experimental"
 };
 
 const { Cc, Ci, Cu } = require('chrome');
-const { isNative } = require('@loader/options');
+const { rootURI, metadata, isNative } = require('@loader/options');
+const { id, loadReason } = require('../self');
 const { descriptor, Sandbox, evaluate, main, resolveURI } = require('toolkit/loader');
 const { once } = require('../system/events');
 const { exit, env, staticArgs } = require('../system');
 const { when: unload } = require('../system/unload');
-const { loadReason } = require('../self');
-const { rootURI, metadata } = require("@loader/options");
 const globals = require('../system/globals');
 const xulApp = require('../system/xul-app');
-const { id } = require('sdk/self');
+const { get } = require('../preferences/service');
 const appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
                         getService(Ci.nsIAppShellService);
 const { preferences } = metadata;
 
 const Startup = Cu.import("resource://gre/modules/sdk/system/Startup.js", {}).exports;
 
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyGetter(this, "BrowserToolboxProcess", function () {
+  return Cu.import("resource:///modules/devtools/ToolboxProcess.jsm", {}).
+         BrowserToolboxProcess;
+});
+
 // Initializes default preferences
 function setDefaultPrefs(prefsURI) {
   const prefs = Cc['@mozilla.org/preferences-service;1'].
                 getService(Ci.nsIPrefService).
                 QueryInterface(Ci.nsIPrefBranch2);
   const branch = prefs.getDefaultBranch('');
   const sandbox = Sandbox({
     name: prefsURI,
@@ -97,17 +102,19 @@ function run(options) {
     }
     catch(error) {
       console.exception(error);
     }
 
     // native-options does stuff directly with preferences key from package.json
     if (preferences && preferences.length > 0) {
       try {
-        require('../preferences/native-options').enable({ preferences: preferences, id: id });
+        require('../preferences/native-options').
+          enable({ preferences: preferences, id: id }).
+          catch(console.exception);
       }
       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
@@ -136,25 +143,28 @@ function run(options) {
 
     // this is where the addon's main.js finally run.
     let program = main(options.loader, options.main);
 
     if (typeof(program.onUnload) === 'function')
       unload(program.onUnload);
 
     if (typeof(program.main) === 'function') {
-
       program.main({
         loadReason: loadReason,
         staticArgs: staticArgs
       }, {
         print: function print(_) { dump(_ + '\n') },
         quit: exit
       });
     }
+
+    if (get("extensions." + id + ".sdk.debug.show", false)) {
+      BrowserToolboxProcess.init({ addonID: id });
+    }
   } catch (error) {
     console.exception(error);
     throw error;
   }
 }
 exports.startup = startup;
 
 // If add-on is lunched via `cfx run` we need to use `system.exit` to let
--- a/addon-sdk/source/python-lib/cuddlefish/prefs.py
+++ b/addon-sdk/source/python-lib/cuddlefish/prefs.py
@@ -50,16 +50,20 @@ DEFAULT_NO_CONNECTIONS_PREFS = {
     'browser.safebrowsing.updateURL': 'http://localhost/safebrowsing-dummy/update',
     'browser.safebrowsing.gethashURL': 'http://localhost/safebrowsing-dummy/gethash',
     'browser.safebrowsing.reportURL': 'http://localhost/safebrowsing-dummy/report',
     'browser.safebrowsing.malware.reportURL': 'http://localhost/safebrowsing-dummy/malwarereport',
 
     # Disable app update
     'app.update.enabled' : False,
 
+    # Disable about:newtab content fetch and ping
+    'browser.newtabpage.directory.source': 'data:application/json,{"jetpack":1}',
+    'browser.newtabpage.directory.ping': '',
+
     # Point update checks to a nonexistent local URL for fast failures.
     'extensions.update.url' : 'http://localhost/extensions-dummy/updateURL',
     'extensions.blocklist.url' : 'http://localhost/extensions-dummy/blocklistURL',
     # Make sure opening about:addons won't hit the network.
     'extensions.webservice.discoverURL' : 'http://localhost/extensions-dummy/discoveryURL'
 }
 
 DEFAULT_FENNEC_PREFS = {
new file mode 100644
--- /dev/null
+++ b/addon-sdk/source/test/addons/author-email/main.js
@@ -0,0 +1,17 @@
+/* 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/. */
+'use strict';
+
+const { Cu } = require('chrome');
+const self = require('sdk/self');
+const { AddonManager } = Cu.import('resource://gre/modules/AddonManager.jsm', {});
+
+exports.testContributors = function(assert, done) {
+  AddonManager.getAddonByID(self.id, (addon) => {
+    assert.equal(addon.creator.name, 'test <test@mozilla.com>', '< and > characters work');
+    done();
+  });
+}
+
+require('sdk/test/runner').runTestsFromModule(module);
new file mode 100644
--- /dev/null
+++ b/addon-sdk/source/test/addons/author-email/package.json
@@ -0,0 +1,4 @@
+{
+  "id": "test-addon-author-email@jetpack",
+  "author": "test <test@mozilla.com>"
+}
--- a/addon-sdk/source/test/test-window-loader.js
+++ b/addon-sdk/source/test/test-window-loader.js
@@ -71,17 +71,17 @@ exports['test `load` events'] = function
         window.document.readyState, 'complete', 'window must be fully loaded'
       );
       assert.ok(onLoadCalled, 'load callback is supposed to be called');
       done();
     }
   });
 };
 
-exports['test removeing listeners'] = function(assert, done) {
+exports['test removing listeners'] = function(assert, done) {
   Loader({
     onLoad: function(window) {
       assert.equal(window, this._window, 'windows should match');
       window.close();
     },
     onUnload: done
   });
 };