Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/clients/manager/ClientSourceOpChild.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 "ClientSourceOpChild.h"
8
9
#include "ClientSource.h"
10
#include "ClientSourceChild.h"
11
#include "mozilla/Unused.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
ClientSource*
17
ClientSourceOpChild::GetSource() const
18
0
{
19
0
  auto actor = static_cast<ClientSourceChild*>(Manager());
20
0
  return actor->GetSource();
21
0
}
22
23
template<typename Method, typename Args>
24
void
25
ClientSourceOpChild::DoSourceOp(Method aMethod, const Args& aArgs)
26
0
{
27
0
  RefPtr<ClientOpPromise> promise;
28
0
  nsCOMPtr<nsISerialEventTarget> target;
29
0
30
0
  // Some ClientSource operations can cause the ClientSource to be destroyed.
31
0
  // This means we should reference the ClientSource pointer for the minimum
32
0
  // possible to start the operation.  Use an extra block scope here to help
33
0
  // enforce this and prevent accidental usage later in the method.
34
0
  {
35
0
    ClientSource* source = GetSource();
36
0
    if (!source) {
37
0
      Unused << PClientSourceOpChild::Send__delete__(this, NS_ERROR_DOM_ABORT_ERR);
38
0
      return;
39
0
    }
40
0
41
0
    target = source->EventTarget();
42
0
43
0
    // This may cause the ClientSource object to be destroyed.  Do not
44
0
    // use the source variable after this call.
45
0
    promise = (source->*aMethod)(aArgs);
46
0
  }
47
0
48
0
  // The ClientSource methods are required to always return a promise.  If
49
0
  // they encounter an error they should just immediately resolve or reject
50
0
  // the promise as appropriate.
51
0
  MOZ_DIAGNOSTIC_ASSERT(promise);
52
0
53
0
  // Capture 'this' is safe here because we disconnect the promise
54
0
  // ActorDestroy() which ensures nethier lambda is called if the
55
0
  // actor is destroyed before the source operation completes.
56
0
  //
57
0
  // Also capture the promise to ensure it lives until we get a reaction
58
0
  // or the actor starts shutting down and we disconnect our Thenable.
59
0
  // If the ClientSource is doing something async it may throw away the
60
0
  // promise on its side if the global is closed.
61
0
  promise->Then(target, __func__,
62
0
    [this, promise] (const mozilla::dom::ClientOpResult& aResult) {
63
0
      mPromiseRequestHolder.Complete();
64
0
      Unused << PClientSourceOpChild::Send__delete__(this, aResult);
65
0
    },
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs const&)::{lambda(mozilla::dom::ClientOpResult const&)#1}::operator()(mozilla::dom::ClientOpResult const&) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs const&)::{lambda(mozilla::dom::ClientOpResult const&)#1}::operator()(mozilla::dom::ClientOpResult const&) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs const&)::{lambda(mozilla::dom::ClientOpResult const&)#1}::operator()(mozilla::dom::ClientOpResult const&) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs const&)::{lambda(mozilla::dom::ClientOpResult const&)#1}::operator()(mozilla::dom::ClientOpResult const&) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs const&)::{lambda(mozilla::dom::ClientOpResult const&)#1}::operator()(mozilla::dom::ClientOpResult const&) const
66
0
    [this, promise] (nsresult aRv) {
67
0
      mPromiseRequestHolder.Complete();
68
0
      Unused << PClientSourceOpChild::Send__delete__(this, aRv);
69
0
    })->Track(mPromiseRequestHolder);
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs const&)::{lambda(nsresult)#1}::operator()(nsresult) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs const&)::{lambda(nsresult)#1}::operator()(nsresult) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs const&)::{lambda(nsresult)#1}::operator()(nsresult) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs const&)::{lambda(nsresult)#1}::operator()(nsresult) const
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs const&)::{lambda(nsresult)#1}::operator()(nsresult) const
70
0
}
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientControlledArgs const&), mozilla::dom::ClientControlledArgs const&)
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientFocusArgs const&), mozilla::dom::ClientFocusArgs const&)
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientPostMessageArgs const&), mozilla::dom::ClientPostMessageArgs const&)
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientClaimArgs const&), mozilla::dom::ClientClaimArgs const&)
Unexecuted instantiation: void mozilla::dom::ClientSourceOpChild::DoSourceOp<RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs>(RefPtr<mozilla::MozPromise<mozilla::dom::ClientOpResult, nsresult, false> > (mozilla::dom::ClientSource::*)(mozilla::dom::ClientGetInfoAndStateArgs const&), mozilla::dom::ClientGetInfoAndStateArgs const&)
71
72
void
73
ClientSourceOpChild::ActorDestroy(ActorDestroyReason aReason)
74
0
{
75
0
  mPromiseRequestHolder.DisconnectIfExists();
76
0
}
77
78
void
79
ClientSourceOpChild::Init(const ClientOpConstructorArgs& aArgs)
80
0
{
81
0
  switch (aArgs.type()) {
82
0
    case ClientOpConstructorArgs::TClientControlledArgs:
83
0
    {
84
0
      DoSourceOp(&ClientSource::Control, aArgs.get_ClientControlledArgs());
85
0
      break;
86
0
    }
87
0
    case ClientOpConstructorArgs::TClientFocusArgs:
88
0
    {
89
0
      DoSourceOp(&ClientSource::Focus, aArgs.get_ClientFocusArgs());
90
0
      break;
91
0
    }
92
0
    case ClientOpConstructorArgs::TClientPostMessageArgs:
93
0
    {
94
0
      DoSourceOp(&ClientSource::PostMessage, aArgs.get_ClientPostMessageArgs());
95
0
      break;
96
0
    }
97
0
    case ClientOpConstructorArgs::TClientClaimArgs:
98
0
    {
99
0
      DoSourceOp(&ClientSource::Claim, aArgs.get_ClientClaimArgs());
100
0
      break;
101
0
    }
102
0
    case ClientOpConstructorArgs::TClientGetInfoAndStateArgs:
103
0
    {
104
0
      DoSourceOp(&ClientSource::GetInfoAndState,
105
0
                 aArgs.get_ClientGetInfoAndStateArgs());
106
0
      break;
107
0
    }
108
0
    default:
109
0
    {
110
0
      MOZ_ASSERT_UNREACHABLE("unknown client operation!");
111
0
      break;
112
0
    }
113
0
  }
114
0
}
115
116
} // namespace dom
117
} // namespace mozilla