/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Web Workers.
 *
 * The Initial Developer of the Original Code is
 *   Mozilla Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2008
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Ben Turner <bent.mozilla@gmail.com> (Original Author)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

/**
 * From http://www.whatwg.org/specs/web-workers/current-work
 */

#include "nsIDOMEvent.idl"
#include "nsIDOMEventTarget.idl"

interface nsIDOMEventListener;

[scriptable, uuid(ab3725b8-3fca-40cc-a42c-92fb154ef01d)]
interface nsIWorkerMessagePort : nsISupports
{
  void postMessage(/* in JSObject aMessage */);
};

[scriptable, uuid(508f2d49-e9a0-4fe8-bd33-321820173b4a)]
interface nsIWorkerMessageEvent : nsIDOMEvent
{
  readonly attribute DOMString data;
  readonly attribute DOMString origin;

  readonly attribute nsISupports source;

  void initMessageEvent(in DOMString aTypeArg,
                        in boolean aCanBubbleArg,
                        in boolean aCancelableArg,
                        in DOMString aDataArg,
                        in DOMString aOriginArg,
                        in nsISupports aSourceArg);
};

[scriptable, uuid(73d82c1d-05de-49c9-a23b-7121ff09a67a)]
interface nsIWorkerErrorEvent : nsIDOMEvent
{
  readonly attribute DOMString message;
  readonly attribute DOMString filename;

  readonly attribute unsigned long lineno;

  void initErrorEvent(in DOMString aTypeArg,
                      in boolean aCanBubbleArg,
                      in boolean aCancelableArg,
                      in DOMString aMessageArg,
                      in DOMString aFilenameArg,
                      in unsigned long aLinenoArg);
};

[scriptable, uuid(17a005c3-4f2f-4bb6-b169-c181fa6873de)]
interface nsIWorkerLocation : nsISupports
{
  readonly attribute AUTF8String href;
  readonly attribute AUTF8String protocol;
  readonly attribute AUTF8String host;
  readonly attribute AUTF8String hostname;
  readonly attribute AUTF8String port;
  readonly attribute AUTF8String pathname;
  readonly attribute AUTF8String search;
  readonly attribute AUTF8String hash;

  AUTF8String toString();
};

[scriptable, uuid(74fb665a-e477-4ce2-b3c6-c58b1b28b6c3)]
interface nsIWorkerNavigator : nsISupports
{
  readonly attribute DOMString appName;
  readonly attribute DOMString appVersion;
  readonly attribute DOMString platform;
  readonly attribute DOMString userAgent;
};

[scriptable, uuid(c111e7d3-8044-4458-aa7b-637696ffb841)]
interface nsIWorkerGlobalScope : nsISupports
{
  readonly attribute nsIWorkerGlobalScope self;
  readonly attribute nsIWorkerNavigator navigator;
  readonly attribute nsIWorkerLocation location;

  attribute nsIDOMEventListener onerror;
};

[scriptable, uuid(5c55ea4b-e4ac-4ceb-bfeb-46bd5e521b8a)]
interface nsIWorkerScope : nsIWorkerGlobalScope
{
  void postMessage(/* in JSObject aMessage */);

  void close();

  attribute nsIDOMEventListener onmessage;
  attribute nsIDOMEventListener onclose;
};

[scriptable, uuid(b90b7561-b5e2-4545-84b0-280dbaaa94ea)]
interface nsIAbstractWorker : nsIDOMEventTarget
{
  attribute nsIDOMEventListener onerror;
};

[scriptable, uuid(daf945c3-8d29-4724-8939-dd383f7d27a7)]
interface nsIWorker : nsIAbstractWorker
{
  void postMessage(/* in JSObject aMessage */);

  attribute nsIDOMEventListener onmessage;

  void terminate();
};

[scriptable, uuid(cfc4bb32-ca83-4d58-9b6f-66f8054a333a)]
interface nsIWorkerFactory : nsISupports
{
    nsIWorker newChromeWorker(/* in DOMString aScriptURL */);
};

%{ C++
#define NS_WORKERFACTORY_CONTRACTID \
"@mozilla.org/threads/workerfactory;1"
%}
