Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #512 GM_getMetadata works on Fennec now

  • Loading branch information...
commit 9d0fb7b4e8dcd0c80a2419157fad0a756e072f4b 1 parent 1bde7cd
@erikvold erikvold authored
View
7 extension/content/e10s/browser.js
@@ -8,7 +8,8 @@
lazyImport(this, "resource://scriptish/api/GM_Resources.js", ["GM_Resources"]);
lazyUtil(global, "installUri");
- lazyUtil(this, "notification");
+ lazyUtil(global, "getScriptHeader");
+ lazyUtil(global, "notification");
var $ = function(id) document.getElementById(id);
@@ -86,6 +87,10 @@
Scriptish_notification.apply(null, json);
});
+ mm.addMessageListener("Scriptish:GetScriptMetadata", function({json}) {
+ return Scriptish_getScriptHeader(Scriptish_config.getScriptById(json.id), json.key, json.localVal);
+ });
+
mm.loadFrameScript(
"chrome://scriptish/content/e10s/browser-content.js",
true); // no delay loading frame script
View
4 extension/content/js/install.js
@@ -6,6 +6,8 @@ Components.utils.import("resource://scriptish/constants.js");
lazyImport(this, "resource://scriptish/config.js", ["Scriptish_config"]);
lazyImport(this, "resource://scriptish/utils/Scriptish_localizeDOM.js", ["Scriptish_localizeOnLoad"]);
+
+lazyUtil(this, "getScriptHeader");
lazyUtil(this, "stringBundle");
Scriptish_localizeOnLoad(this);
@@ -45,7 +47,7 @@ function delayedClose() timeout(close);
on("load", function() {
let script = scriptDownloader.script;
- let headers = script.getScriptHeader();
+ let headers = Scriptish_getScriptHeader(script);
// setup lists
["domains", "matches", "includes", "excludes"].forEach(function(i) {
View
14 extension/content/tests/testScriptHeaderParse.js
@@ -1,7 +1,7 @@
-module("Script.header_parse");
+module("Scriptish_parser");
test("normal @keys (with space b4 @)", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
// ==UserScript==
// @id test-id
@@ -22,7 +22,7 @@ test("normal @keys (with space b4 @)", function() {
});
test("normal @keys and following @fail", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
// ==UserScript==
// @id test-id
@@ -41,7 +41,7 @@ test("normal @keys and following @fail", function() {
});
test("normal @keys and leading @fail", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
// @fail test-fail
// ==UserScript==
@@ -60,7 +60,7 @@ test("normal @keys and leading @fail", function() {
});
test("two sets of normal @keys", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
// ==UserScript==
// @id test-id
@@ -81,7 +81,7 @@ test("two sets of normal @keys", function() {
});
test("@keys without space b4 @", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
//==UserScript==
//@id test-id
@@ -103,7 +103,7 @@ test("@keys without space b4 @", function() {
});
test("normal @keys case check", function() {
- var parser = importModule("resource://scriptish/script/script.js").Script.header_parse;
+ var parser = importModule("resource://scriptish/utils/Scriptish_parser.js").Scriptish_parser;
var header = (<><![CDATA[
// ==UserScript==
// @Key v1
View
40 extension/modules/api.js
@@ -9,6 +9,7 @@ lazyImport(this, "resource://scriptish/utils/Scriptish_injectScripts.js", ["Scri
lazyUtil(this, "alert");
lazyUtil(this, "cryptoHash");
+lazyUtil(this, "getScriptHeader");
lazyUtil(this, "notification");
lazyUtil(this, "openInTab");
lazyUtil(this, "stringBundle");
@@ -142,7 +143,7 @@ function GM_API(options) {
this.GM_getResourceText = function GM_getResourceText(aName) {
if (!GM_apiLeakCheck("GM_getResourceText")) return;
- if (options.content) {
+ if (options.global && options.global.sendSyncMessage) {
return options.global.sendSyncMessage("Scriptish:GetScriptResourceText", {
scriptID: aScript.id,
resource: aName
@@ -153,36 +154,17 @@ function GM_API(options) {
}
this.GM_getMetadata = function(aKey, aLocalVal) {
- let key = aKey.toLowerCase().trim();
- if (aLocalVal) {
- switch (key) {
- case "id":
- case "name":
- case "namespace":
- case "creator":
- case "author":
- case "description":
- case "version":
- case "jsversion":
- case "delay":
- case "noframes":
- return aScript[key];
- case "homepage":
- case "homepageurl":
- return aScript.homepageURL;
- case "updateurl":
- return aScript.updateURL;
- case "contributor":
- case "include":
- case "exclude":
- case "screenshot":
- return aScript[key + "s"];
- case "match":
- return aScript[key + "es"];
- }
+ if (!GM_apiLeakCheck("GM_getMetadata")) return;
+
+ if (options.global && options.global.sendSyncMessage) {
+ return options.global.sendSyncMessage("Scriptish:GetScriptMetadata", {
+ id: aScript.id,
+ key: aKey,
+ localVal: aLocalVal
+ })[0];
}
- return aScript.getScriptHeader(key);
+ return Scriptish_getScriptHeader(aScript, aKey, aLocalVal);
}
this.GM_openInTab = function GM_openInTab(aURL, aLoadInBackground, aReuse) {
View
43 extension/modules/script/script.js
@@ -22,6 +22,7 @@ lazyUtil(this, "isGreasemonkeyable");
lazyUtil(this, "getUriFromFile");
lazyUtil(this, "getContents");
lazyUtil(this, "memoize");
+lazyUtil(this, "parser");
lazyUtil(this, "stringBundle");
const metaRegExp = /\/\/[ \t]*(?:==\/?UserScript==|\@\S+(?:[ \t]+(?:[^\r\f\n]+))?)/g;
@@ -203,7 +204,7 @@ Script.prototype = {
if (4 > req.readyState || (req.status != 200 && req.status != 0)
|| !req.responseText)
return;
- var data = Script.header_parse(req.responseText);
+ var data = Scriptish_parser(req.responseText);
if (!data["uso:rating"] || !data["uso:script"] || data["uso:script"][0] != scriptID
|| !data["uso:reviews"] || !data["uso:installs"])
return;
@@ -580,12 +581,6 @@ Script.prototype = {
return this._size;
},
- getScriptHeader: function(aKey) {
- // TODO: cache headers and clear cache when the script is modified..
- var headers = Script.header_parse(Scriptish_getContents(this._tempFile || this._file));
- return aKey ? headers[aKey] : headers;
- },
-
get screenshots() this._screenshots,
_initFileName: function(name, useExt) {
@@ -839,42 +834,12 @@ Script.prototype = {
};
Script.parseVersion = function Script_parseVersion(aSrc) {
- var parsed = Script.header_parse(aSrc);
+ var parsed = Scriptish_parser(aSrc);
if (parsed.version) return parsed.version.pop();
return null;
}
-// TODO: DRY this by combining it with Script.parse some way..
-Script.header_parse = function(aSource) {
- var headers = {};
- var foundMeta = false;
- var line;
-
- // do not 'optimize' by reusing this reg exp! it should not be reused!
- var metaRegExp = /\/\/[ \t]*(?:==(\/?UserScript)==|\@(\S+)(?:[ \t]+([^\r\f\n]+))?)/g;
-
- // read one line at a time looking for start meta delimiter or EOF
- while (line = metaRegExp.exec(aSource)) {
- if (line[1]) {
- if ("userscript" == line[1].toLowerCase()) {
- foundMeta = true; // start
- continue;
- } else {
- break; // done
- }
- }
- if (!foundMeta) continue;
-
- var header = line[2].toLowerCase();
- var value = line[3];
-
- if (!headers[header]) headers[header] = [value];
- else headers[header].push(value);
- }
-
- return headers;
-}
-
+// TODO: DRY this by combining this with Scriptish_parser some way..
Script.parse = function Script_parse(aConfig, aSource, aURI, aUpdateScript) {
var script = new Script(aConfig);
View
1  extension/modules/utils/Scriptish_getProfileFile.js
@@ -1,3 +1,4 @@
+"use strict";
var EXPORTED_SYMBOLS = ["Scriptish_getProfileFile"];
Components.utils.import("resource://scriptish/constants.js");
View
42 extension/modules/utils/Scriptish_getScriptHeader.js
@@ -0,0 +1,42 @@
+"use strict";
+var EXPORTED_SYMBOLS = ["Scriptish_getScriptHeader"];
+Components.utils.import("resource://scriptish/constants.js");
+lazyUtil(this, "getContents");
+lazyUtil(this, "parser");
+
+function Scriptish_getScriptHeader(aScript, aKey, aLocalVal) {
+ if (aLocalVal) {
+ let key = aKey ? aKey.toLowerCase().trim() : "";
+
+ switch (key) {
+ case "id":
+ case "name":
+ case "namespace":
+ case "creator":
+ case "author":
+ case "description":
+ case "version":
+ case "jsversion":
+ case "delay":
+ case "noframes":
+ return aScript[key];
+ case "homepage":
+ case "homepageurl":
+ return aScript.homepageURL;
+ case "updateurl":
+ return aScript.updateURL;
+ case "contributor":
+ case "include":
+ case "exclude":
+ case "screenshot":
+ return aScript[key + "s"];
+ case "match":
+ return aScript[key + "es"];
+ }
+ }
+
+ // TODO: cache headers and clear cache when the script is modified..
+ // TODO: should not use privates here
+ var headers = Scriptish_parser(Scriptish_getContents(aScript._tempFile || aScript._file));
+ return aKey ? headers[aKey] : headers;
+}
View
32 extension/modules/utils/Scriptish_parser.js
@@ -0,0 +1,32 @@
+"use strict";
+var EXPORTED_SYMBOLS = ["Scriptish_parser"];
+
+function Scriptish_parser(aSource) {
+ var headers = {};
+ var foundMeta = false;
+ var line;
+
+ // do not 'optimize' by reusing this reg exp! it should not be reused!
+ var metaRegExp = /\/\/[ \t]*(?:==(\/?UserScript)==|\@(\S+)(?:[ \t]+([^\r\f\n]+))?)/g;
+
+ // read one line at a time looking for start meta delimiter or EOF
+ while (line = metaRegExp.exec(aSource)) {
+ if (line[1]) {
+ if ("userscript" == line[1].toLowerCase()) {
+ foundMeta = true; // start
+ continue;
+ } else {
+ break; // done
+ }
+ }
+ if (!foundMeta) continue;
+
+ var header = line[2].toLowerCase();
+ var value = line[3];
+
+ if (!headers[header]) headers[header] = [value];
+ else headers[header].push(value);
+ }
+
+ return headers;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.