1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
3 // This component is intended to handle remote XUL requests
5 function oilsProtocol() {}
7 oilsProtocol.prototype = {
8 _system_principal: null,
10 protocolflags: Components.interfaces.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
11 Components.interfaces.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT,
12 newURI: function(aSpec, aOriginCharset, aBaseURI) {
13 var new_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIStandardURL);
14 new_url.init(1, -1, aSpec, aOriginCharset, aBaseURI);
15 return new_url.QueryInterface(Components.interfaces.nsIURI);
17 newChannel: function(aURI) {
18 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
20 switch(aURI.spec.replace(/^oils:\/\/([^\/]*)\/.*$/,'$1')) {
22 var data_cache = Components.classes["@open-ils.org/openils_data_cache;1"].getService().wrappedJSObject.data;
23 host = data_cache.server_unadorned;
26 // To allow elevated permissions on a specific host for selfcheck purposes change this from null.
27 // This is intended for installing an extension on Firefox specifically for selfcheck purposes
28 // NOTE: I honestly don't know how dangerous this might be, but I can't imagine it is worse than the previous "grant the domain permissions to do anything" model.
32 return null; // Bad input. Not really sure what to do.
35 if(!host) return null; // Not really sure what to do when we don't have the data we need. Unless manual entry is happening, though, shouldn't be an issue.
36 var chunk = aURI.spec.replace(/^oils:\/\/[^\/]*\//,'');
37 var channel = ios.newChannel("https://" + host + "/" + chunk, null, null).QueryInterface(Components.interfaces.nsIHttpChannel);
38 channel.setRequestHeader("OILS-Wrapper", "true", false);
39 if(this._system_principal == null) {
40 // We don't have the owner?
41 var chrome_service = Components.classesByID['{61ba33c0-3031-11d3-8cd0-0060b0fc14a3}'].getService().QueryInterface(Components.interfaces.nsIProtocolHandler);
42 var chrome_uri = chrome_service.newURI("chrome://open_ils_staff_client/content/main/main.xul", null, null);
43 var chrome_channel = chrome_service.newChannel(chrome_uri);
44 this._system_principal = chrome_channel.owner;
45 var chrome_request = chrome_channel.QueryInterface(Components.interfaces.nsIRequest);
46 chrome_request.cancel(0x804b0002);
48 if (this._system_principal) channel.owner = this._system_principal;
51 allowPort: function(aPort, aScheme) {
54 classDescription: "OILS Protocol Handler",
55 contractID: "@mozilla.org/network/protocol;1?name=oils",
56 classID: Components.ID('{51d35450-5e59-11e1-b86c-0800200c9a66}'),
57 QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]),
60 if (XPCOMUtils.generateNSGetFactory)
61 var NSGetFactory = XPCOMUtils.generateNSGetFactory([oilsProtocol]);
63 var NSGetModule = XPCOMUtils.generateNSGetModule([oilsProtocol]);