[Pkg-mozext-commits] [greasemonkey] 01/21: ScriptProtocol.newChannel(): Function correctly in parent.
David Prévot
taffit at moszumanska.debian.org
Sun Sep 13 21:27:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository greasemonkey.
commit 6f5ba1ce5c03f5628ad737b20627e0399b620759
Author: Anthony Lieuallen <arantius at gmail.com>
Date: Fri May 29 18:49:29 2015 -0400
ScriptProtocol.newChannel(): Function correctly in parent.
Fixes #1955
---
modules/scriptProtocol.js | 48 +++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/modules/scriptProtocol.js b/modules/scriptProtocol.js
index 149ae35..234d2c9 100644
--- a/modules/scriptProtocol.js
+++ b/modules/scriptProtocol.js
@@ -113,21 +113,41 @@ var ScriptProtocol = {
// Incomplete URI, send a 404.
if (!m) return dummy;
- var mm = Cc["@mozilla.org/childprocessmessagemanager;1"]
- .getService(Ci.nsISyncMessageSender);
- var response = mm.sendSyncMessage(
- 'greasemonkey:scripts-for-uuid', {'uuid': m[1]});
- // We expect exactly one response, listing exactly one script.
- if (response.length != 1) return dummy;
- if (response[0].length != 1) return dummy;
-
- // So, fail. The service only exists in the parent process.
- var script = response[0][0];
- if (script) {
- for (var i = 0, resource = null; resource = script.resources[i]; i++) {
- if (resource.name == m[2]) {
- return ioService.newChannelFromURI(GM_util.uriFromUrl(resource.url));
+ var script = null;
+ // If we're serving (e.g.) a favicon image, this request can be coming
+ // from the parent process!
+ var runtime = Cc["@mozilla.org/xre/app-info;1"]
+ .getService(Ci.nsIXULRuntime);
+ if (runtime.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
+ var scripts = GM_util.getService().config.getMatchingScripts(
+ function(script) { return script.uuid == m[1]; }
+ );
+ script = scripts && scripts.length && scripts[0];
+ } else {
+ var mm = Cc["@mozilla.org/childprocessmessagemanager;1"]
+ .getService(Ci.nsISyncMessageSender);
+ var response = mm.sendSyncMessage(
+ 'greasemonkey:scripts-for-uuid', {'uuid': m[1]});
+ // We expect exactly one response, listing exactly one script.
+ if (response.length != 1) return dummy;
+ if (response[0].length != 1) return dummy;
+ script = response[0][0];
+ }
+
+ // Fail fast if we couldn't find the script.
+ if (!script) return dummy;
+
+ for (var i = 0, resource = null; resource = script.resources[i]; i++) {
+ if (resource.name == m[2]) {
+ var uri = null;
+ if (resource.url) {
+ // In child scope, IPCScript gives us the URL to the file.
+ uri = GM_util.uriFromUrl(resource.url);
+ } else {
+ // In parent scope we have the raw script, with file intact.
+ uri = GM_util.getUriFromFile(resource.file);
}
+ return ioService.newChannelFromURI(uri);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git
More information about the Pkg-mozext-commits
mailing list