1 : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is Web Workers.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2011
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Ben Turner <bent.mozilla@gmail.com> (Original Author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef mozilla_dom_workers_workerprivate_h__
40 : #define mozilla_dom_workers_workerprivate_h__
41 :
42 : #include "Workers.h"
43 :
44 : #include "nsIRunnable.h"
45 : #include "nsIThread.h"
46 : #include "nsIThreadInternal.h"
47 :
48 : #include "jsapi.h"
49 : #include "mozilla/CondVar.h"
50 : #include "mozilla/Mutex.h"
51 : #include "mozilla/TimeStamp.h"
52 : #include "nsAutoPtr.h"
53 : #include "nsCOMPtr.h"
54 : #include "nsEventQueue.h"
55 : #include "nsStringGlue.h"
56 : #include "nsTArray.h"
57 : #include "nsTPriorityQueue.h"
58 :
59 : #include "EventTarget.h"
60 : #include "Queue.h"
61 : #include "WorkerFeature.h"
62 :
63 : class JSAutoStructuredCloneBuffer;
64 : class nsIDocument;
65 : class nsIPrincipal;
66 : class nsIMemoryMultiReporter;
67 : class nsIScriptContext;
68 : class nsIURI;
69 : class nsPIDOMWindow;
70 : class nsITimer;
71 :
72 : BEGIN_WORKERS_NAMESPACE
73 :
74 : class WorkerPrivate;
75 :
76 : class WorkerRunnable : public nsIRunnable
77 : {
78 : public:
79 : enum Target { ParentThread, WorkerThread };
80 : enum BusyBehavior { ModifyBusyCount, UnchangedBusyCount };
81 : enum ClearingBehavior { SkipWhenClearing, RunWhenClearing };
82 :
83 : protected:
84 : WorkerPrivate* mWorkerPrivate;
85 : Target mTarget;
86 : BusyBehavior mBusyBehavior;
87 : ClearingBehavior mClearingBehavior;
88 :
89 : public:
90 : NS_DECL_ISUPPORTS
91 :
92 : bool
93 : Dispatch(JSContext* aCx);
94 :
95 : static bool
96 : DispatchToMainThread(nsIRunnable*);
97 :
98 : bool
99 0 : WantsToRunDuringClear()
100 : {
101 0 : return mClearingBehavior == RunWhenClearing;
102 : }
103 :
104 : protected:
105 : WorkerRunnable(WorkerPrivate* aWorkerPrivate, Target aTarget,
106 : BusyBehavior aBusyBehavior,
107 : ClearingBehavior aClearingBehavior)
108 : #ifdef DEBUG
109 : ;
110 : #else
111 : : mWorkerPrivate(aWorkerPrivate), mTarget(aTarget),
112 : mBusyBehavior(aBusyBehavior), mClearingBehavior(aClearingBehavior)
113 : { }
114 : #endif
115 :
116 0 : virtual ~WorkerRunnable()
117 0 : { }
118 :
119 : virtual bool
120 : PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
121 :
122 : virtual void
123 : PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
124 : bool aDispatchResult);
125 :
126 : virtual bool
127 : DispatchInternal();
128 :
129 : virtual bool
130 : WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) = 0;
131 :
132 : virtual void
133 : PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult);
134 :
135 : private:
136 : NS_DECL_NSIRUNNABLE
137 : };
138 :
139 : class WorkerSyncRunnable : public WorkerRunnable
140 : {
141 : protected:
142 : PRUint32 mSyncQueueKey;
143 : bool mBypassSyncQueue;
144 :
145 : protected:
146 : friend class WorkerPrivate;
147 :
148 0 : WorkerSyncRunnable(WorkerPrivate* aWorkerPrivate, PRUint32 aSyncQueueKey,
149 : bool aBypassSyncQueue = false,
150 : ClearingBehavior aClearingBehavior = SkipWhenClearing)
151 : : WorkerRunnable(aWorkerPrivate, WorkerThread, UnchangedBusyCount,
152 : aClearingBehavior),
153 0 : mSyncQueueKey(aSyncQueueKey), mBypassSyncQueue(aBypassSyncQueue)
154 0 : { }
155 :
156 0 : virtual ~WorkerSyncRunnable()
157 0 : { }
158 :
159 : virtual bool
160 : DispatchInternal();
161 : };
162 :
163 : class WorkerControlRunnable : public WorkerRunnable
164 : {
165 : protected:
166 0 : WorkerControlRunnable(WorkerPrivate* aWorkerPrivate, Target aTarget,
167 : BusyBehavior aBusyBehavior)
168 0 : : WorkerRunnable(aWorkerPrivate, aTarget, aBusyBehavior, SkipWhenClearing)
169 0 : { }
170 :
171 0 : virtual ~WorkerControlRunnable()
172 0 : { }
173 :
174 : virtual bool
175 : DispatchInternal();
176 : };
177 :
178 : template <class Derived>
179 : class WorkerPrivateParent : public events::EventTarget
180 : {
181 : public:
182 : struct LocationInfo
183 0 : {
184 : nsCString mHref;
185 : nsCString mProtocol;
186 : nsCString mHost;
187 : nsCString mHostname;
188 : nsCString mPort;
189 : nsCString mPathname;
190 : nsCString mSearch;
191 : nsCString mHash;
192 : };
193 :
194 : protected:
195 : mozilla::Mutex mMutex;
196 : mozilla::CondVar mCondVar;
197 :
198 : private:
199 : JSObject* mJSObject;
200 : WorkerPrivate* mParent;
201 : JSContext* mParentJSContext;
202 : nsString mScriptURL;
203 : nsCString mDomain;
204 : LocationInfo mLocationInfo;
205 :
206 : // Main-thread things.
207 : nsCOMPtr<nsPIDOMWindow> mWindow;
208 : nsCOMPtr<nsIScriptContext> mScriptContext;
209 : nsCOMPtr<nsIURI> mBaseURI;
210 : nsCOMPtr<nsIURI> mScriptURI;
211 : nsCOMPtr<nsIPrincipal> mPrincipal;
212 : nsCOMPtr<nsIDocument> mDocument;
213 :
214 : // Only used for top level workers.
215 : nsTArray<nsRefPtr<WorkerRunnable> > mQueuedRunnables;
216 :
217 : PRUint64 mBusyCount;
218 : Status mParentStatus;
219 : PRUint32 mJSContextOptions;
220 : PRUint32 mJSRuntimeHeapSize;
221 : PRUint8 mGCZeal;
222 : bool mJSObjectRooted;
223 : bool mParentSuspended;
224 : bool mIsChromeWorker;
225 : bool mPrincipalIsSystem;
226 :
227 : protected:
228 0 : WorkerPrivateParent(JSContext* aCx, JSObject* aObject, WorkerPrivate* aParent,
229 : JSContext* aParentJSContext, const nsAString& aScriptURL,
230 : bool aIsChromeWorker, const nsACString& aDomain,
231 : nsCOMPtr<nsPIDOMWindow>& aWindow,
232 : nsCOMPtr<nsIScriptContext>& aScriptContext,
233 : nsCOMPtr<nsIURI>& aBaseURI,
234 : nsCOMPtr<nsIPrincipal>& aPrincipal,
235 : nsCOMPtr<nsIDocument>& aDocument);
236 :
237 0 : ~WorkerPrivateParent();
238 :
239 : private:
240 : Derived*
241 0 : ParentAsWorkerPrivate() const
242 : {
243 0 : return static_cast<Derived*>(const_cast<WorkerPrivateParent*>(this));
244 : }
245 :
246 : bool
247 0 : NotifyPrivate(JSContext* aCx, Status aStatus, bool aFromJSFinalizer);
248 :
249 : bool
250 0 : TerminatePrivate(JSContext* aCx, bool aFromJSFinalizer)
251 : {
252 0 : return NotifyPrivate(aCx, Terminating, aFromJSFinalizer);
253 : }
254 :
255 : public:
256 : // May be called on any thread...
257 : bool
258 0 : Start();
259 :
260 : // Called on the parent thread.
261 : bool
262 0 : Notify(JSContext* aCx, Status aStatus)
263 : {
264 0 : return NotifyPrivate(aCx, aStatus, false);
265 : }
266 :
267 : bool
268 0 : Cancel(JSContext* aCx)
269 : {
270 0 : return Notify(aCx, Canceling);
271 : }
272 :
273 : bool
274 0 : Kill(JSContext* aCx)
275 : {
276 0 : return Notify(aCx, Killing);
277 : }
278 :
279 : bool
280 0 : Suspend(JSContext* aCx);
281 :
282 : bool
283 0 : Resume(JSContext* aCx);
284 :
285 : void
286 0 : TraceInstance(JSTracer* aTrc)
287 : {
288 : // This should only happen on the parent thread but we can't assert that
289 : // because it can also happen on the cycle collector thread when this is a
290 : // top-level worker.
291 0 : events::EventTarget::TraceInstance(aTrc);
292 0 : }
293 :
294 : void
295 0 : FinalizeInstance(JSContext* aCx, bool aFromJSFinalizer);
296 :
297 : bool
298 0 : Terminate(JSContext* aCx)
299 : {
300 0 : return TerminatePrivate(aCx, false);
301 : }
302 :
303 : bool
304 0 : Close(JSContext* aCx);
305 :
306 : bool
307 0 : ModifyBusyCount(JSContext* aCx, bool aIncrease);
308 :
309 : bool
310 0 : RootJSObject(JSContext* aCx, bool aRoot);
311 :
312 : void
313 0 : ForgetMainThreadObjects(nsTArray<nsCOMPtr<nsISupports> >& aDoomed);
314 :
315 : bool
316 0 : PostMessage(JSContext* aCx, jsval aMessage);
317 :
318 : PRUint64
319 0 : GetInnerWindowId();
320 :
321 : void
322 0 : UpdateJSContextOptions(JSContext* aCx, PRUint32 aOptions);
323 :
324 : void
325 0 : UpdateJSRuntimeHeapSize(JSContext* aCx, PRUint32 aJSRuntimeHeapSize);
326 :
327 : #ifdef JS_GC_ZEAL
328 : void
329 0 : UpdateGCZeal(JSContext* aCx, PRUint8 aGCZeal);
330 : #endif
331 :
332 : void
333 0 : GarbageCollect(JSContext* aCx, bool aShrinking);
334 :
335 : using events::EventTarget::GetEventListenerOnEventTarget;
336 : using events::EventTarget::SetEventListenerOnEventTarget;
337 :
338 : void
339 0 : QueueRunnable(WorkerRunnable* aRunnable)
340 : {
341 0 : AssertIsOnMainThread();
342 0 : mQueuedRunnables.AppendElement(aRunnable);
343 0 : }
344 :
345 : WorkerPrivate*
346 0 : GetParent() const
347 : {
348 0 : return mParent;
349 : }
350 :
351 : bool
352 0 : IsSuspended() const
353 : {
354 0 : AssertIsOnParentThread();
355 0 : return mParentSuspended;
356 : }
357 :
358 : Status
359 0 : ParentStatus() const
360 : {
361 0 : mMutex.AssertCurrentThreadOwns();
362 0 : return mParentStatus;
363 : }
364 :
365 : JSContext*
366 0 : ParentJSContext() const;
367 :
368 : nsIScriptContext*
369 0 : GetScriptContext() const
370 : {
371 0 : AssertIsOnMainThread();
372 0 : return mScriptContext;
373 : }
374 :
375 : JSObject*
376 0 : GetJSObject() const
377 : {
378 0 : return mJSObject;
379 : }
380 :
381 : const nsString&
382 0 : ScriptURL() const
383 : {
384 0 : return mScriptURL;
385 : }
386 :
387 : const nsCString&
388 0 : Domain() const
389 : {
390 0 : return mDomain;
391 : }
392 :
393 : nsIURI*
394 0 : GetBaseURI() const
395 : {
396 0 : AssertIsOnMainThread();
397 0 : return mBaseURI;
398 : }
399 :
400 : void
401 0 : SetBaseURI(nsIURI* aBaseURI);
402 :
403 : nsIURI*
404 0 : GetScriptURI() const
405 : {
406 0 : AssertIsOnMainThread();
407 0 : return mScriptURI;
408 : }
409 :
410 : void
411 0 : SetScriptURI(nsIURI* aScriptURI)
412 : {
413 0 : AssertIsOnMainThread();
414 0 : mScriptURI = aScriptURI;
415 0 : }
416 :
417 : nsIPrincipal*
418 0 : GetPrincipal() const
419 : {
420 0 : AssertIsOnMainThread();
421 0 : return mPrincipal;
422 : }
423 :
424 : void
425 0 : SetPrincipal(nsIPrincipal* aPrincipal);
426 :
427 : bool
428 0 : UsesSystemPrincipal() const
429 : {
430 0 : return mPrincipalIsSystem;
431 : }
432 :
433 : nsIDocument*
434 0 : GetDocument() const
435 : {
436 0 : AssertIsOnMainThread();
437 0 : return mDocument;
438 : }
439 :
440 : void
441 0 : SetDocument(nsIDocument* aDocument)
442 : {
443 0 : AssertIsOnMainThread();
444 0 : mDocument = aDocument;
445 0 : }
446 :
447 : nsPIDOMWindow*
448 0 : GetWindow()
449 : {
450 0 : AssertIsOnMainThread();
451 0 : return mWindow;
452 : }
453 :
454 : LocationInfo&
455 0 : GetLocationInfo()
456 : {
457 0 : return mLocationInfo;
458 : }
459 :
460 : PRUint32
461 0 : GetJSContextOptions() const
462 : {
463 0 : return mJSContextOptions;
464 : }
465 :
466 : PRUint32
467 0 : GetJSRuntimeHeapSize() const
468 : {
469 0 : return mJSRuntimeHeapSize;
470 : }
471 :
472 : #ifdef JS_GC_ZEAL
473 : PRUint8
474 0 : GetGCZeal() const
475 : {
476 0 : return mGCZeal;
477 : }
478 : #endif
479 :
480 : bool
481 0 : IsChromeWorker() const
482 : {
483 0 : return mIsChromeWorker;
484 : }
485 :
486 : #ifdef DEBUG
487 : void
488 0 : AssertIsOnParentThread() const;
489 :
490 : void
491 0 : AssertInnerWindowIsCorrect() const;
492 : #else
493 : void
494 : AssertIsOnParentThread() const
495 : { }
496 :
497 : void
498 : AssertInnerWindowIsCorrect() const
499 : { }
500 : #endif
501 : };
502 :
503 : class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
504 : {
505 : friend class WorkerPrivateParent<WorkerPrivate>;
506 : typedef WorkerPrivateParent<WorkerPrivate> ParentType;
507 :
508 : struct TimeoutInfo;
509 :
510 : typedef Queue<WorkerRunnable*, 50> EventQueue;
511 : EventQueue mQueue;
512 : EventQueue mControlQueue;
513 :
514 : struct SyncQueue
515 : {
516 : Queue<WorkerRunnable*, 10> mQueue;
517 : bool mComplete;
518 : bool mResult;
519 :
520 0 : SyncQueue()
521 0 : : mComplete(false), mResult(false)
522 0 : { }
523 :
524 0 : ~SyncQueue()
525 0 : {
526 : WorkerRunnable* event;
527 0 : while (mQueue.Pop(event)) {
528 0 : event->Release();
529 : }
530 0 : }
531 : };
532 :
533 : nsTArray<nsAutoPtr<SyncQueue> > mSyncQueues;
534 :
535 : // Touched on multiple threads, protected with mMutex.
536 : JSContext* mJSContext;
537 : nsRefPtr<WorkerCrossThreadDispatcher> mCrossThreadDispatcher;
538 :
539 : // Things touched on worker thread only.
540 : nsTArray<ParentType*> mChildWorkers;
541 : nsTArray<WorkerFeature*> mFeatures;
542 : nsTArray<nsAutoPtr<TimeoutInfo> > mTimeouts;
543 :
544 : nsCOMPtr<nsITimer> mTimer;
545 : nsCOMPtr<nsIMemoryMultiReporter> mMemoryReporter;
546 :
547 : mozilla::TimeStamp mKillTime;
548 : PRUint32 mErrorHandlerRecursionCount;
549 : PRUint32 mNextTimeoutId;
550 : Status mStatus;
551 : bool mSuspended;
552 : bool mTimerRunning;
553 : bool mRunningExpiredTimeouts;
554 : bool mCloseHandlerStarted;
555 : bool mCloseHandlerFinished;
556 : bool mMemoryReporterRunning;
557 : bool mMemoryReporterDisabled;
558 :
559 : #ifdef DEBUG
560 : nsCOMPtr<nsIThread> mThread;
561 : #endif
562 :
563 : public:
564 : ~WorkerPrivate();
565 :
566 : static WorkerPrivate*
567 : Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
568 : JSString* aScriptURL, bool aIsChromeWorker);
569 :
570 : void
571 : DoRunLoop(JSContext* aCx);
572 :
573 : bool
574 : OperationCallback(JSContext* aCx);
575 :
576 : bool
577 0 : Dispatch(WorkerRunnable* aEvent)
578 : {
579 0 : return Dispatch(aEvent, &mQueue);
580 : }
581 :
582 : bool
583 0 : Dispatch(WorkerSyncRunnable* aEvent)
584 : {
585 0 : if (aEvent->mBypassSyncQueue) {
586 0 : return Dispatch(aEvent, &mQueue);
587 : }
588 :
589 0 : return DispatchToSyncQueue(aEvent);
590 : }
591 :
592 : bool
593 0 : Dispatch(WorkerControlRunnable* aEvent)
594 : {
595 0 : return Dispatch(aEvent, &mControlQueue);
596 : }
597 :
598 : bool
599 0 : CloseInternal(JSContext* aCx)
600 : {
601 0 : AssertIsOnWorkerThread();
602 0 : return NotifyInternal(aCx, Closing);
603 : }
604 :
605 : bool
606 : SuspendInternal(JSContext* aCx);
607 :
608 : bool
609 : ResumeInternal(JSContext* aCx);
610 :
611 : void
612 : TraceInternal(JSTracer* aTrc);
613 :
614 : bool
615 : ModifyBusyCountFromWorker(JSContext* aCx, bool aIncrease);
616 :
617 : bool
618 : AddChildWorker(JSContext* aCx, ParentType* aChildWorker);
619 :
620 : void
621 : RemoveChildWorker(JSContext* aCx, ParentType* aChildWorker);
622 :
623 : bool
624 : AddFeature(JSContext* aCx, WorkerFeature* aFeature);
625 :
626 : void
627 : RemoveFeature(JSContext* aCx, WorkerFeature* aFeature);
628 :
629 : void
630 : NotifyFeatures(JSContext* aCx, Status aStatus);
631 :
632 : bool
633 0 : HasActiveFeatures()
634 : {
635 0 : return !(mChildWorkers.IsEmpty() && mTimeouts.IsEmpty() &&
636 0 : mFeatures.IsEmpty());
637 : }
638 :
639 : PRUint32
640 : CreateNewSyncLoop();
641 :
642 : bool
643 : RunSyncLoop(JSContext* aCx, PRUint32 aSyncLoopKey);
644 :
645 : void
646 : StopSyncLoop(PRUint32 aSyncLoopKey, bool aSyncResult);
647 :
648 : bool
649 : PostMessageToParent(JSContext* aCx, jsval aMessage);
650 :
651 : bool
652 : NotifyInternal(JSContext* aCx, Status aStatus);
653 :
654 : void
655 : ReportError(JSContext* aCx, const char* aMessage, JSErrorReport* aReport);
656 :
657 : bool
658 : SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp, bool aIsInterval);
659 :
660 : bool
661 : ClearTimeout(JSContext* aCx, uint32 aId);
662 :
663 : bool
664 : RunExpiredTimeouts(JSContext* aCx);
665 :
666 : bool
667 : RescheduleTimeoutTimer(JSContext* aCx);
668 :
669 : void
670 0 : CloseHandlerStarted()
671 : {
672 0 : AssertIsOnWorkerThread();
673 0 : mCloseHandlerStarted = true;
674 0 : }
675 :
676 : void
677 0 : CloseHandlerFinished()
678 : {
679 0 : AssertIsOnWorkerThread();
680 0 : mCloseHandlerFinished = true;
681 0 : }
682 :
683 : void
684 : UpdateJSContextOptionsInternal(JSContext* aCx, PRUint32 aOptions);
685 :
686 : void
687 : UpdateJSRuntimeHeapSizeInternal(JSContext* aCx, PRUint32 aJSRuntimeHeapSize);
688 :
689 : void
690 : ScheduleDeletion(bool aWasPending);
691 :
692 : bool
693 : BlockAndCollectRuntimeStats(bool isQuick, void* aData, bool* aDisabled);
694 :
695 : bool
696 : DisableMemoryReporter();
697 :
698 : #ifdef JS_GC_ZEAL
699 : void
700 : UpdateGCZealInternal(JSContext* aCx, PRUint8 aGCZeal);
701 : #endif
702 :
703 : void
704 : GarbageCollectInternal(JSContext* aCx, bool aShrinking,
705 : bool aCollectChildren);
706 :
707 : JSContext*
708 0 : GetJSContext() const
709 : {
710 0 : AssertIsOnWorkerThread();
711 0 : return mJSContext;
712 : }
713 :
714 : #ifdef DEBUG
715 : void
716 : AssertIsOnWorkerThread() const;
717 :
718 : void
719 0 : SetThread(nsIThread* aThread)
720 : {
721 0 : mThread = aThread;
722 0 : }
723 : #else
724 : void
725 : AssertIsOnWorkerThread() const
726 : { }
727 : #endif
728 :
729 : WorkerCrossThreadDispatcher*
730 : GetCrossThreadDispatcher();
731 :
732 : private:
733 : WorkerPrivate(JSContext* aCx, JSObject* aObject, WorkerPrivate* aParent,
734 : JSContext* aParentJSContext, const nsAString& aScriptURL,
735 : bool aIsChromeWorker, const nsACString& aDomain,
736 : nsCOMPtr<nsPIDOMWindow>& aWindow,
737 : nsCOMPtr<nsIScriptContext>& aScriptContext,
738 : nsCOMPtr<nsIURI>& aBaseURI, nsCOMPtr<nsIPrincipal>& aPrincipal,
739 : nsCOMPtr<nsIDocument>& aDocument);
740 :
741 : bool
742 : Dispatch(WorkerRunnable* aEvent, EventQueue* aQueue);
743 :
744 : bool
745 : DispatchToSyncQueue(WorkerSyncRunnable* aEvent);
746 :
747 : void
748 : ClearQueue(EventQueue* aQueue);
749 :
750 : bool
751 0 : MayContinueRunning()
752 : {
753 0 : AssertIsOnWorkerThread();
754 :
755 : Status status;
756 : {
757 0 : mozilla::MutexAutoLock lock(mMutex);
758 0 : status = mStatus;
759 : }
760 :
761 0 : if (status >= Killing) {
762 0 : return false;
763 : }
764 0 : if (status >= Running) {
765 0 : return mKillTime.IsNull() || RemainingRunTimeMS() > 0;
766 : }
767 0 : return true;
768 : }
769 :
770 : PRUint32
771 : RemainingRunTimeMS() const;
772 :
773 : void
774 : CancelAllTimeouts(JSContext* aCx);
775 :
776 : bool
777 : ScheduleKillCloseEventRunnable(JSContext* aCx);
778 :
779 : void
780 0 : StopAcceptingEvents()
781 : {
782 0 : AssertIsOnWorkerThread();
783 :
784 0 : mozilla::MutexAutoLock lock(mMutex);
785 :
786 0 : mStatus = Dead;
787 0 : mJSContext = nsnull;
788 :
789 0 : ClearQueue(&mControlQueue);
790 0 : ClearQueue(&mQueue);
791 0 : }
792 :
793 : bool
794 : ProcessAllControlRunnables();
795 : };
796 :
797 : WorkerPrivate*
798 : GetWorkerPrivateFromContext(JSContext* aCx);
799 :
800 : enum WorkerStructuredDataType
801 : {
802 : DOMWORKER_SCTAG_FILE = JS_SCTAG_USER_MIN + 0x1000,
803 : DOMWORKER_SCTAG_BLOB,
804 :
805 : DOMWORKER_SCTAG_END
806 : };
807 :
808 : JSStructuredCloneCallbacks*
809 : WorkerStructuredCloneCallbacks(bool aMainRuntime);
810 :
811 : JSStructuredCloneCallbacks*
812 : ChromeWorkerStructuredCloneCallbacks(bool aMainRuntime);
813 :
814 : END_WORKERS_NAMESPACE
815 :
816 : #endif /* mozilla_dom_workers_workerprivate_h__ */
|