2019-01-24 00:07:08 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/ChildProcessChannelListener.h"
|
|
|
|
|
2021-01-04 17:18:37 +03:00
|
|
|
#include "mozilla/ipc/Endpoint.h"
|
2020-05-04 17:53:34 +03:00
|
|
|
#include "nsDocShellLoadState.h"
|
|
|
|
|
2019-01-24 00:07:08 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
static StaticRefPtr<ChildProcessChannelListener> sCPCLSingleton;
|
|
|
|
|
|
|
|
void ChildProcessChannelListener::RegisterCallback(uint64_t aIdentifier,
|
|
|
|
Callback&& aCallback) {
|
2021-02-22 15:07:48 +03:00
|
|
|
if (auto args = mChannelArgs.Extract(aIdentifier)) {
|
2020-03-20 01:30:07 +03:00
|
|
|
nsresult rv =
|
2020-05-08 06:28:42 +03:00
|
|
|
aCallback(args->mLoadState, std::move(args->mStreamFilterEndpoints),
|
|
|
|
args->mTiming);
|
2020-03-20 01:30:07 +03:00
|
|
|
args->mResolver(rv);
|
2019-01-24 00:07:08 +03:00
|
|
|
} else {
|
2021-02-26 12:11:46 +03:00
|
|
|
mCallbacks.InsertOrUpdate(aIdentifier, std::move(aCallback));
|
2019-01-24 00:07:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 09:09:54 +03:00
|
|
|
void ChildProcessChannelListener::OnChannelReady(
|
2020-02-24 05:16:24 +03:00
|
|
|
nsDocShellLoadState* aLoadState, uint64_t aIdentifier,
|
2020-04-09 10:03:49 +03:00
|
|
|
nsTArray<Endpoint>&& aStreamFilterEndpoints, nsDOMNavigationTiming* aTiming,
|
|
|
|
Resolver&& aResolver) {
|
2021-02-22 15:07:48 +03:00
|
|
|
if (auto callback = mCallbacks.Extract(aIdentifier)) {
|
2020-05-08 06:28:42 +03:00
|
|
|
nsresult rv =
|
|
|
|
(*callback)(aLoadState, std::move(aStreamFilterEndpoints), aTiming);
|
2020-03-20 01:30:07 +03:00
|
|
|
aResolver(rv);
|
2019-01-24 00:07:08 +03:00
|
|
|
} else {
|
2021-02-26 12:11:46 +03:00
|
|
|
mChannelArgs.InsertOrUpdate(
|
|
|
|
aIdentifier, CallbackArgs{aLoadState, std::move(aStreamFilterEndpoints),
|
2021-02-16 18:53:33 +03:00
|
|
|
aTiming, std::move(aResolver)});
|
2019-01-24 00:07:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-27 07:10:23 +03:00
|
|
|
ChildProcessChannelListener::~ChildProcessChannelListener() {
|
2021-03-24 20:56:49 +03:00
|
|
|
for (const auto& args : mChannelArgs.Values()) {
|
|
|
|
args.mResolver(NS_ERROR_FAILURE);
|
2020-06-27 07:10:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:07:08 +03:00
|
|
|
already_AddRefed<ChildProcessChannelListener>
|
|
|
|
ChildProcessChannelListener::GetSingleton() {
|
|
|
|
if (!sCPCLSingleton) {
|
|
|
|
sCPCLSingleton = new ChildProcessChannelListener();
|
|
|
|
ClearOnShutdown(&sCPCLSingleton);
|
|
|
|
}
|
|
|
|
RefPtr<ChildProcessChannelListener> cpcl = sCPCLSingleton;
|
|
|
|
return cpcl.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|