因爲我在尋找一個解決方案,並且沒有可用的附加組件實際上與我的Firefox 31.0(Ubuntu)工作,所以我決定嘗試創建我自己的附加組件。
代碼如果你想存檔一個類似的目標或只是想知道它是如何工作的。
console.log("starting addon to disable content-disposition...");
//getting necessary objects
var {Cc, Ci} = require("chrome");
//creating the observer object which alters the Content-Disposition header to inline
var httpResponseObserver = {
//gets fired whenever a response is getting processed
observe: function(subject, topic, data) {
if (topic == "http-on-examine-response") {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
httpChannel.setResponseHeader("Content-Disposition", "inline", false);
}
},
//needed for this.observerServer.addObserver --> without addObserver will fail
get observerService() {
return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
},
//used to register with an observer
register: function() {
console.log("register with an observer to get response-events");
this.observerService.addObserver(this, "http-on-examine-response", false);
},
//used to unregister from the observer
unregister: function() {
console.log("unregister from observer");
this.observerService.removeObserver(this, "http-on-examine-response");
}
};
//gets called at enable or install of the add-on
exports.main = function(options, callbacks) {
console.log("content-dispostion main method got invoked");
//call register to make httpResponseObserver.observe get fired whenever a response gets processed
httpResponseObserver.register();
};
//gets called on disable or uninstall
exports.onUnload = function(reason) {
console.log("content-dispostion unloaded");
//unregister from observer
httpResponseObserver.unregister();
};
/*
//not needed!!! just test code for altering http-request header
var httpRequestObserver =
{
observe: function(subject, topic, data)
{
console.log("in observe...");
console.log("topic is: " + topic);
if (topic == "http-on-modify-request") {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
httpChannel.setRequestHeader("X-Hello", "World", false);
}
},
get observerService() {
return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
},
register: function()
{
this.observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function()
{
this.observerService.removeObserver(this, "http-on-modify-request");
}
};
httpRequestObserver.register();
*/
作爲替代方案,您可以讓我的xpi-File在Firefox中直接安裝插件。如果你想禁用「Content-Disposition」修改,只需關閉附加組件;-)。
http://www.file-upload.net/download-9374691/content-disposition_remover.xpi.html
什麼是錯與選擇 「打開方式:Acrobat Reader軟件」,卻得到了Acrobat Reader軟件窗口?這隻會將文件保存到臨時目錄,就像您在瀏覽器中打開它一樣。 – Borealid 2010-07-15 00:20:28
簡單地說,它只是使用太多的窗口。見下文。 – mctom987 2010-07-15 21:44:28
@Borealid我記得pdfplugin用於顯示文件,因爲它正在被提取(不必全部獲取/下載它,然後顯示它)。 – aularon 2010-09-09 10:04:49