Bug 1842509 - Remove media.webvtt.regions.enabled pref r=alwu,webidl,smaug,peterv
[gecko.git] / dom / serviceworkers / FetchEventOpParent.cpp
blob06c65f36d299a5ad7188b44e8dfdfb8223d38b13
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 "FetchEventOpParent.h"
9 #include "mozilla/dom/FetchTypes.h"
10 #include "nsDebug.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/Unused.h"
15 #include "mozilla/dom/FetchEventOpProxyParent.h"
16 #include "mozilla/dom/FetchStreamUtils.h"
17 #include "mozilla/dom/InternalResponse.h"
18 #include "mozilla/dom/RemoteWorkerControllerParent.h"
19 #include "mozilla/dom/RemoteWorkerParent.h"
20 #include "mozilla/ipc/BackgroundParent.h"
22 namespace mozilla {
24 using namespace ipc;
26 namespace dom {
28 std::tuple<Maybe<ParentToParentInternalResponse>, Maybe<ResponseEndArgs>>
29 FetchEventOpParent::OnStart(
30 MovingNotNull<RefPtr<FetchEventOpProxyParent>> aFetchEventOpProxyParent) {
31 Maybe<ParentToParentInternalResponse> preloadResponse =
32 std::move(mState.as<Pending>().mPreloadResponse);
33 Maybe<ResponseEndArgs> preloadResponseEndArgs =
34 std::move(mState.as<Pending>().mEndArgs);
35 mState = AsVariant(Started{std::move(aFetchEventOpProxyParent)});
36 return std::make_tuple(preloadResponse, preloadResponseEndArgs);
39 void FetchEventOpParent::OnFinish() {
40 MOZ_ASSERT(mState.is<Started>());
41 mState = AsVariant(Finished());
44 mozilla::ipc::IPCResult FetchEventOpParent::RecvPreloadResponse(
45 ParentToParentInternalResponse&& aResponse) {
46 AssertIsOnBackgroundThread();
48 mState.match(
49 [&aResponse](Pending& aPending) {
50 MOZ_ASSERT(aPending.mPreloadResponse.isNothing());
51 aPending.mPreloadResponse = Some(std::move(aResponse));
53 [&aResponse](Started& aStarted) {
54 auto backgroundParent = WrapNotNull(
55 WrapNotNull(aStarted.mFetchEventOpProxyParent->Manager())
56 ->Manager());
57 Unused << aStarted.mFetchEventOpProxyParent->SendPreloadResponse(
58 ToParentToChild(aResponse, backgroundParent));
60 [](const Finished&) {});
62 return IPC_OK();
65 mozilla::ipc::IPCResult FetchEventOpParent::RecvPreloadResponseTiming(
66 ResponseTiming&& aTiming) {
67 AssertIsOnBackgroundThread();
69 mState.match(
70 [&aTiming](Pending& aPending) {
71 MOZ_ASSERT(aPending.mTiming.isNothing());
72 aPending.mTiming = Some(std::move(aTiming));
74 [&aTiming](Started& aStarted) {
75 Unused << aStarted.mFetchEventOpProxyParent->SendPreloadResponseTiming(
76 std::move(aTiming));
78 [](const Finished&) {});
80 return IPC_OK();
83 mozilla::ipc::IPCResult FetchEventOpParent::RecvPreloadResponseEnd(
84 ResponseEndArgs&& aArgs) {
85 AssertIsOnBackgroundThread();
87 mState.match(
88 [&aArgs](Pending& aPending) {
89 MOZ_ASSERT(aPending.mEndArgs.isNothing());
90 aPending.mEndArgs = Some(std::move(aArgs));
92 [&aArgs](Started& aStarted) {
93 Unused << aStarted.mFetchEventOpProxyParent->SendPreloadResponseEnd(
94 std::move(aArgs));
96 [](const Finished&) {});
98 return IPC_OK();
101 void FetchEventOpParent::ActorDestroy(ActorDestroyReason) {
102 AssertIsOnBackgroundThread();
105 } // namespace dom
106 } // namespace mozilla