Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/ContentProcessMessageManager.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 "ContentProcessMessageManager.h"
8
9
#include "nsContentCID.h"
10
#include "mozilla/dom/ContentChild.h"
11
#include "mozilla/dom/MessageManagerBinding.h"
12
#include "mozilla/dom/ParentProcessMessageManager.h"
13
#include "mozilla/dom/ResolveSystemBinding.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/ipc/SharedMap.h"
16
17
using namespace mozilla;
18
using namespace mozilla::dom;
19
20
bool ContentProcessMessageManager::sWasCreated = false;
21
22
ContentProcessMessageManager::ContentProcessMessageManager(nsFrameMessageManager* aMessageManager)
23
 : MessageManagerGlobal(aMessageManager),
24
   mInitialized(false)
25
0
{
26
0
  mozilla::HoldJSObjects(this);
27
0
}
28
29
ContentProcessMessageManager::~ContentProcessMessageManager()
30
0
{
31
0
  mAnonymousGlobalScopes.Clear();
32
0
  mozilla::DropJSObjects(this);
33
0
}
34
35
ContentProcessMessageManager*
36
ContentProcessMessageManager::Get()
37
0
{
38
0
  nsCOMPtr<nsIMessageSender> service = do_GetService(NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID);
39
0
  if (!service) {
40
0
    return nullptr;
41
0
  }
42
0
  sWasCreated = true;
43
0
  return static_cast<ContentProcessMessageManager*>(service.get());
44
0
}
45
46
already_AddRefed<mozilla::dom::ipc::SharedMap>
47
ContentProcessMessageManager::SharedData()
48
0
{
49
0
  if (ContentChild* child = ContentChild::GetSingleton()) {
50
0
    return do_AddRef(child->SharedData());
51
0
  }
52
0
  auto* ppmm = nsFrameMessageManager::sParentProcessManager;
53
0
  return do_AddRef(ppmm->SharedData()->GetReadOnly());
54
0
}
55
56
bool
57
ContentProcessMessageManager::WasCreated()
58
18
{
59
18
  return sWasCreated;
60
18
}
61
62
void
63
ContentProcessMessageManager::MarkForCC()
64
0
{
65
0
  MarkScopesForCC();
66
0
  MessageManagerGlobal::MarkForCC();
67
0
}
68
69
NS_IMPL_CYCLE_COLLECTION_CLASS(ContentProcessMessageManager)
70
71
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ContentProcessMessageManager)
72
0
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
73
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
74
75
0
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ContentProcessMessageManager)
76
0
  NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
77
0
  tmp->nsMessageManagerScriptExecutor::Trace(aCallbacks, aClosure);
78
0
NS_IMPL_CYCLE_COLLECTION_TRACE_END
79
80
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ContentProcessMessageManager)
81
0
  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
82
0
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
83
0
  tmp->nsMessageManagerScriptExecutor::Unlink();
84
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
85
86
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentProcessMessageManager)
87
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
88
0
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessageSender)
89
0
  NS_INTERFACE_MAP_ENTRY(nsIMessageSender)
90
0
  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
91
0
NS_INTERFACE_MAP_END
92
93
NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentProcessMessageManager)
94
NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentProcessMessageManager)
95
96
bool
97
ContentProcessMessageManager::Init()
98
0
{
99
0
  if (mInitialized) {
100
0
    return true;
101
0
  }
102
0
  mInitialized = true;
103
0
104
0
  return nsMessageManagerScriptExecutor::Init();
105
0
}
106
107
JSObject*
108
ContentProcessMessageManager::WrapObject(JSContext* aCx,
109
                                         JS::Handle<JSObject*> aGivenProto)
110
0
{
111
0
  return ContentProcessMessageManager_Binding::Wrap(aCx, this, aGivenProto);
112
0
}
113
114
JSObject*
115
ContentProcessMessageManager::GetOrCreateWrapper()
116
0
{
117
0
  JS::RootedValue val(RootingCx());
118
0
  {
119
0
    // Scope to run ~AutoJSAPI before working with a raw JSObject*.
120
0
    AutoJSAPI jsapi;
121
0
    jsapi.Init();
122
0
123
0
    if (!GetOrCreateDOMReflectorNoWrap(jsapi.cx(), this, &val)) {
124
0
      return nullptr;
125
0
    }
126
0
  }
127
0
  MOZ_ASSERT(val.isObject());
128
0
  return &val.toObject();
129
0
}
130
131
void
132
ContentProcessMessageManager::LoadScript(const nsAString& aURL)
133
0
{
134
0
  Init();
135
0
  JS::Rooted<JSObject*> messageManager(mozilla::dom::RootingCx(), GetOrCreateWrapper());
136
0
  LoadScriptInternal(messageManager, aURL, true);
137
0
}
138
139
void
140
ContentProcessMessageManager::SetInitialProcessData(JS::HandleValue aInitialData)
141
0
{
142
0
  mMessageManager->SetInitialProcessData(aInitialData);
143
0
}