[Pkg-mozext-commits] [greasemonkey] 06/16: Remove ScriptChannel.

David Prévot taffit at moszumanska.debian.org
Thu Jan 30 13:42:28 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository greasemonkey.

commit d38792d54b9758e0569c493cdbf97b39e1aa5661
Author: Ventero <ventero at ventero.de>
Date:   Sun Jan 26 22:42:47 2014 +0100

    Remove ScriptChannel.
    
    Using the resource URL of a resource with a name that ends with
    .user.js would lead to surprising results: GM_getResourceText
    would return the actual resource content, but using the URL returned
    by GM_getResourceURL would result in the parent script content being
    returned.
    
    Refs 1999be3484154d22f41afba465fb56366e6cf61b.
---
 components/scriptProtocol.js | 48 +++++++++++---------------------------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/components/scriptProtocol.js b/components/scriptProtocol.js
index 8e5814d..3225209 100644
--- a/components/scriptProtocol.js
+++ b/components/scriptProtocol.js
@@ -8,23 +8,13 @@ const ioService = Cc['@mozilla.org/network/io-service;1']
     .getService(Ci.nsIIOService);
 
 
-function ScriptChannel(aUri, aScript) {
+function DummyChannel(aUri, aScript) {
   // nsIRequest
   this.loadFlags = 0;
   this.loadGroup = null;
   this.name = aUri.spec;
-  this.status = 200;
-
+  this.status = 404;
   this.content = '';
-  if (aScript) {
-    this.content = GM_util.getScriptSource(aScript);
-  } else {
-    this.status = 404;
-  }
-
-  if (aUri.spec.match(/\?.*wrapped=1/)) {
-    this.content = GM_util.anonWrap(this.content);
-  }
 
   // nsIChannel
   this.contentCharset = 'utf-8';
@@ -35,23 +25,10 @@ function ScriptChannel(aUri, aScript) {
   this.owner = null;
   this.securityInfo = null;
   this.URI = aUri;
-
-  this.pipe = Cc['@mozilla.org/pipe;1'].createInstance(Ci.nsIPipe);
-  this.pipe.init(true, true, 0, 0, null);
-
-  var inputStreamChannel = Cc['@mozilla.org/network/input-stream-channel;1']
-      .createInstance(Ci.nsIInputStreamChannel);
-  inputStreamChannel.setURI(aUri);
-  inputStreamChannel.contentStream = this.pipe.inputStream;
-  this.channel = inputStreamChannel.QueryInterface(Ci.nsIChannel);
 }
 
 // nsIChannel
-ScriptChannel.prototype.asyncOpen = function(aListener, aContext) {
-  this.channel.asyncOpen(aListener, aContext);
-  this.pipe.outputStream.write(this.content, this.content.length);
-  this.pipe.outputStream.close();
-};
+DummyChannel.prototype.asyncOpen = function(aListener, aContext) { };
 
 
 function ScriptProtocol() {}
@@ -95,27 +72,26 @@ ScriptProtocol.prototype.newURI = function(aSpec, aCharset, aBaseUri) {
 // 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 (aUri.spec.match(/\.user\.js($|\?)/)) {
-    return new ScriptChannel(aUri, script);
-  } else if (script) {
+
+  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));
       }
     }
-  } else {
-    return new ScriptChannel(aUri, script);
   }
-  
-  // Default fall-through case, send a 404.  (By using a script channel
-  // w/out any script object.)(
-  return new ScriptChannel(aUri);
-};
 
+  // Default fall-through case, send a 404.
+  return new DummyChannel(aUri);
+};
 
 const components = [ScriptProtocol];
 if ("generateNSGetFactory" in XPCOMUtils) {

-- 
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