Bug 462525 - username truncation code is unnecessarily duplicated in nsLoginManagerP...
[wine-gecko.git] / dom / src / threads / nsDOMWorkerPool.h
blob18135a311eece994d9652f943d1f3e0e6fbf1f29
1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is worker threads.
17 * The Initial Developer of the Original Code is
18 * Mozilla Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Vladimir Vukicevic <vladimir@pobox.com> (Original Author)
24 * Ben Turner <bent.mozilla@gmail.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __NSDOMWORKERPOOL_H__
41 #define __NSDOMWORKERPOOL_H__
43 // Bases
44 #include "nsDOMWorkerBase.h"
45 #include "nsIClassInfo.h"
46 #include "nsIDOMThreads.h"
48 // Other includes
49 #include "jsapi.h"
50 #include "nsStringGlue.h"
51 #include "nsTPtrArray.h"
52 #include "prmon.h"
54 class nsDOMWorkerThread;
55 class nsIDocument;
56 class nsIScriptContext;
57 class nsIScriptError;
58 class nsIScriptGlobalObject;
60 /**
61 * The pool is almost always touched only on the main thread.
63 class nsDOMWorkerPool : public nsDOMWorkerBase,
64 public nsIDOMWorkerPool,
65 public nsIClassInfo
67 friend class nsDOMThreadService;
68 friend class nsDOMWorkerFunctions;
69 friend class nsDOMWorkerPoolWeakRef;
70 friend class nsDOMWorkerScriptLoader;
71 friend class nsDOMWorkerStreamObserver;
72 friend class nsDOMWorkerThread;
73 friend class nsReportErrorRunnable;
74 friend JSBool DOMWorkerOperationCallback(JSContext* aCx);
76 public:
77 NS_DECL_ISUPPORTS
78 NS_DECL_NSIDOMWORKERPOOL
79 NS_DECL_NSICLASSINFO
81 nsDOMWorkerPool(nsIDocument* aDocument);
83 // For nsDOMWorkerBase
84 virtual nsDOMWorkerPool* Pool() {
85 return this;
88 nsIDocument* ParentDocument();
89 nsIScriptContext* ScriptContext();
91 private:
92 virtual ~nsDOMWorkerPool();
94 nsresult Init();
96 // For nsDOMWorkerBase
97 virtual nsresult HandleMessage(const nsAString& aMessage,
98 nsDOMWorkerBase* aSourceThread);
100 // For nsDOMWorkerBase
101 virtual nsresult DispatchMessage(nsIRunnable* aRunnable);
103 void HandleError(nsIScriptError* aError,
104 nsDOMWorkerThread* aSource);
106 void NoteDyingWorker(nsDOMWorkerThread* aWorker);
108 void CancelWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject);
109 void SuspendWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject);
110 void ResumeWorkersForGlobal(nsIScriptGlobalObject* aGlobalObject);
112 PRMonitor* Monitor() {
113 return mMonitor;
116 // Weak reference to the window that created and owns this pool.
117 nsISupports* mParentGlobal;
119 // Weak reference to the document that created this pool.
120 nsIDocument* mParentDocument;
122 // Weak array of workers. The idea is that workers can be garbage collected
123 // independently of the owning pool and other workers.
124 nsTPtrArray<nsDOMWorkerThread> mWorkers;
126 // An error handler function, may be null.
127 nsCOMPtr<nsIDOMWorkerErrorListener> mErrorListener;
129 // Monitor for suspending and resuming workers.
130 PRMonitor* mMonitor;
133 #endif /* __NSDOMWORKERPOOL_H__ */