[Pkg-mozext-commits] [greasemonkey] 33/43: Move ScriptProtocol into a JSM loaded by frame script.
David Prévot
taffit at moszumanska.debian.org
Sun Feb 22 21:56:12 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 f249351140408712963587ef5616c1bcc0ea5a08
Author: Anthony Lieuallen <arantius at gmail.com>
Date: Wed Jan 28 10:14:56 2015 -0500
Move ScriptProtocol into a JSM loaded by frame script.
---
chrome.manifest | 3 -
components/greasemonkey.js | 36 +++++++++---
components/scriptProtocol.js | 96 ------------------------------
content/framescript.js | 2 +
modules/installPolicy.js | 3 +
modules/ipcscript.js | 3 +-
modules/scriptProtocol.js | 136 +++++++++++++++++++++++++++++++++++++++++++
7 files changed, 170 insertions(+), 109 deletions(-)
diff --git a/chrome.manifest b/chrome.manifest
index cd9a430..4218e0e 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -2,9 +2,6 @@ component {77bf3650-1cd6-11da-8cd6-0800200c9a66} components/greasemonkey.js
contract @greasemonkey.mozdev.org/greasemonkey-service;1 {77bf3650-1cd6-11da-8cd6-0800200c9a66}
category profile-after-change @greasemonkey.mozdev.org/greasemonkey-service;1 @greasemonkey.mozdev.org/greasemonkey-service;1
-component {20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598} components/scriptProtocol.js
-contract @mozilla.org/network/protocol;1?name=greasemonkey-script {20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598}
-
content greasemonkey content/
skin greasemonkey classic/1.0 skin/
diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index 2147c9e..8cb2171 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -44,27 +44,34 @@ function startup(aService) {
loader.loadSubScript("chrome://greasemonkey/content/config.js");
loader.loadSubScript("chrome://greasemonkey/content/third-party/mpl-utils.js");
- var messageManager = Cc["@mozilla.org/globalmessagemanager;1"]
+ var parentMessageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:script-install', aService.scriptInstall.bind(aService));
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:scripts-for-url', aService.getScriptsForUrl.bind(aService));
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
+ 'greasemonkey:scripts-for-uuid',
+ aService.getScriptsForUuid.bind(aService));
+ parentMessageManager.addMessageListener(
'greasemonkey:url-is-temp-file', aService.urlIsTempFile.bind(aService));
var scriptValHandler = aService.handleScriptValMsg.bind(aService);
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:scriptVal-delete', scriptValHandler);
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:scriptVal-get', scriptValHandler);
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:scriptVal-list', scriptValHandler);
- messageManager.addMessageListener(
+ parentMessageManager.addMessageListener(
'greasemonkey:scriptVal-set', scriptValHandler);
- messageManager.loadFrameScript(
+ // Yes, we have to load the frame script once here in the parent scope.
+ // Why? Who knows!?
+ var globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"]
+ .getService(Ci.nsIMessageListenerManager);
+ globalMessageManager.loadFrameScript(
"chrome://greasemonkey/content/framescript.js", true);
Services.obs.addObserver(aService, 'quit-application', false);
@@ -152,6 +159,17 @@ service.prototype.getScriptsForUrl = function(aMessage) {
return scripts;
};
+service.prototype.getScriptsForUuid = function(aMessage) {
+ var uuid = aMessage.data.uuid;
+ var scripts = this.config.getMatchingScripts(
+ function(script) { return script.uuid == uuid; }
+ ).map(function(script) {
+ // Make the script serializable so it can be sent to the frame script.
+ return new IPCScript(script);
+ });
+ return scripts;
+};
+
service.prototype.getStoreByScriptId = function(aScriptId) {
if ('undefined' == typeof this.scriptValStores[aScriptId]) {
var script = this.config.getScriptById(aScriptId);
diff --git a/components/scriptProtocol.js b/components/scriptProtocol.js
deleted file mode 100644
index ee5eb60..0000000
--- a/components/scriptProtocol.js
+++ /dev/null
@@ -1,96 +0,0 @@
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import('resource://greasemonkey/util.js');
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const schemeName = 'greasemonkey-script';
-const ioService = Cc['@mozilla.org/network/io-service;1']
- .getService(Ci.nsIIOService);
-
-
-function DummyChannel(aUri, aScript) {
- // nsIRequest
- this.loadFlags = 0;
- this.loadGroup = null;
- this.name = aUri.spec;
- this.status = 404;
- this.content = '';
-
- // nsIChannel
- this.contentCharset = 'utf-8';
- this.contentLength = this.content.length;
- this.contentType = 'application/javascript';
- this.notificationCallbacks = null;
- this.originalURI = aUri;
- this.owner = null;
- this.securityInfo = null;
- this.URI = aUri;
-}
-
-// nsIChannel
-DummyChannel.prototype.asyncOpen = function(aListener, aContext) { };
-
-
-function ScriptProtocol() {}
-
-// XPCOMUtils generation
-ScriptProtocol.prototype.classDescription =
- 'Protocol handler for greasemonkey-script:';
-ScriptProtocol.prototype.classID =
- Components.ID('{20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598}');
-ScriptProtocol.prototype.contractID =
- '@mozilla.org/network/protocol;1?name=' + schemeName;
-ScriptProtocol.prototype.QueryInterface = XPCOMUtils.generateQI([
- Components.interfaces.nsIProtocolHandler,
- Components.interfaces.nsISupports,
- ]);
-
-// nsIProtocolHandler
-ScriptProtocol.prototype.scheme = schemeName;
-ScriptProtocol.prototype.defaultPort = -1;
-ScriptProtocol.prototype.protocolFlags = 0
- | Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT
- | Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE
- | Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE
- | Ci.nsIProtocolHandler.URI_NOAUTH
- | Ci.nsIProtocolHandler.URI_NON_PERSISTABLE
- | Ci.nsIProtocolHandler.URI_NORELATIVE
- ;
-
-// nsIProtocolHandler
-ScriptProtocol.prototype.allowPort = function(aPort, aScheme) {
- return false;
-};
-
-// nsIProtocolHandler
-ScriptProtocol.prototype.newURI = function(aSpec, aCharset, aBaseUri) {
- var uri = Cc['@mozilla.org/network/simple-uri;1'].createInstance(Ci.nsIURI);
- uri.spec = aSpec;
- return uri;
-};
-
-// nsIProtocolHandler
-ScriptProtocol.prototype.newChannel = function(aUri) {
- var m = aUri.spec.match(/greasemonkey-script:([-0-9a-f]+)\/(.*)/);
-
- // Incomplete URI, send a 404.
- if (!m) return new DummyChannel(aUri);
-
- var script = GM_util.getService().config.getMatchingScripts(function(script) {
- return script.uuid == m[1];
- })[0];
-
- if (script) {
- for (var i = 0, resource = null; resource = script.resources[i]; i++) {
- if (resource.name == m[2]) {
- return ioService.newChannelFromURI(
- GM_util.getUriFromFile(resource.file));
- }
- }
- }
-
- // Default fall-through case, send a 404.
- return new DummyChannel(aUri);
-};
-
-var NSGetFactory = XPCOMUtils.generateNSGetFactory([ScriptProtocol]);
diff --git a/content/framescript.js b/content/framescript.js
index 22f4503..7289d9c 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -13,6 +13,7 @@ Cu.import('resource://greasemonkey/installPolicy.js');
Cu.import('resource://greasemonkey/ipcscript.js');
Cu.import('resource://greasemonkey/miscapis.js');
Cu.import('resource://greasemonkey/sandbox.js');
+Cu.import('resource://greasemonkey/scriptProtocol.js');
Cu.import('resource://greasemonkey/util.js');
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
@@ -281,4 +282,5 @@ addEventListener('unload', function() {
(function() {
var tmpDir = sendSyncMessage('greasemonkey:temp-dir-path');
initInstallPolicy(tmpDir[0]);
+ initScriptProtocol();
})();
diff --git a/modules/installPolicy.js b/modules/installPolicy.js
index dbcadb2..bb239cd 100644
--- a/modules/installPolicy.js
+++ b/modules/installPolicy.js
@@ -11,6 +11,7 @@ Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://greasemonkey/util.js');
+var gHaveDoneInit = false;
var gIgnoreNextScript = false;
var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
@@ -21,6 +22,8 @@ function ignoreNextScript() {
}
function initInstallPolicy(aTmpPath) {
+ if (gHaveDoneInit) return;
+ gHaveDoneInit = true;
InstallPolicy.init(aTmpPath);
}
diff --git a/modules/ipcscript.js b/modules/ipcscript.js
index 87f6794..dba1f3e 100644
--- a/modules/ipcscript.js
+++ b/modules/ipcscript.js
@@ -31,7 +31,8 @@ function IPCScript(aScript) {
return {
'name': res.name,
'mimetype': res.mimetype,
- 'textContent': res.textContent
+ 'textContent': res.textContent,
+ 'url': GM_util.getUriFromFile(res.file).spec
};
});
};
diff --git a/modules/scriptProtocol.js b/modules/scriptProtocol.js
new file mode 100644
index 0000000..a6426ac
--- /dev/null
+++ b/modules/scriptProtocol.js
@@ -0,0 +1,136 @@
+var EXPORTED_SYMBOLS = ['initScriptProtocol'];
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import('resource://greasemonkey/util.js');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const schemeName = 'greasemonkey-script';
+const ioService = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+
+
+var gHaveDoneInit = false;
+var gScope = this;
+
+function initScriptProtocol() {
+ if (gHaveDoneInit) return;
+ gHaveDoneInit = true;
+ ScriptProtocol.init();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+function DummyChannel(aUri, aScript) {
+ // nsIRequest
+ this.loadFlags = 0;
+ this.loadGroup = null;
+ this.name = aUri.spec;
+ this.status = 404;
+ this.content = '';
+
+ // nsIChannel
+ this.contentCharset = 'utf-8';
+ this.contentLength = this.content.length;
+ this.contentType = 'application/javascript';
+ this.notificationCallbacks = null;
+ this.originalURI = aUri;
+ this.owner = null;
+ this.securityInfo = null;
+ this.URI = aUri;
+}
+
+// nsIChannel
+DummyChannel.prototype.asyncOpen = function(aListener, aContext) { };
+
+////////////////////////////////////////////////////////////////////////////////
+
+var ScriptProtocol = {
+ _classDescription: 'Protocol handler for "greasemonkey-script:"',
+ _classID: Components.ID('20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598'),
+ _contractID: '@mozilla.org/network/protocol;1?name=' + schemeName,
+
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsIFactory,
+ Ci.nsIProtocolHandler,
+ Ci.nsISupportsWeakReference
+ ]),
+
+ init: function() {
+ try {
+ var registrar = Components.manager.QueryInterface(
+ Ci.nsIComponentRegistrar);
+ registrar.registerFactory(
+ this._classID, this._classDescription, this._contractID, this);
+ } catch (e) {
+ if ('NS_ERROR_FACTORY_EXISTS' == e.name) {
+ // No-op, ignore these. But why do they happen!?
+ } else {
+ dump('Error registering ScriptProtocol factory:\n' + e + '\n');
+ }
+ return;
+ };
+ },
+
+////////////////////////////////// nsIFactory //////////////////////////////////
+
+ createInstance: function(outer, iid) {
+ if (outer) {
+ throw Cr.NS_ERROR_NO_AGGREGATION;
+ }
+ return this.QueryInterface(iid);
+ },
+
+////////////////////////////// nsIProtocolHandler //////////////////////////////
+
+ scheme: schemeName,
+ defaultPort: -1,
+ protocolFlags: 0
+ | Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT
+ | Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE
+ | Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE
+ | Ci.nsIProtocolHandler.URI_NOAUTH
+ | Ci.nsIProtocolHandler.URI_NON_PERSISTABLE
+ | Ci.nsIProtocolHandler.URI_NORELATIVE
+ ,
+
+ allowPort: function(aPort, aScheme) {
+ return false;
+ },
+
+ newURI: function(aSpec, aCharset, aBaseUri) {
+ var uri = Cc['@mozilla.org/network/simple-uri;1']
+ .createInstance(Ci.nsIURI);
+ uri.spec = aSpec;
+ return uri;
+ },
+
+ newChannel: function(aUri) {
+ var m = aUri.spec.match(/greasemonkey-script:([-0-9a-f]+)\/(.*)/);
+ var dummy = new DummyChannel(aUri);
+
+ // 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));
+ }
+ }
+ }
+
+ // Default fall-through case, send a 404.
+ return dummy;
+ }
+};
--
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