Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #514 and #523 Fetching user script textContent from chrome pro…

…cess, adding installed user scripts to already open content processes, and adding installed user scripts to EM.
  • Loading branch information...
commit c3fc1cce6e0b5f01f62fc942e7d53b6276021aa2 1 parent 9bad530
@erikvold erikvold authored
View
10 extension/content/e10s/browser-content.js
@@ -18,14 +18,13 @@ function updateExcludes({json}) {
}
var configJSON = sendSyncMessage("Scriptish:FrameSetup", "")[0];
+var scripts;
(function(configJSON) {
Scriptish_setExcludes(configJSON.excludes);
- var scripts = configJSON.scripts.map(function(i) {
- var script = SimpleScript.loadFromJSON(i);
- script.textContent = sendSyncMessage("Scriptish:GetScriptContents", script.id)[0];
- return script;
+ scripts = configJSON.scripts.map(function(i) {
+ return SimpleScript.loadFromJSON(i);
});
Scriptish_manager.setup({
@@ -36,6 +35,9 @@ var configJSON = sendSyncMessage("Scriptish:FrameSetup", "")[0];
})(configJSON);
addMessageListener("Scriptish:GlobalExcludesUpdate", updateExcludes);
+addMessageListener("Scriptish:ScriptInstalled", function(data) {
+ scripts.push(SimpleScript.loadFromJSON(data.json));
+});
})(Components.utils.import, {}, this);
View
23 extension/content/e10s/browser.js
@@ -16,9 +16,9 @@
inc("resource://scriptish/utils/Scriptish_updateChk.js");
var us_head = $("addons-userscripts");
- var next = us_head.nextSibling;
var parent = us_head.parentNode;
- Scriptish_config.scripts.forEach(function(script) {
+
+ function createNode(script) {
var ele = ExtensionsView._createItem(script, "userscript");
ele.setAttribute("typeLabel", "User Script");
// TODO: implement for Fennec.. #517
@@ -26,8 +26,23 @@
ele.setAttribute("isDisabled", !script.enabled);
ele.setAttribute("data-scriptish-scriptid", script.id);
ele.addon = script;
- parent.insertBefore(ele, next);
- });
+ return ele;
+ }
+
+ function insertScript(script) {
+ parent.insertBefore(createNode(script), us_head.nextSibling);
+ }
+
+ // insert script nodes into the EM
+ Scriptish_config.scripts.forEach(insertScript);
+ Services.obs.addObserver({
+ observe: function(aSubject, aTopic, aData) {
+ tools.timeout(function() {
+ var script = Scriptish_config.getScriptById(JSON.parse(aData).id);
+ insertScript(script);
+ });
+ }
+ }, "scriptish-script-installed", false);
}, false);
var mm = messageManager;
View
5 extension/modules/addonprovider.js
@@ -9,6 +9,7 @@ lazyImport(this, "resource://gre/modules/AddonManager.jsm", ["AddonManager", "Ad
lazyUtil(this, "notification");
lazyUtil(this, "openManager");
lazyUtil(this, "popupNotification");
+lazyUtil(this, "sendAsyncE10SMessage");
lazyUtil(this, "stringBundle");
const Scriptish_ScriptProvider = {
@@ -45,6 +46,10 @@ const Scriptish_ScriptProvider = {
Scriptish_notification(msg, null, null, callback);
}
+ if ("Fennec" == Services.appinfo.name) {
+ Scriptish_sendAsyncE10SMessage("Scriptish:ScriptInstalled", script.toJSON());
+ }
+
break;
case "scriptish-script-edit-enabling":
AddonManagerPrivate.callAddonListeners(
View
4 extension/modules/api.js
@@ -123,7 +123,7 @@ function GM_API(options) {
if (!GM_apiLeakCheck("GM_getResourceURL")) return;
if (options.content) {
- return options.content.sendSyncMessage("Scriptish:GetScriptResourceURL", {
+ return options.global.sendSyncMessage("Scriptish:GetScriptResourceURL", {
scriptID: aScript.id,
resource: aName
});
@@ -135,7 +135,7 @@ function GM_API(options) {
if (!GM_apiLeakCheck("GM_getResourceText")) return;
if (options.content) {
- return options.content.sendSyncMessage("Scriptish:GetScriptResourceText", {
+ return options.global.sendSyncMessage("Scriptish:GetScriptResourceText", {
scriptID: aScript.id,
resource: aName
});
View
6 extension/modules/utils/Scriptish_evalInSandbox.js
@@ -19,9 +19,11 @@ function Scriptish_evalInSandbox(aScript, aSandbox, aWindow, options) {
// e10s
if (options && options.global && options.global.sendSyncMessage) {
var reqAry = options.global.sendSyncMessage("Scriptish:GetScriptRequires", id)[0];
+ var scriptText = options.global.sendSyncMessage("Scriptish:GetScriptContents", id)[0];
}
else {
var reqAry = aScript.requires;
+ var scriptText = aScript.textContent;
}
// eval script @requires
@@ -48,7 +50,7 @@ function Scriptish_evalInSandbox(aScript, aSandbox, aWindow, options) {
try {
try {
Cu.evalInSandbox(
- aScript.textContent + "\n",
+ scriptText + "\n",
aSandbox,
jsVer,
fileURLPrefix + fileURL,
@@ -71,7 +73,7 @@ function Scriptish_evalInSandbox(aScript, aSandbox, aWindow, options) {
);
Scriptish_logScriptError(sw, aWindow, fileURL, id);
Cu.evalInSandbox(
- "(function(){" + aScript.textContent + "\n})()",
+ "(function(){" + scriptText + "\n})()",
aSandbox,
jsVer,
fileURLPrefix + fileURL,
View
1  extension/modules/utils/Scriptish_sendAsyncE10SMessage.js
@@ -1,5 +1,6 @@
var EXPORTED_SYMBOLS = ["Scriptish_sendAsyncE10SMessage"];
Components.utils.import("resource://scriptish/constants.js");
+Components.utils.import("resource://scriptish/scriptish.js");
function Scriptish_sendAsyncE10SMessage(aName, aJSON) {
let bWins = Scriptish.getWindows();
Please sign in to comment.
Something went wrong with that request. Please try again.