Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / docshell / base / ChildProcessChannelListener.cpp
blob628d75abb1864982fdb0621a641655cac0d6141d
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"
12 namespace mozilla {
13 namespace dom {
15 static StaticRefPtr<ChildProcessChannelListener> sCPCLSingleton;
17 void ChildProcessChannelListener::RegisterCallback(uint64_t aIdentifier,
18 Callback&& aCallback) {
19 if (auto args = mChannelArgs.Extract(aIdentifier)) {
20 nsresult rv =
21 aCallback(args->mLoadState, std::move(args->mStreamFilterEndpoints),
22 args->mTiming);
23 args->mResolver(rv);
24 } else {
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)) {
34 nsresult rv =
35 (*callback)(aLoadState, std::move(aStreamFilterEndpoints), aTiming);
36 aResolver(rv);
37 } else {
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;
57 return cpcl.forget();
60 } // namespace dom
61 } // namespace mozilla