Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4 from ochameau/bug/733582-post-1.4-refactoring-f…
Browse files Browse the repository at this point in the history
…ixes

Bug 733582: Post 1.4 refactoring fixes. r=@erikvold
  • Loading branch information
ochameau committed Sep 10, 2012
2 parents 7b46c8f + ccf05aa commit 0c040e6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 189 deletions.
76 changes: 0 additions & 76 deletions lib/addon-install.js

This file was deleted.

77 changes: 50 additions & 27 deletions lib/addons-builder-helper.js
Expand Up @@ -5,40 +5,50 @@
const { Cc, Ci, Cu } = require('chrome'); const { Cc, Ci, Cu } = require('chrome');
const windowManager = Cc['@mozilla.org/appshell/window-mediator;1']. const windowManager = Cc['@mozilla.org/appshell/window-mediator;1'].
getService(Ci.nsIWindowMediator); getService(Ci.nsIWindowMediator);
const windowUtils = require("api-utils/window/utils");


const { PageMod } = require("addon-kit/page-mod"); const { PageMod } = require("addon-kit/page-mod");


const { AddonInstall } = require("addon-install"); const AddonInstaller = require("api-utils/addon/installer");
const { createTemporaryFileFromData } = require("file-utils"); const tmpFile = require("test-harness/tmp-file");


const CONFIG_FILENAME = "addon-config.json"; const CONFIG_FILENAME = "addon-config.json";
const CONFIG_PREF = "extensions.addonBuilderHelper.trustedOrigins"; const CONFIG_PREF = "extensions.addonBuilderHelper.trustedOrigins";




/** /**
* Utility method to toggle the XUL JS Console. * Utility method to toggle the XUL JS Console.
* Return `message` attribute send back to webpage. * Return `message` attribute sent back to the webpage.
*/ */
let consoleWindow = null;
function toggleConsoleWindow(command) { function toggleConsoleWindow(command) {
consoleWindow = windowManager.getMostRecentWindow('global:console'); let consoleWindow = windowManager.getMostRecentWindow('global:console');
switch(command) { switch(command) {
case 'open': case 'open':
consoleWindow = consoleWindow ? consoleWindow.focus() : if (consoleWindow)
windowManager.getMostRecentWindow(null) consoleWindow.focus();
.open('chrome://global/content/console.xul', else
'_blank', windowUtils.open('chrome://global/content/console.xul', {
'chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar'); features: {
chrome: true,
extrachrome: true,
menubar: true,
resizable: true,
scrollbars: true,
status: true,
toolbar: true
}
});
break; break;
case 'close': case 'close':
consoleWindow = consoleWindow ? consoleWindow.close() : null; if (consoleWindow)
consoleWindow.close();
break; break;
case 'isOpen': case 'isOpen':
return consoleWindow ? true : false; return consoleWindow ? true : false;
break; break;
default: default:
return 'An unrecognized command was passed through the "contents" ' + return 'An unrecognized command was passed for the "toggleConsole" ' +
'property of the mozFlightDeck send object. Available commands ' + 'command of the mozFlightDeck send action. Available commands ' +
'are "open", "close", and "isOpen"'; 'are "open", "close", and "isOpen"';
} }
return null; return null;
Expand Down Expand Up @@ -124,36 +134,49 @@ function onContentScriptRequest(addonManager, args, callback) {
} }


function SingleAddonManager() { function SingleAddonManager() {
var self = this; let currentAddonId = null;
var currExtension = null;


return { return {
get isInstalled() { get isInstalled() {
return (currExtension != null && currExtension.isInstalled); return currentAddonId != null;
}, },


get installedID() { get installedID() {
if (!currExtension) return currentAddonId;
return null;
return currExtension.id;
}, },


install: function install(xpiData, callback) { install: function install(xpiData, callback) {
if (currExtension) { // If an addon is already installed, uninstall it first
if (currentAddonId) {
let self = this; let self = this;
self.uninstall(function () { self.uninstall(function () {
self.install(xpiData, callback); self.install(xpiData, callback);
}); });
} }
else else {
currExtension = AddonInstall.new(createTemporaryFileFromData(xpiData), callback); let xpiPath = tmpFile.createFromString(xpiData);
AddonInstaller.install(xpiPath).then(function success(addonId) {
currentAddonId = addonId;
if (typeof callback == "function")
callback(true, addonId);
},
function failure(reason) {
currentAddonId = null;
if (typeof callback == "function")
callback(false);
});
}
}, },


uninstall: function uninstall(callback) { uninstall: function uninstall(callback) {
if (currExtension) { if (!currentAddonId) {
var oldExtension = currExtension; if (typeof callback == "function")
currExtension = null; callback();
oldExtension.unload(callback); }
else {
let addonId = currentAddonId;
currentAddonId = null;
AddonInstaller.uninstall(addonId).then(callback);
} }
} }
}; };
Expand Down Expand Up @@ -186,7 +209,7 @@ exports.main = function main() {
try { try {
config.trustedOrigins = config.trustedOrigins.concat(pref.split(",")); config.trustedOrigins = config.trustedOrigins.concat(pref.split(","));
} catch (e) { } catch (e) {
console.log("Error when reading preference " + CONFIG_PREF); console.error("Error when reading preference " + CONFIG_PREF);
console.exception(e); console.exception(e);
} }
} }
Expand Down
37 changes: 0 additions & 37 deletions lib/file-utils.js

This file was deleted.

46 changes: 0 additions & 46 deletions tests/test-addon-install.js

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test-addons-builder-helper.js
Expand Up @@ -4,9 +4,9 @@


const { Cc, Ci, Cu } = require("chrome"); const { Cc, Ci, Cu } = require("chrome");
const tabs = require("addon-kit/tabs"); const tabs = require("addon-kit/tabs");
const { Services } = Components.utils.import("resource://gre/modules/Services.jsm"); const { Services } = Cu.import("resource://gre/modules/Services.jsm");


const { readBinaryURI } = require("file-utils"); const { getChromeURIContent } = require("api-utils/utils/data");


const TEST_ADDON_URL = require("self").data.url("abh-unit-test@mozilla.com.xpi"); const TEST_ADDON_URL = require("self").data.url("abh-unit-test@mozilla.com.xpi");


Expand Down Expand Up @@ -189,7 +189,7 @@ exports.testInstall = createTest(
Services.obs.addObserver(eventsObserver, "abh-unit-test", false); Services.obs.addObserver(eventsObserver, "abh-unit-test", false);


// We can't use self.data.load as it doesn't read in binary mode! // We can't use self.data.load as it doesn't read in binary mode!
let xpiData = readBinaryURI(TEST_ADDON_URL); let xpiData = getChromeURIContent(TEST_ADDON_URL);
worker.port.emit("xpiData", xpiData); worker.port.emit("xpiData", xpiData);


worker.port.on("uninstalled", function () { worker.port.on("uninstalled", function () {
Expand Down

0 comments on commit 0c040e6

Please sign in to comment.