Question

How can I make an http passthrough pluggable protocol for IE work in Firefox?

Alternatively, how to develop one for Firefox? Any examples would be appreciated.

Thanks.

Was it helpful?

Solution 2

Write an XPCOM object that implements nsIObserver. Then create listener for http-on-modify-request and http-on-examine-response.

var myObj = new MyObserver(); //implements nsIObserver
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(myObj "http-on-modify-request",   false);
observerService.addObserver(myObj, "http-on-examine-response", false);

OTHER TIPS

On Firefox, if you would like to bypass a default behavior in a "pluggable" manner, you could write an NPAPI based plugin. Let's say that the documentation is thin on this subject... but to get you started, you could consult this.

With an NPAPI plugin, you have access to the whole OS and thus are free to expose any other resources to Firefox.

Write an XPCOM object that implements nsIProtocolHandler. For example, you can access local images from web pages:

const Cu = Components.utils;
const Ci = Components.interfaces;
const Cm = Components.manager;
const Cc = Components.classes;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");+
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
/***********************************************************
class definition
***********************************************************/
function sampleProtocol() {
     // If you only need to access your component from JavaScript, 
     //uncomment   the following line:
     this.wrappedJSObject = this;
}   
sampleProtocol.prototype = {
classDescription: "LocalFile sample protocol",
classID:          Components.ID("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"),
contractID:       "@mozilla.org/network/protocol;1?name=x-localfile",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
//interface nsIProtocolHandler
 allowPort :function(port, scheme)
 {
  if ((port == 80)&&(scheme == x-localfile)) {
   return true;
 }
 else
 {
     return false;
 }
},

newChannel: function(aURI)
{
    // Just example. Implementation must parse aURI
    var file = new FileUtils.File("D:\\temp\\getImage.jpg");
    var uri = NetUtil.ioService.newFileURI(file);
    var channel = NetUtil.ioService.newChannelFromURI(uri);
    return channel;
},
newURI(aSpec, aOriginCharset, aBaseURI)
{
    //URI looks like x-localfile://example.com/image1.jpg
    var uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
    uri.spec = aSpec;
    return uri;
},
scheme: "x-localfile",
defaultPort: 80,
protocolFlags: 76
};
var components = [sampleProtocol];
if ("generateNSGetFactory" in XPCOMUtils)
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);  //   Firefox 4.0 and higher
else
var NSGetModule = XPCOMUtils.generateNSGetModule(components);    // Firefox 3.x

Be carefull! This approach can create vulnerability

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top