0
A
回答
0
编写实现nsIObserver的XPCOM对象。然后为http-on-modify-request和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);
0
在Firefox上,如果您想以“可插拔”的方式绕过默认行为,您可以编写NPAPI based plugin。假设文档在这个主题上很薄弱......但为了让你开始,你可以咨询this。
使用NPAPI插件,您可以访问整个操作系统,因此可以向Firefox公开任何其他资源。
0
编写实现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
要当心!这种方法可能造成漏洞
相关问题
- 1. Cookie如何在HTTP协议中传递?
- 2. 异步可插入协议
- 3. 关于HTTP协议
- 4. 在Java中使用异步可插入协议的HTTP请求
- 5. WebDav协议VS HTTP协议
- 6. firefox 5和协议文件://在http
- 7. 消息传递协议
- 8. 使用哪种消息传递协议?
- 9. 传递数据TextView使用协议
- 10. 使用协议/代理传递数组
- 11. 适用于即时消息传递的协议
- 12. 为什么基于TCP的HTTP协议?
- 13. uwsgi协议比http协议更快吗?
- 14. Firebase XMPP协议与HTTP协议
- 15. HTTP传输错误:java.net.MalformedURLException:无协议:REPLACE_WITH_ACTUAL_URL
- 16. mysql_connect()使用http协议
- 17. clojure,用于插入数据库项目的协议
- 18. HTTP和HTTPS协议
- 19. HTTP协议:仅HTML?
- 20. c#和HTTP协议
- 21. iOS + Android HTTP协议
- 22. HTTP协议工作
- 23. 使用异步插入协议
- 24. 从本地协议强制使用Javascript协议中的http协议
- 25. 用于流式传输音频/视频输入的协议
- 26. 异步可插入协议处理程序:转发到其他协议?
- 27. 使用Three20与HTTP协议以外的其他协议
- 28. LoadRunner Java over HTTP协议与WEB(http/html)协议
- 29. HTTP协议的本质
- 30. 困惑的HTTP协议