Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read gzip header data stream #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions extension/chrome/content/firephp/FirePHP.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ const nsIWebProgressListener = (FB_NEW)?Ci.nsIWebProgressListener:CI("nsIWebProg
const nsISupportsWeakReference = (FB_NEW)?Ci.nsISupportsWeakReference:CI("nsISupportsWeakReference");
const nsISupports = (FB_NEW)?Ci.nsISupport:CI("nsISupports");

const ioService = CCSV("@mozilla.org/network/io-service;1", "nsIIOService");
//const ioService = CCSV("@mozilla.org/network/io-service;1", "nsIIOService");
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);

const observerService = CCSV("@mozilla.org/observer-service;1", "nsIObserverService");
//const observerService = CCSV("@mozilla.org/observer-service;1", "nsIObserverService");
const observerService = Cc["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);


const STATE_TRANSFERRING = nsIWebProgressListener.STATE_TRANSFERRING;
const STATE_IS_DOCUMENT = nsIWebProgressListener.STATE_IS_DOCUMENT;
Expand Down
16 changes: 15 additions & 1 deletion extension/chrome/content/firephp/RequestProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,15 @@ FirePHPProcessor.ProcessRequest = function(Wildfire,URL,Data) {
try {

if(Wildfire.hasMessages()) {



Wildfire.addListenerOnMessageIsReady('http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1',
function(message) {
var item = json_parse(message);
this.processMessage(item[0].Type, item[1], item[0]);
}, this);


var messages = Wildfire.getMessages('http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');

if(messages && messages.length>0) {
Expand All @@ -467,6 +475,12 @@ FirePHPProcessor.ProcessRequest = function(Wildfire,URL,Data) {
}


Wildfire.addListenerOnMessageIsReady('http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1',
function(message) {
var item = json_parse(messages[index]);
this.processMessage("dump", item, {"Label": "Dump"});
}, this);

messages = Wildfire.getMessages('http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');

if(messages && messages.length>0) {
Expand Down
14 changes: 13 additions & 1 deletion extension/chrome/content/firephp/Wildfire/Channel/HttpHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Wildfire.Channel.HttpHeaders = function() {

this.protocol_ids = new Array();

this.options = new Array();

this.messages = new Array();

this.messageReceived = function(Key, Value)
Expand All @@ -22,7 +24,13 @@ Wildfire.Channel.HttpHeaders = function() {

this.protocol_ids[id] = Value;

} else {
}
else if(Key.substr(this.headerPrefix.length,7)=='option-') {
var id = Key.substr(this.headerPrefix.length+7);

this.options[id] = Value == 'true' || Value == '1' || Value == 1;
}
else {

var parsed_key = this.parseKey(Key);

Expand Down Expand Up @@ -65,6 +73,10 @@ Wildfire.Channel.HttpHeaders = function() {
}
};

this.getOption = function(option) {
return(this.options[option]);
};

this.getProtocol = function(URI) {
if(!this.protocols[URI]) {
var protocol = this.initProtocol(URI);
Expand Down
81 changes: 79 additions & 2 deletions extension/chrome/content/firephp/Wildfire/Plugin/FirePHP.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Wildfire.Plugin.FirePHP = function() {
this.channel = new Wildfire.Channel.HttpHeaders;

this.messages = new Array();

this.callbackMessageIsReady = {};


this.init = function() {
Expand Down Expand Up @@ -77,13 +79,88 @@ Wildfire.Plugin.FirePHP = function() {

var messages = new Array();

var message_tmp;

for( var index in this.messages ) {
if(this.messages[index][1]==StructureURI) {
messages.push(this.messages[index][2]);
message_tmp = this.messages[index][2];
if(this.channel.getOption('gzip')) {
//use callback onMessageIsReady
this._gzip_decode(StructureURI, message_tmp);
} else {
messages.push(message_tmp);
}
}
}

return messages;
};

}
this.addListenerOnMessageIsReady = function(StructureURI, listener, context) {
this.callbackMessageIsReady[StructureURI] = [listener, context];
};

this._gzip_decode = function (StructureURI, s) { // Decompress an LZW-encoded string
var StreamListener = function(callback, context) {
this.data = [];
this.callbackOnReady = callback;
this.callbackContext = context;
};

StreamListener.prototype = {
onDataAvailable : function(request, context, inputStream, offset, count)
{
var scriptable = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
scriptable.init(inputStream);
this.data.push(scriptable.read(inputStream.available()));
},

onStartRequest : function(request, context)
{
this.data = [];
},

onStopRequest : function(request, context)
{
this.callbackOnReady.call(this.callbackContext, this.getData());
},

getData : function() {
return(this.data.join(''));
},

};

//listener for the converted data
var listener;
if(this.callbackMessageIsReady[StructureURI] && typeof(this.callbackMessageIsReady[StructureURI][0]) == 'function') {
listener = new StreamListener(this.callbackMessageIsReady[StructureURI][0], this.callbackMessageIsReady[StructureURI][1]);
} else {
listener = new StreamListener(function() {}, this);
}


var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);

var uri = ioService.newURI("data:gzip;base64," + s, null, null);

var chan = ioService.newChannelFromURI(uri);

var request = chan.QueryInterface(Components.interfaces.nsIRequest);

// Attempt to gunzip

var converterService = Components.classes["@mozilla.org/streamConverters;1"]
.getService(Components.interfaces.nsIStreamConverterService);

// Instantiate our gzip decompresser converter
var converterStreamListener = converterService.asyncConvertData("gzip",
"uncompressed", listener, null);


chan.asyncOpen(converterStreamListener, this);

};

}
2 changes: 1 addition & 1 deletion extension/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<em:id>[email protected]</em:id>
<em:name>FirePHP</em:name>
<em:version>0.6.2</em:version>
<em:version>0.7</em:version>
<em:type>2</em:type>

<em:creator>Christoph Dorn</em:creator>
Expand Down