用于Firefox的Http直通可插拔协议

用于Firefox的Http直通可插拔协议,http,firefox,protocols,pluggableprotocol,Http,Firefox,Protocols,Pluggableprotocol,如何使IE的http直通可插拔协议在Firefox中工作 或者,如何为Firefox开发一个?任何例子都将不胜感激 谢谢。在Firefox上,如果您想以“可插入”的方式绕过默认行为,您可以编写一个。比如说,关于这个主题的文档很少。。。但是为了让你开始,你可以咨询 使用NPAPI插件,您可以访问整个操作系统,因此可以自由地向Firefox公开任何其他资源。编写一个实现nsIObserver的XPCOM对象。然后在修改请求时为http创建侦听器,在检查响应时为http创建侦听器 var myObj

如何使IE的http直通可插拔协议在Firefox中工作

或者,如何为Firefox开发一个?任何例子都将不胜感激


谢谢。

在Firefox上,如果您想以“可插入”的方式绕过默认行为,您可以编写一个。比如说,关于这个主题的文档很少。。。但是为了让你开始,你可以咨询


使用NPAPI插件,您可以访问整个操作系统,因此可以自由地向Firefox公开任何其他资源。

编写一个实现nsIObserver的XPCOM对象。然后在修改请求时为http创建侦听器,在检查响应时为http创建侦听器

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

编写一个实现nsIProtocolHandler的XPCOM对象。例如,您可以从网页访问本地图像:

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
小心点!这种方法会造成漏洞