Changes

Jump to: navigation, search

DOMWorkerThreads

2,529 bytes added, 22:19, 23 June 2008
no edit summary
interface nsIDOMWorkerThread;
interface nsIScriptError;
interface nsIURI;
[scriptable, function, uuid(e50ca05d-1381-4abb-a021-02eb720cfc38)]
interface nsIDOMWorkerThread : nsISupports
{
/**
* The nsIDOMWorkerMessageListener which handles messages for this worker.
*
* Developers should set this attribute to a proper object before another
* worker begins sending messages to ensure that all messages are received.
*
* The main script can set this property directly on the pool object.
*
* Worker scripts must set this attribute on the 'thisThread' global object
* defined in its scope. Setting the messageListener from the pool's script is
* not permitted.
*/
attribute nsIDOMWorkerMessageListener messageListener;
 
/**
* Sends a message to the worker.
* the script will run.
*/
nsIDOMWorkerThread createWorker(in DOMString aSourceScriptaScriptText);
/**
* which the script will run. See nsIURI.
*/
nsIDOMWorkerThread createWorkerFromURI(in nsIURI aSourceScriptDOMString aScriptURI);
};
 
[scriptable, function, uuid(fc8c2d9c-7b0e-467e-91f8-4715497d8ac6)]
interface nsIDOMWorkerHttpRequestCallback : nsISupports
{
void onChange();
};
 
[scriptable, uuid(b66e5bf1-3269-4e33-ab32-4786fec42377)]
interface nsIDOMWorkerHttpRequest : nsISupports
{
/**
* See nsIXMLHttpRequest.idl
*/
readonly attribute AString responseText;
 
/**
* See nsIXMLHttpRequest.idl
*/
readonly attribute unsigned long status;
 
/**
* See nsIXMLHttpRequest.idl
*/
readonly attribute AUTF8String statusText;
 
/**
* See nsIXMLHttpRequest.idl
*/
void abort();
 
/**
* See nsIXMLHttpRequest.idl
*/
string getAllResponseHeaders();
 
/**
* See nsIXMLHttpRequest.idl
*/
ACString getResponseHeader(in AUTF8String header);
 
/**
* See nsIXMLHttpRequest.idl
*/
void open(in AUTF8String method, in AUTF8String url);
 
/**
* See nsIXMLHttpRequest.idl
*/
void send(in nsIVariant body);
 
/**
* See nsIXMLHttpRequest.idl
*/
void sendAsBinary(in DOMString body);
 
/**
* See nsIXMLHttpRequest.idl
*/
void setRequestHeader(in AUTF8String header, in AUTF8String value);
 
/**
* See nsIXMLHttpRequest.idl
*/
readonly attribute long readyState;
 
/**
* See nsIXMLHttpRequest.idl
*/
void overrideMimeType(in AUTF8String mimetype);
 
/**
* See nsIXMLHttpRequest.idl
*/
attribute nsIDOMWorkerHttpRequestCallback onload;
 
/**
* See nsIXMLHttpRequest.idl
*/
attribute nsIDOMWorkerHttpRequestCallback onerror;
 
/**
* See nsIXMLHttpRequest.idl
*/
attribute nsIDOMWorkerHttpRequestCallback onprogress;
 
/**
* See nsIXMLHttpRequest.idl
*/
attribute nsIDOMWorkerHttpRequestCallback onuploadprogress;
 
/**
* See nsIXMLHttpRequest.idl
*/
attribute nsIDOMWorkerHttpRequestCallback onreadystatechange;
};
 
interface nsIDOMWorkerGlobalScope
{
/**
* The worker object that created this scope.
*/
readonly attribute nsIDOMWorkerThread thisThread;
 
/**
* Sends a message to the pool that created the worker.
*
* @param aMessage (in DOMString)
* The message to send. This may be a string or an object that can be
* serialized via JSON (see http://developer.mozilla.org/en/docs/JSON).
*/
void postMessageToPool(in DOMString aMessage);
 
/**
* The nsIDOMWorkerMessageListener which handles messages for this worker.
*
* Developers should set this attribute to a proper object before another
* worker begins sending messages to ensure that all messages are received.
*/
attribute nsIDOMWorkerMessageListener messageListener;
 
/**
* Loads the script indicated from the given URI.
*
* This function will block until the script file has loaded and has been
* executed.
*
* @param aURIString
* The URI to load.
*
* @throws Will throw an error if the URI cannot be loaded or executed.
*/
void loadScript(in DOMString aURIString);
 
/**
* Creates a new HttpRequest object.
*
* Use: 'var req = new HttpRequest();'
*/
/* nsIDOMWorkerHttpRequest HttpRequest(); */
 
/**
* See nsIDOMJSWindow.idl
*/
void dump(in DOMString str);
 
/**
* See nsIDOMJSWindow.idl
*/
long setTimeout(/* in JSObject aFunctionOrString, */
/* in JSObject aMilisecondDelay, */
/* [optional] in aArgsToFunctionOrString */);
 
/**
* See nsIDOMJSWindow.idl
*/
long setInterval(/* in JSObject aFunctionOrString, */
/* in JSObject aMilisecondDelay, */
/* [optional] in aArgsToFunctionOrString */);
 
/**
* See nsIDOMJSWindow.idl
*/
void clearTimeout(/* in JSObject aTimeoutId */);
 
/**
* See nsIDOMJSWindow.idl
*/
void clearInterval(/* in JSObject aIntervalId */);
};
 
</pre>
</code>
=== The worker's scope ===
The worker's scope is far more limited. A worker has access to the following objects: * See <code>thisThread</code>** This is the <code>nsIDOMWorkerThread</code> object representing the current worker. It can be passed as an argument to the <code>postMessage</code> method on another <code>nsIDOMWorkerThread</code> object or on the <code>postMessageToPool()</code> function. A worker has access to the following global functions: * <code>dump(in DOMString aString)</code>** The same as normal <code>dump()nsIDOMWorkerGlobalScope</code> above for DOM scopes. <code>aString</code> is output to the console. * <code>postMessageToPool(in DOMString aMessage)</code>** The same as calling <code>postMessage</code> on the <code>nsIDOMWorkerPool</code> object that created the workerdetails.
=== Sample usage ===
Confirm
137
edits

Navigation menu