Skip to content

Commit

Permalink
[dev helper] add the "rpc" protocol
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
myrdd committed Apr 28, 2015
1 parent a90e87f commit bdbae64
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/content/scheme-unknown-and-without-host-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>

<iframe src="rpc:iframe"></iframe>

</body>
</html>
4 changes: 4 additions & 0 deletions tests/mozmill/extension/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
91 changes: 91 additions & 0 deletions tests/mozmill/extension/content/rpc-uri.jsm
Original file line number Diff line number Diff line change
@@ -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;
})();

0 comments on commit bdbae64

Please sign in to comment.