1
我正在寫一個FireFox插件,它顯示來自我的服務器的網頁作爲控件和信息面板。這些面板是用常規URL編寫和工作的,但是當我嘗試通過自定義協議訪問它們時(每個XMLHttpRequest都會返回空白,就像我正在執行XSS一樣)。我知道數據正在通過 - 請求是有效的,並被服務器接受,並且tcpdump表示他們正在將其發送到我的機器。顯然,它與自定義協議實現有關,所以這裏是相關部分:在FireFox中的自定義協議中運行時,XMLHttpRequest中的空白responseText?
newURI: function(spec, charset, baseURI)
{
var uri = Components.classes[@"mozilla.org/network/simple-uri;1"].createInstance(nsIURI);
if (baseURI) {
spec = "myplugin:" + spec;
}
uri.spec = spec;
return(uri);
},
newChannel: function(aURI)
{
var incomingURI = aURI.spec;
var purpose = incomingURI.substring(incomingURI.indexOf(":") + 1, incomingURI.length);
var my_spec;
var my_uri;
var proto;
var api_scheme = "http";
var api_host = "myapi.myserver.com";
var api_token = "temp";
purpose = encodeURI(purpose);
if(purpose.match(/^\//)) // If it begins with a "/" (relative URL)
if(purpose.match(/\?/)) // It already contains a query string
my_spec = api_scheme + "://" + api_host + purpose + "&api_token=" + api_token;
else
my_spec = api_scheme + "://" + api_host + purpose + "?api_token=" + api_token;
else
my_spec = api_scheme + "://" + api_host + "/frontend/" + purpose + "?api_token=" + api_token;
my_uri = Components.classes[@mozilla.org/network/simple-uri;1].createInstance(nsIURI);
my_uri.spec = my_spec;
proto = Components.classes["@mozilla.org/network/protocol;1?name="+api_scheme].getService(nsIProtocolHandler);
return (proto.newChannel(my_uri));
}
};