Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/workers/SharedWorker.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_workers_sharedworker_h__
8
#define mozilla_dom_workers_sharedworker_h__
9
10
#include "WorkerCommon.h"
11
12
#include "mozilla/dom/BindingDeclarations.h"
13
#include "mozilla/DOMEventTargetHelper.h"
14
15
#ifdef XP_WIN
16
#undef PostMessage
17
#endif
18
19
class nsPIDOMWindowInner;
20
21
namespace mozilla {
22
class EventChainPreVisitor;
23
24
namespace dom {
25
class MessagePort;
26
class StringOrWorkerOptions;
27
class WorkerPrivate;
28
class Event;
29
30
namespace workerinternals {
31
class RuntimeService;
32
}
33
34
class SharedWorker final : public DOMEventTargetHelper
35
{
36
  friend class workerinternals::RuntimeService;
37
38
  typedef mozilla::ErrorResult ErrorResult;
39
  typedef mozilla::dom::GlobalObject GlobalObject;
40
41
  RefPtr<WorkerPrivate> mWorkerPrivate;
42
  RefPtr<MessagePort> mMessagePort;
43
  nsTArray<RefPtr<Event>> mFrozenEvents;
44
  bool mFrozen;
45
46
public:
47
  static already_AddRefed<SharedWorker>
48
  Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
49
              const StringOrWorkerOptions& aOptions, ErrorResult& aRv);
50
51
  MessagePort*
52
  Port();
53
54
  bool
55
  IsFrozen() const
56
0
  {
57
0
    return mFrozen;
58
0
  }
59
60
  void
61
  Freeze();
62
63
  void
64
  Thaw();
65
66
  void
67
  QueueEvent(Event* aEvent);
68
69
  void
70
  Close();
71
72
  NS_DECL_ISUPPORTS_INHERITED
73
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SharedWorker, DOMEventTargetHelper)
74
75
  IMPL_EVENT_HANDLER(error)
76
77
  virtual JSObject*
78
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
79
80
  void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
81
82
  WorkerPrivate*
83
  GetWorkerPrivate() const
84
  {
85
    return mWorkerPrivate;
86
  }
87
88
private:
89
  // This class can only be created from the RuntimeService.
90
  SharedWorker(nsPIDOMWindowInner* aWindow,
91
               WorkerPrivate* aWorkerPrivate,
92
               MessagePort* aMessagePort);
93
94
  // This class is reference-counted and will be destroyed from Release().
95
  ~SharedWorker();
96
97
  // Only called by MessagePort.
98
  void
99
  PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
100
              const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
101
};
102
103
} // dom namespace
104
} // mozilla namespace
105
106
#endif // mozilla_dom_workers_sharedworker_h__