Permalink
Browse files

Merge branch 'master' into issue-524

  • Loading branch information...
2 parents a5fa12d + 8780b5e commit aecc071dd11751c32f5f762e20aeaadb1478b6b9 @supahgreg supahgreg committed Sep 5, 2011
@@ -46,6 +46,14 @@ addMessageListener("Scriptish:ScriptChanged", function({json}) {
}
}
});
+addMessageListener("Scriptish:ScriptUninstalled", function({json}) {
+ for (var i = scripts.length - 1; ~i; i--) {
+ if (scripts[i].id == json) {
+ scripts.splice(i, 1);
+ return;
+ }
+ }
+});
})(Components.utils.import, {}, this);
@@ -59,6 +59,12 @@ const Scriptish_ScriptProvider = {
case "scriptish-script-edit-enabled":
AddonManagerPrivate.callAddonListeners(
aData.enabling ? "onEnabled" : "onDisabled", script);
+
+ // notify content processes that a script's enabled state changed
+ if ("Fennec" == Services.appinfo.name) {
+ // TODO: use a more intelligent custom message handler
+ Scriptish_sendAsyncE10SMessage("Scriptish:ScriptChanged", script.toJSON());
+ }
break;
case "scriptish-script-modified":
case "scriptish-script-updated":
@@ -105,6 +111,11 @@ const Scriptish_ScriptProvider = {
break;
case "scriptish-script-uninstalled":
AddonManagerPrivate.callAddonListeners("onUninstalled", script);
+
+ // notify content processes that a script is uninstalled
+ if ("Fennec" == Services.appinfo.name) {
+ Scriptish_sendAsyncE10SMessage("Scriptish:ScriptUninstalled", script.id);
+ }
break;
}
},
@@ -25,6 +25,7 @@ lazyUtil(this, "memoize");
lazyUtil(this, "parser");
lazyUtil(this, "stringBundle");
+const MAX_NAME_LENGTH = 60;
const metaRegExp = /\/\/[ \t]*(?:==\/?UserScript==|\@\S+(?:[ \t]+(?:[^\r\f\n]+))?)/g;
const nonIdChars = /[^\w@\.\-_]+/g; // any char matched by this is not valid
const JSVersions = ['1.6', '1.7', '1.8', '1.8.1'];
@@ -596,6 +597,22 @@ Script.prototype = {
name = name.replace(/[^-_A-Z0-9@]+/gi, "");
ext = ext.replace(/\s+/g, "_").replace(/[^-_A-Z0-9]+/gi, "");
+ // Limit long names to a reasonable length
+ if (name.length > MAX_NAME_LENGTH) {
+ // Try to preserve the namespace
+ var atIndex = name.lastIndexOf("@");
+ var beforeAt = name;
+ var tail = "";
+
+ // 37 == "@".length + approximate_USO_namespace.length
+ if (atIndex >= 0) {
+ beforeAt = name.substring(0, atIndex - 1);
+ tail = name.substring(atIndex).substr(0, 37);
+ }
+
+ name = beforeAt.substr(0, MAX_NAME_LENGTH - tail.length) + tail;
+ }
+
// If no Latin characters found - use default
if (!name) name = "user_script";
if (ext) name += "." + ext;

0 comments on commit aecc071

Please sign in to comment.