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/. */
7 #include "mozilla/dom/ChildProcessChannelListener.h"
9 #include "mozilla/ipc/Endpoint.h"
10 #include "nsDocShellLoadState.h"
15 static StaticRefPtr
<ChildProcessChannelListener
> sCPCLSingleton
;
17 void ChildProcessChannelListener::RegisterCallback(uint64_t aIdentifier
,
18 Callback
&& aCallback
) {
19 if (auto args
= mChannelArgs
.Extract(aIdentifier
)) {
21 aCallback(args
->mLoadState
, std::move(args
->mStreamFilterEndpoints
),
25 mCallbacks
.InsertOrUpdate(aIdentifier
, std::move(aCallback
));
29 void ChildProcessChannelListener::OnChannelReady(
30 nsDocShellLoadState
* aLoadState
, uint64_t aIdentifier
,
31 nsTArray
<Endpoint
>&& aStreamFilterEndpoints
, nsDOMNavigationTiming
* aTiming
,
32 Resolver
&& aResolver
) {
33 if (auto callback
= mCallbacks
.Extract(aIdentifier
)) {
35 (*callback
)(aLoadState
, std::move(aStreamFilterEndpoints
), aTiming
);
38 mChannelArgs
.InsertOrUpdate(
39 aIdentifier
, CallbackArgs
{aLoadState
, std::move(aStreamFilterEndpoints
),
40 aTiming
, std::move(aResolver
)});
44 ChildProcessChannelListener::~ChildProcessChannelListener() {
45 for (const auto& args
: mChannelArgs
.Values()) {
46 args
.mResolver(NS_ERROR_FAILURE
);
50 already_AddRefed
<ChildProcessChannelListener
>
51 ChildProcessChannelListener::GetSingleton() {
52 if (!sCPCLSingleton
) {
53 sCPCLSingleton
= new ChildProcessChannelListener();
54 ClearOnShutdown(&sCPCLSingleton
);
56 RefPtr
<ChildProcessChannelListener
> cpcl
= sCPCLSingleton
;
61 } // namespace mozilla