2010-07-28 21:52:59 +00:00
|
|
|
/*
|
|
|
|
* Helper structures to track callbacks from image and channel loads.
|
|
|
|
*/
|
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
// START_REQUEST and STOP_REQUEST are used by ChannelListener, and
|
2012-10-12 01:58:24 +00:00
|
|
|
// stored in ChannelListener.requestStatus.
|
|
|
|
const START_REQUEST = 0x01;
|
2012-10-12 16:11:23 +00:00
|
|
|
const STOP_REQUEST = 0x02;
|
|
|
|
const DATA_AVAILABLE = 0x04;
|
|
|
|
|
|
|
|
// One bit per callback that imageListener below implements. Stored in
|
|
|
|
// ImageListener.state.
|
|
|
|
const SIZE_AVAILABLE = 0x01;
|
|
|
|
const FRAME_UPDATE = 0x02;
|
|
|
|
const FRAME_COMPLETE = 0x04;
|
|
|
|
const LOAD_COMPLETE = 0x08;
|
|
|
|
const DECODE_COMPLETE = 0x10;
|
2010-07-28 21:52:59 +00:00
|
|
|
|
2012-12-18 16:37:15 +00:00
|
|
|
// An implementation of imgIScriptedNotificationObserver with the ability to
|
|
|
|
// call specified functions on onStartRequest and onStopRequest.
|
2010-07-28 21:52:59 +00:00
|
|
|
function ImageListener(start_callback, stop_callback)
|
|
|
|
{
|
2012-10-12 16:11:23 +00:00
|
|
|
this.sizeAvailable = function onSizeAvailable(aRequest)
|
2010-07-28 21:52:59 +00:00
|
|
|
{
|
|
|
|
do_check_false(this.synchronous);
|
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
this.state |= SIZE_AVAILABLE;
|
2010-07-28 21:52:59 +00:00
|
|
|
|
|
|
|
if (this.start_callback)
|
|
|
|
this.start_callback(this, aRequest);
|
|
|
|
}
|
2012-10-12 16:11:23 +00:00
|
|
|
this.frameComplete = function onFrameComplete(aRequest)
|
2010-07-28 21:52:59 +00:00
|
|
|
{
|
|
|
|
do_check_false(this.synchronous);
|
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
this.state |= FRAME_COMPLETE;
|
2012-10-12 01:58:24 +00:00
|
|
|
}
|
2012-10-12 16:11:23 +00:00
|
|
|
this.decodeComplete = function onDecodeComplete(aRequest)
|
2012-10-12 01:58:24 +00:00
|
|
|
{
|
|
|
|
do_check_false(this.synchronous);
|
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
this.state |= DECODE_COMPLETE;
|
2012-10-12 01:58:24 +00:00
|
|
|
}
|
2012-10-12 16:11:23 +00:00
|
|
|
this.loadComplete = function onLoadcomplete(aRequest)
|
2012-10-12 01:58:24 +00:00
|
|
|
{
|
|
|
|
do_check_false(this.synchronous);
|
|
|
|
|
2013-01-18 21:47:18 +00:00
|
|
|
try {
|
|
|
|
aRequest.requestDecode();
|
|
|
|
} catch (e) {
|
|
|
|
do_print("requestDecode threw " + e);
|
|
|
|
}
|
2010-07-28 21:52:59 +00:00
|
|
|
|
2012-10-12 16:11:23 +00:00
|
|
|
this.state |= LOAD_COMPLETE;
|
2010-07-28 21:52:59 +00:00
|
|
|
|
|
|
|
if (this.stop_callback)
|
|
|
|
this.stop_callback(this, aRequest);
|
|
|
|
}
|
2012-10-12 16:11:23 +00:00
|
|
|
this.frameUpdate = function onFrameUpdate(aRequest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
this.isAnimated = function onIsAnimated()
|
2012-10-12 16:11:22 +00:00
|
|
|
{
|
|
|
|
}
|
2010-07-28 21:52:59 +00:00
|
|
|
|
|
|
|
// Initialize the synchronous flag to true to start. This must be set to
|
|
|
|
// false before exiting to the event loop!
|
|
|
|
this.synchronous = true;
|
|
|
|
|
|
|
|
// A function to call when onStartRequest is called.
|
|
|
|
this.start_callback = start_callback;
|
|
|
|
|
|
|
|
// A function to call when onStopRequest is called.
|
|
|
|
this.stop_callback = stop_callback;
|
|
|
|
|
|
|
|
// The image load/decode state.
|
|
|
|
// A bitfield that tracks which callbacks have been called. Takes the bits
|
|
|
|
// defined above.
|
|
|
|
this.state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function NS_FAILED(val)
|
|
|
|
{
|
|
|
|
return !!(val & 0x80000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChannelListener()
|
|
|
|
{
|
|
|
|
this.onStartRequest = function onStartRequest(aRequest, aContext)
|
|
|
|
{
|
|
|
|
if (this.outputListener)
|
|
|
|
this.outputListener.onStartRequest(aRequest, aContext);
|
|
|
|
|
|
|
|
this.requestStatus |= START_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onDataAvailable = function onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount)
|
|
|
|
{
|
|
|
|
if (this.outputListener)
|
|
|
|
this.outputListener.onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount);
|
2012-10-12 16:11:23 +00:00
|
|
|
|
|
|
|
this.requestStatus |= DATA_AVAILABLE;
|
2010-07-28 21:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.onStopRequest = function onStopRequest(aRequest, aContext, aStatusCode)
|
|
|
|
{
|
|
|
|
if (this.outputListener)
|
|
|
|
this.outputListener.onStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
|
|
|
|
// If we failed (or were canceled - failure is implied if canceled),
|
|
|
|
// there's no use tracking our state, since it's meaningless.
|
|
|
|
if (NS_FAILED(aStatusCode))
|
|
|
|
this.requestStatus = 0;
|
|
|
|
else
|
|
|
|
this.requestStatus |= STOP_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A listener to pass the notifications we get to.
|
|
|
|
this.outputListener = null;
|
|
|
|
|
|
|
|
// The request's status. A bitfield that holds one or both of START_REQUEST
|
|
|
|
// and STOP_REQUEST, according to which callbacks have been called on the
|
|
|
|
// associated request.
|
|
|
|
this.requestStatus = 0;
|
|
|
|
}
|