Source code

Revision control

Other Tools

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 "mozilla/dom/ChildProcessChannelListener.h"
8
9
namespace mozilla {
10
namespace dom {
11
12
static StaticRefPtr<ChildProcessChannelListener> sCPCLSingleton;
13
14
void ChildProcessChannelListener::RegisterCallback(uint64_t aIdentifier,
15
Callback&& aCallback) {
16
if (auto args = mChannelArgs.GetAndRemove(aIdentifier)) {
17
nsresult rv =
18
aCallback(args->mLoadState, std::move(args->mRedirects), args->mTiming);
19
args->mResolver(rv);
20
} else {
21
mCallbacks.Put(aIdentifier, std::move(aCallback));
22
}
23
}
24
25
void ChildProcessChannelListener::OnChannelReady(
26
nsDocShellLoadState* aLoadState, uint64_t aIdentifier,
27
nsTArray<net::DocumentChannelRedirect>&& aRedirects,
28
nsDOMNavigationTiming* aTiming, Resolver&& aResolver) {
29
if (auto callback = mCallbacks.GetAndRemove(aIdentifier)) {
30
nsresult rv = (*callback)(aLoadState, std::move(aRedirects), aTiming);
31
aResolver(rv);
32
} else {
33
mChannelArgs.Put(aIdentifier, {aLoadState, std::move(aRedirects), aTiming,
34
std::move(aResolver)});
35
}
36
}
37
38
already_AddRefed<ChildProcessChannelListener>
39
ChildProcessChannelListener::GetSingleton() {
40
if (!sCPCLSingleton) {
41
sCPCLSingleton = new ChildProcessChannelListener();
42
ClearOnShutdown(&sCPCLSingleton);
43
}
44
RefPtr<ChildProcessChannelListener> cpcl = sCPCLSingleton;
45
return cpcl.forget();
46
}
47
48
} // namespace dom
49
} // namespace mozilla