Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/messagechannel/MessageChannel.cpp
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
#include "MessageChannel.h"
8
9
#include "mozilla/dom/MessageChannelBinding.h"
10
#include "mozilla/dom/MessagePort.h"
11
#include "mozilla/dom/Navigator.h"
12
#include "mozilla/dom/WorkerRunnable.h"
13
#include "nsContentUtils.h"
14
#include "nsIDocument.h"
15
#include "nsIGlobalObject.h"
16
#include "nsIPrincipal.h"
17
#include "nsServiceManagerUtils.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MessageChannel, mGlobal, mPort1, mPort2)
23
NS_IMPL_CYCLE_COLLECTING_ADDREF(MessageChannel)
24
NS_IMPL_CYCLE_COLLECTING_RELEASE(MessageChannel)
25
26
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageChannel)
27
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
28
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
29
0
NS_INTERFACE_MAP_END
30
31
MessageChannel::MessageChannel(nsIGlobalObject* aGlobal)
32
  : mGlobal(aGlobal)
33
0
{
34
0
  MOZ_ASSERT(aGlobal);
35
0
}
36
37
MessageChannel::~MessageChannel()
38
0
{
39
0
}
40
41
JSObject*
42
MessageChannel::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
43
0
{
44
0
  return MessageChannel_Binding::Wrap(aCx, this, aGivenProto);
45
0
}
46
47
/* static */ already_AddRefed<MessageChannel>
48
MessageChannel::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
49
0
{
50
0
  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
51
0
  return Constructor(global, aRv);
52
0
}
53
54
/* static */ already_AddRefed<MessageChannel>
55
MessageChannel::Constructor(nsIGlobalObject* aGlobal, ErrorResult& aRv)
56
0
{
57
0
  MOZ_ASSERT(aGlobal);
58
0
59
0
  nsID portUUID1;
60
0
  aRv = nsContentUtils::GenerateUUIDInPlace(portUUID1);
61
0
  if (aRv.Failed()) {
62
0
    return nullptr;
63
0
  }
64
0
65
0
  nsID portUUID2;
66
0
  aRv = nsContentUtils::GenerateUUIDInPlace(portUUID2);
67
0
  if (aRv.Failed()) {
68
0
    return nullptr;
69
0
  }
70
0
71
0
  RefPtr<MessageChannel> channel = new MessageChannel(aGlobal);
72
0
73
0
  channel->mPort1 = MessagePort::Create(aGlobal, portUUID1, portUUID2, aRv);
74
0
  if (NS_WARN_IF(aRv.Failed())) {
75
0
    return nullptr;
76
0
  }
77
0
78
0
  channel->mPort2 = MessagePort::Create(aGlobal, portUUID2, portUUID1, aRv);
79
0
  if (NS_WARN_IF(aRv.Failed())) {
80
0
    return nullptr;
81
0
  }
82
0
83
0
  channel->mPort1->UnshippedEntangle(channel->mPort2);
84
0
  channel->mPort2->UnshippedEntangle(channel->mPort1);
85
0
86
0
  return channel.forget();
87
0
}
88
89
} // namespace dom
90
} // namespace mozilla