Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/systemservices/MediaChild.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 sw=2 ts=8 et ft=cpp : */
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 file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "MediaChild.h"
8
#include "MediaParent.h"
9
10
#include "nsGlobalWindow.h"
11
#include "mozilla/MediaManager.h"
12
#include "mozilla/Logging.h"
13
#include "nsQueryObject.h"
14
15
#undef LOG
16
mozilla::LazyLogModule gMediaChildLog("MediaChild");
17
0
#define LOG(args) MOZ_LOG(gMediaChildLog, mozilla::LogLevel::Debug, args)
18
19
namespace mozilla {
20
namespace media {
21
22
already_AddRefed<Pledge<nsCString>>
23
GetPrincipalKey(const ipc::PrincipalInfo& aPrincipalInfo, bool aPersist)
24
0
{
25
0
  RefPtr<MediaManager> mgr = MediaManager::GetInstance();
26
0
  MOZ_ASSERT(mgr);
27
0
28
0
  RefPtr<Pledge<nsCString>> p = new Pledge<nsCString>();
29
0
  uint32_t id = mgr->mGetPrincipalKeyPledges.Append(*p);
30
0
31
0
  if (XRE_GetProcessType() == GeckoProcessType_Default) {
32
0
    mgr->GetNonE10sParent()->RecvGetPrincipalKey(id, aPrincipalInfo, aPersist);
33
0
  } else {
34
0
    Child::Get()->SendGetPrincipalKey(id, aPrincipalInfo, aPersist);
35
0
  }
36
0
  return p.forget();
37
0
}
38
39
void
40
SanitizeOriginKeys(const uint64_t& aSinceWhen, bool aOnlyPrivateBrowsing)
41
0
{
42
0
  LOG(("SanitizeOriginKeys since %" PRIu64 " %s", aSinceWhen,
43
0
       (aOnlyPrivateBrowsing? "in Private Browsing." : ".")));
44
0
45
0
  if (XRE_GetProcessType() == GeckoProcessType_Default) {
46
0
    // Avoid opening MediaManager in this case, since this is called by
47
0
    // sanitize.js when cookies are cleared, which can happen on startup.
48
0
    RefPtr<Parent<NonE10s>> tmpParent = new Parent<NonE10s>();
49
0
    tmpParent->RecvSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing);
50
0
  } else {
51
0
    Child::Get()->SendSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing);
52
0
  }
53
0
}
54
55
static Child* sChild;
56
57
Child* Child::Get()
58
0
{
59
0
  MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Content);
60
0
  MOZ_ASSERT(NS_IsMainThread());
61
0
  if (!sChild) {
62
0
    sChild = static_cast<Child*>(dom::ContentChild::GetSingleton()->SendPMediaConstructor());
63
0
  }
64
0
  return sChild;
65
0
}
66
67
Child::Child()
68
  : mActorDestroyed(false)
69
0
{
70
0
  LOG(("media::Child: %p", this));
71
0
  MOZ_COUNT_CTOR(Child);
72
0
}
73
74
Child::~Child()
75
0
{
76
0
  LOG(("~media::Child: %p", this));
77
0
  sChild = nullptr;
78
0
  MOZ_COUNT_DTOR(Child);
79
0
}
80
81
void Child::ActorDestroy(ActorDestroyReason aWhy)
82
0
{
83
0
  mActorDestroyed = true;
84
0
}
85
86
mozilla::ipc::IPCResult
87
Child::RecvGetPrincipalKeyResponse(const uint32_t& aRequestId,
88
                                   const nsCString& aKey)
89
0
{
90
0
  RefPtr<MediaManager> mgr = MediaManager::GetInstance();
91
0
  if (!mgr) {
92
0
    return IPC_FAIL_NO_REASON(this);
93
0
  }
94
0
  RefPtr<Pledge<nsCString>> pledge =
95
0
    mgr->mGetPrincipalKeyPledges.Remove(aRequestId);
96
0
  if (pledge) {
97
0
    pledge->Resolve(aKey);
98
0
  }
99
0
  return IPC_OK();
100
0
}
101
102
PMediaChild*
103
AllocPMediaChild()
104
0
{
105
0
  return new Child();
106
0
}
107
108
bool
109
DeallocPMediaChild(media::PMediaChild *aActor)
110
0
{
111
0
  delete static_cast<Child*>(aActor);
112
0
  return true;
113
0
}
114
115
} // namespace media
116
} // namespace mozilla