[Pkg-mozext-commits] [requestpolicy] 250/280: [dev helper] add the "rpc" protocol

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:35 UTC 2015


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

taffit pushed a commit to branch master
in repository requestpolicy.

commit bdbae6405f43305df519d4614c5ecd4295db5fc2
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Apr 28 09:12:33 2015 +0200

    [dev helper] add the "rpc" protocol
    
    This commit adds a protocol handler named "rpc" to the
    Dev Helper extension. It will help testing requests that
    contain URIs without host, such as "rpc:foobar".
    
    See also #447.
---
 .../content/scheme-unknown-and-without-host-2.html | 11 +++
 tests/mozmill/extension/bootstrap.js               |  4 +
 tests/mozmill/extension/content/rpc-uri.jsm        | 91 ++++++++++++++++++++++
 3 files changed, 106 insertions(+)

diff --git a/tests/content/scheme-unknown-and-without-host-2.html b/tests/content/scheme-unknown-and-without-host-2.html
new file mode 100644
index 0000000..b749b73
--- /dev/null
+++ b/tests/content/scheme-unknown-and-without-host-2.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+<head>
+  <meta charset="utf-8" />
+</head>
+<body>
+
+<iframe src="rpc:iframe"></iframe>
+
+</body>
+</html>
diff --git a/tests/mozmill/extension/bootstrap.js b/tests/mozmill/extension/bootstrap.js
index 2d1270c..7e509f8 100644
--- a/tests/mozmill/extension/bootstrap.js
+++ b/tests/mozmill/extension/bootstrap.js
@@ -28,9 +28,13 @@ const Cu = Components.utils;
 function startup(data, reason) {
   Cu.import("chrome://rpc-dev-helper/content/console-observer.jsm");
   ConsoleObserver.startup();
+  Cu.import("chrome://rpc-dev-helper/content/rpc-uri.jsm");
+  CustomUri.startup();
 }
 
 function shutdown(data, reason) {
+  CustomUri.shutdown();
+  Cu.unload("chrome://rpc-dev-helper/content/rpc-uri.jsm");
   ConsoleObserver.shutdown();
   Cu.unload("chrome://rpc-dev-helper/content/console-observer.jsm");
 }
diff --git a/tests/mozmill/extension/content/rpc-uri.jsm b/tests/mozmill/extension/content/rpc-uri.jsm
new file mode 100644
index 0000000..8596eb0
--- /dev/null
+++ b/tests/mozmill/extension/content/rpc-uri.jsm
@@ -0,0 +1,91 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RPC Dev Helper - A helper add-on for RequestPolicy development.
+ * Copyright (c) 2015 Martin Kimmerle
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cu = Components.utils;
+
+var EXPORTED_SYMBOLS = ["CustomUri"];
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const destinationURI = "http://www.maindomain.test/destination.html";
+
+
+var CustomUri = (function () {
+  var self = {
+    classDescription: "RPC Protocol",
+    contractID: "@mozilla.org/network/protocol;1?name=rpc",
+    classID: Components.ID("{2d668f50-d8af-11e4-8830-0800200c9a66}"),
+    QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
+
+    scheme: "rpc",
+    protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
+                   Ci.nsIProtocolHandler.URI_NOAUTH |
+                   Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
+
+
+    newURI: function (aSpec, aOriginCharset, aBaseURI) {
+      var uri = Cc["@mozilla.org/network/simple-uri;1"]
+          .createInstance(Ci.nsIURI);
+      uri.spec = aSpec;
+      return uri;
+    },
+
+    newChannel: function (aURI) {
+      var path = aURI.path;
+      var uri = Services.io.newURI(destinationURI + "?" + path, null, null);
+      var channel = Services.io.newChannelFromURI(uri, null)
+          .QueryInterface(Ci.nsIHttpChannel);
+      return channel;
+    },
+
+    //
+    // nsIFactory interface implementation
+    //
+
+    createInstance: function (outer, iid) {
+      if (outer) {
+        throw Cr.NS_ERROR_NO_AGGREGATION;
+      }
+      return self.QueryInterface(iid);
+    },
+
+    startup: registerFactory,
+    shutdown: unregisterFactory
+  };
+
+
+  function registerFactory() {
+    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
+        .registerFactory(self.classID, self.classDescription,
+                         self.contractID, self);
+  }
+
+  function unregisterFactory() {
+    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
+        .unregisterFactory(self.classID, self);
+  }
+
+  return self;
+})();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list