我正在尝试开发一个firefox扩展,它将额外的HTTP头字段插入到传出的HTTP请求中(与我同时开发的apache扩展接口).
虽然我理解扩展的各个组件并理解Web上提供的基本教程,但我发现很难从"Hello World"教程扩展到开发一个完整的扩展.
我想要为我的目的调整的示例代码显示在设置HTTP请求标头的底部.
我想知道,在扩展层次结构中应放置此代码的位置以及如何调用/构造/激活此代码,它是否会在扩展初始化时自动运行?
提前致谢.
我正在尝试实现一个firefox扩展,它会过滤传入的HTTP响应并相应地处理它们.
我希望阻止包含特定标头的HTTP响应.阅读了一些MDC文章后,观察HTTP响应的最常见方式似乎是注册一个http-on-examine-response观察者.
我的问题是:使用这个观察者,是否可以阻止HTTP请求进一步处理(作为副产品,页面将继续等待响应)?或者我是否需要使用XPCOM的其他方面(如果是这样,请注意指向正确的方向)?
先谢谢你,
迈克
所以我一直在努力更新用于FF4和Gecko 2的旧扩展,但是我遇到了一些问题,我收到的错误是,classID缺失或组件不正确....
有没有其他人有类似的问题或知道如何解决这个问题?
function jsshellClient() {
this.classDescription = "sdConnector JavaScript Shell Service";
this.classID = Components.ID("{54f7f162-35d9-524d-9021-965a3ba86366}");
this.contractID = "@activestate.com/SDService?type=jsshell;1"
this._xpcom_categories = [{category: "sd-service", entry: "jsshell"}];
this.name = "jsshell";
this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("sdconnector.jsshell.");
this.enabled = this.prefs.getBoolPref("enabled");
this.port = this.prefs.getIntPref("port");
this.loopbackOnly = this.prefs.getBoolPref("loopbackOnly");
this.backlog = this.prefs.getIntPref("backlog");
}
jsshellClient.prototype = new session();
jsshellClient.prototype.constructor = jsshellClient;
Run Code Online (Sandbox Code Playgroud)
在原型上为此调用generateNSGetFactory时,它在FF4中的错误控制台中发出错误,抱怨classID.我很确定没有其他东西使用相同的GUID,所以我没有看到问题.
我有一个Firefox的bootstrapped扩展.现在我想实现nsIContentPolicy XPCOM组件.我写了一个组件模块代码.现在我想注册这个组件.我想注册组件的原因是我想将我的组件添加到 nsICategoryManager.addCategoryEntry"content-policy"类别.
var {Cc, Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
//console.error("Running interceptor");
function Interceptor()
}
Interceptor.prototype = {
classDescription: "DeferredTo HTTP requests Interceptor",
classID: "{B5B3D9A0-08FC-11E3-8253-5EF06188709B}",
contractID: "@deferredto.com/Interceptor;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy]),
shouldLoad : function dt_shouldLoad(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
console.log("dt_shouldLoad");
if (contentLocation.scheme != "http" && contentLocation.scheme != "https")
return Ci.nsIContentPolicy.ACCEPT;
let result = Ci.nsIContentPolicy.ACCEPT;
// we should check for TYPE_SUBDOCUMENT as well if we want frames.
if ((Ci.nsIContentPolicy.TYPE_DOCUMENT == aContentType) &&
SOME_REGULAR_EXPRESSION.test(aContentLocation.spec)) {
// do stuff here, possibly changing …Run Code Online (Sandbox Code Playgroud) 以前,我为mozilla版本3.6和XulRunner版本的1.9.2创建了XPCOM dll.
现在我尝试为mozilla最新版本(即4及更高版本)更新该xpcom dll.
所以我下载了Xul Runner以上的版本,但我找不到nsIGenericFactory.h.
如何使用我的xpcom dll为mozilla 4及以上版本.
实际上我使用以下示例来开发XPCOM DLL.
http://www.iosart.com/firefox/xpcom/
谢谢..
WRT构建Firefox附加组件.
是否可以通过一些XPCOM或javascript方法获取鼠标下的元素?(非js-ctypes请,因为这需要操作系统特异性)
当用户按下Ctrl+ Shift+ 时,我想检测鼠标下面的内容M.
现在mouseover,当用户按下这个热键时,我正在为文档添加一个监听器,所以当他移动它时我可以在鼠标下面获取该元素,而不是当他按下热键组合时正好在鼠标下面的元素.
是否有 API 调用允许启用/禁用 Firefox 附加组件?
在Mozilla中使用DOMParser方法从XML字符串解析DOM上是否支持document.getElementById方法?我正在创建一个mozilla扩展,它读取xmlfile并使用DOM Parser将xml转换为DOM元素,并尝试通过Id获取元素.方法getElementsByTagName有效,但不是getElementById.它总是返回null.
function (xmlString) {
var parser = new DOMParser();
var doc = parser.parseFromString(xmlString, "text/xml");
var aNodes = doc.getElementsByTagName("nodeTag");
for(var i=0; i<aNodes.length; ++i) {
var id = aNodes[i].getAttribute('id');
var resultNode = doc.getElementById(id);
alert(id);
alert(resultNode);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了上面的代码.alert(id)返回正确的id,其中alert(resultNode)每次都返回null.
我想编写一个XPCOM组件,它在网页中作为javascript对象公开.像Google Gears这样的东西就是我所追求的.也就是说,在安装Google Gears Firefox扩展程序后,任何想要使用它的网页都可以使用javascript对象"google.gears".我发现了很多关于XPCOM开发的mozilla文档,但没有任何关于将组件暴露给网页中运行的javascript的信息.XPCOM可以实现吗?我是否需要编写Firefox插件而不是扩展名?
一直试图让以下代码在firefox附加组件中工作:
var oMyForm = new FormData();
oMyForm.append("username", "Groucho");
oMyForm.append("accountnum", 123456); // number 123456 is immediately converted to string "123456"
// HTML file input user's choice...
oMyForm.append("userfile", fileInputElement.files[0]);
// JavaScript file-like object...
var oFileBody = '<a id="a"><b id="b">hey!</b></a>'; // the body of the new file...
var oBlob = new Blob([oFileBody], { type: "text/xml"});
oMyForm.append("webmasterfile", oBlob);
var oReq = new XMLHttpRequest();
oReq.open("POST", "http://foo.com/submitform.php");
oReq.send(oMyForm);
Run Code Online (Sandbox Code Playgroud)
所以我知道我必须使用XPCOM,但我找不到相同的东西.到目前为止我发现了这个:
var oMyForm = Cc["@mozilla.org/files/formdata;1"].createInstance(Ci.nsIDOMFormData);
oMyForm.append("username", "Groucho");
oMyForm.append("accountnum", 123456); // number 123456 is immediately converted to …Run Code Online (Sandbox Code Playgroud) xpcom ×10
firefox ×6
javascript ×6
mouseevent ×1
mozilla ×1
xml ×1
xml-parsing ×1
xul ×1
xulrunner ×1