/src/mozilla-central/dom/clients/manager/ClientHandleOpParent.cpp
Line | Count | Source (jump to first uncovered line) |
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 "ClientHandleOpParent.h" |
8 | | |
9 | | #include "ClientHandleParent.h" |
10 | | #include "ClientSourceParent.h" |
11 | | #include "mozilla/dom/PClientManagerParent.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace dom { |
15 | | |
16 | | ClientSourceParent* |
17 | | ClientHandleOpParent::GetSource() const |
18 | 0 | { |
19 | 0 | auto handle = static_cast<ClientHandleParent*>(Manager()); |
20 | 0 | return handle->GetSource(); |
21 | 0 | } |
22 | | |
23 | | void |
24 | | ClientHandleOpParent::ActorDestroy(ActorDestroyReason aReason) |
25 | 0 | { |
26 | 0 | mPromiseRequestHolder.DisconnectIfExists(); |
27 | 0 | } |
28 | | |
29 | | void |
30 | | ClientHandleOpParent::Init(const ClientOpConstructorArgs& aArgs) |
31 | 0 | { |
32 | 0 | ClientSourceParent* source = GetSource(); |
33 | 0 | if (!source) { |
34 | 0 | Unused << PClientHandleOpParent::Send__delete__(this, NS_ERROR_DOM_ABORT_ERR); |
35 | 0 | return; |
36 | 0 | } |
37 | 0 | |
38 | 0 | RefPtr<ClientOpPromise> p; |
39 | 0 |
|
40 | 0 | // ClientPostMessageArgs can contain PBlob actors. This means we |
41 | 0 | // can't just forward the args from one PBackground manager to |
42 | 0 | // another. Instead, unpack the structured clone data and repack |
43 | 0 | // it into a new set of arguments. |
44 | 0 | if (aArgs.type() == ClientOpConstructorArgs::TClientPostMessageArgs) { |
45 | 0 | const ClientPostMessageArgs& orig = aArgs.get_ClientPostMessageArgs(); |
46 | 0 |
|
47 | 0 | ClientPostMessageArgs rebuild; |
48 | 0 | rebuild.serviceWorker() = orig.serviceWorker(); |
49 | 0 |
|
50 | 0 | StructuredCloneData data; |
51 | 0 | data.BorrowFromClonedMessageDataForBackgroundParent(orig.clonedData()); |
52 | 0 | if (!data.BuildClonedMessageDataForBackgroundParent(source->Manager()->Manager(), |
53 | 0 | rebuild.clonedData())) { |
54 | 0 | Unused << PClientHandleOpParent::Send__delete__(this, NS_ERROR_DOM_ABORT_ERR); |
55 | 0 | return; |
56 | 0 | } |
57 | 0 | |
58 | 0 | p = source->StartOp(rebuild); |
59 | 0 | } |
60 | 0 | |
61 | 0 | // Other argument types can just be forwarded straight through. |
62 | 0 | else { |
63 | 0 | p = source->StartOp(aArgs); |
64 | 0 | } |
65 | 0 |
|
66 | 0 | // Capturing 'this' is safe here because we disconnect the promise in |
67 | 0 | // ActorDestroy() which ensures neither lambda is called if the actor |
68 | 0 | // is destroyed before the source operation completes. |
69 | 0 | p->Then(GetCurrentThreadSerialEventTarget(), __func__, |
70 | 0 | [this] (const ClientOpResult& aResult) { |
71 | 0 | mPromiseRequestHolder.Complete(); |
72 | 0 | Unused << PClientHandleOpParent::Send__delete__(this, aResult); |
73 | 0 | }, |
74 | 0 | [this] (nsresult aRv) { |
75 | 0 | mPromiseRequestHolder.Complete(); |
76 | 0 | Unused << PClientHandleOpParent::Send__delete__(this, aRv); |
77 | 0 | })->Track(mPromiseRequestHolder); |
78 | 0 | } |
79 | | |
80 | | } // namespace dom |
81 | | } // namespace mozilla |