Last active
August 29, 2015 14:27
-
-
Save meandavejustice/b434b643e116b3196fc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stack: | |
"send@resource://gre/modules/commonjs/toolkit/loader.js -> | |
resource://gre/modules/commonjs/sdk/content/worker.js:90:57sendToWeb@ | |
resource://gre/modules/commonjs/toolkit/loader.js -> | |
resource://idea-town-addon/index.js:124:5installListeners.onDownloadProgress@ | |
resource://gre/modules/commonjs/toolkit/loader.js -> | |
resource://idea-town-addon/index.js:71:5AMI_callInstallListeners@ | |
resource://gre/modules/AddonManager.jsm:1621:15AMP_callInstallListeners@ | |
resource://gre/modules/AddonManager.jsm:2568:1AI_onDataAvailable@ | |
resource://gre/modules/addons/XPIProvider.jsm:5627:10" | |
Filename: | |
resource://gre/modules/commonjs/toolkit/loader.js -> | |
resource://gre/modules/commonjs/sdk/content/worker.js | |
Message: | |
Component returned failure code: 0x80520009 (NS_ERROR_FILE_INVALID_PATH) [nsIFile.target] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This Source Code is subject to the terms of the Mozilla Public License | |
* version 2.0 (the "License"). You can obtain a copy of the License at | |
* http://mozilla.org/MPL/2.0/. | |
*/ | |
const {Cu} = require("chrome"); | |
const self = require('sdk/self'); | |
const pageMod = require("sdk/page-mod"); | |
let workers = []; | |
pageMod.PageMod({ | |
include: cfg.ALLOWED_ORIGINS, | |
contentScriptFile: self.data.url("message-bridge.js"), | |
contentScriptWhen: 'start', | |
onAttach: setupWorker | |
}); | |
let {AddonManager} = Cu.import("resource://gre/modules/AddonManager.jsm", null); | |
function setupWorker (worker) { | |
// workers.push(worker); | |
worker.port.on('detach', function (msg, what, ok) { | |
console.error('worker detached', msg, what, ok); | |
}); | |
worker.port.on('error', function (msg, what, ok) { | |
console.error('worker error', msg, what, ok); | |
}); | |
worker.port.on('from-web-to-addon', function (msg) { | |
if (!msg.type) { return; } | |
switch (msg.type) { | |
case 'update-check': | |
sendToWeb(worker, { type: 'addon-updates', detail: state.updates }); | |
break; | |
case 'update-approve': | |
state.updates = require('exclude')(state.updates, msg.detail); | |
button.badge = state.updates.length; | |
triggerInstalls(msg.detail); | |
break; | |
case 'loaded': | |
sendToWeb(worker, { type: 'addon-available' }); | |
break; | |
default: | |
console.log('ADDON RECEIVED FROM WEB', msg); | |
sendToWeb(worker, { type: 'echo', data: msg }); | |
break; | |
} | |
}); | |
var installListeners = { | |
onInstallEnded: function(install, addon) { | |
console.error('onInstallEnded'); | |
sendToWeb(worker, {type: 'addon-install:install-ended', detail: install}); | |
}, | |
onInstallFailed: function(install) { | |
console.error('onInstallFailed'); | |
sendToWeb(worker, {type: 'addon-install:install-failed', detail: install}); | |
}, | |
onInstallStarted: function(install) { | |
console.error('onInstallStarted'); | |
sendToWeb(worker, {type: 'addon-install:install-started', detail: install}); | |
}, | |
onNewInstall: function(install) { | |
console.error('onNewInstall'); | |
sendToWeb(worker, {type: 'addon-install:install-new', detail: install}); | |
}, | |
onInstallCancelled: function(install) { | |
console.error('onInstallCancelled'); | |
sendToWeb(worker, {type: 'addon-install:install-cancelled', detail: install}); | |
}, | |
onDownloadStarted: function(install) { | |
console.error('onDownloadStarted') | |
throw new Error('fuck evertything'); | |
sendToWeb(worker, {type: 'addon-install:download-started', detail: install}); | |
}, | |
onDownloadProgress: function(install) { | |
console.error('onDownloadProgress') | |
sendToWeb(worker, {type: 'addon-install:download-progress', detail: install}); | |
}, | |
onDownloadEnded: function(install) { | |
console.error('onDownloadEnded') | |
sendToWeb(worker, {type: 'addon-install:download-ended', detail: install}); | |
}, | |
onDownloadCancelled: function(install) { | |
console.error('onDownloadCancelled') | |
sendToWeb(worker, {type: 'addon-install:download-cancelled', detail: install}); | |
}, | |
onDownloadFailed: function(install) { | |
console.error('onDownloadFailed') | |
sendToWeb(worker, {type: 'addon-install:download-failed', detail: install}); | |
} | |
}; | |
AddonManager.addInstallListener(installListeners); | |
} | |
function sendToWeb(worker, data) { | |
try { | |
worker.port.emit('from-addon-to-web', data); | |
// workers[workers.length -1].port.emit('from-addon-to-web', data); | |
// workers.forEach(function(work) { | |
// work.port.emit('from-addon-to-web', data); | |
// }) | |
} | |
catch (e) { | |
console.error('sendToWeb ERROR:: ', e); | |
} | |
console.error('sendToWeb:: ', worker, data); | |
} | |
/* | |
* Originally sourced from https://github.com/palant/autoinstaller/blob/master/lib/main.js#L22 | |
* | |
* */ | |
function installAddon(data) { | |
try { | |
AddonManager.getInstallForURL(data, function(install) { | |
install.install(); | |
}, "application/x-xpinstall"); | |
} | |
catch (e) { | |
console.error(e) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Page script acts as messaging bridge between addon and web content. | |
// Relay messages from web to addon. | |
window.addEventListener("from-web-to-addon", function (event) { | |
self.port.emit('from-web-to-addon', event.detail); | |
}, false); | |
// Relay messages from addon to web. | |
self.port.on('from-addon-to-web', function (data) { | |
var clonedDetail = cloneInto(data, document.defaultView); | |
document.documentElement.dispatchEvent(new CustomEvent( | |
'from-addon-to-web', { bubbles: true, detail: clonedDetail } | |
)); | |
}); | |
self.port.on('detach', function (msg, what, ok) { | |
console.error('worker detached', msg, what, ok); | |
}); | |
self.port.on('error', function (msg, what, ok) { | |
console.error('worker error', msg, what, ok); | |
}); | |
self.on('detach', function (msg, what, ok) { | |
console.error('worker detached', msg, what, ok); | |
}); | |
self.on('error', function (msg, what, ok) { | |
console.error('worker error', msg, what, ok); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment