Line data Source code
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 : #define LOG(args) MOZ_LOG(gMediaChildLog, mozilla::LogLevel::Debug, args)
18 :
19 : namespace mozilla {
20 : namespace media {
21 :
22 : already_AddRefed<Pledge<nsCString>>
23 0 : GetPrincipalKey(const ipc::PrincipalInfo& aPrincipalInfo, bool aPersist)
24 : {
25 0 : RefPtr<MediaManager> mgr = MediaManager::GetInstance();
26 0 : MOZ_ASSERT(mgr);
27 :
28 0 : RefPtr<Pledge<nsCString>> p = new Pledge<nsCString>();
29 0 : uint32_t id = mgr->mGetPrincipalKeyPledges.Append(*p);
30 :
31 0 : if (XRE_GetProcessType() == GeckoProcessType_Default) {
32 0 : mgr->GetNonE10sParent()->RecvGetPrincipalKey(id, aPrincipalInfo, aPersist);
33 : } else {
34 0 : Child::Get()->SendGetPrincipalKey(id, aPrincipalInfo, aPersist);
35 : }
36 0 : return p.forget();
37 : }
38 :
39 : void
40 0 : SanitizeOriginKeys(const uint64_t& aSinceWhen, bool aOnlyPrivateBrowsing)
41 : {
42 0 : LOG(("SanitizeOriginKeys since %" PRIu64 " %s", aSinceWhen,
43 : (aOnlyPrivateBrowsing? "in Private Browsing." : ".")));
44 :
45 0 : if (XRE_GetProcessType() == GeckoProcessType_Default) {
46 : // Avoid opening MediaManager in this case, since this is called by
47 : // 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 : } else {
51 0 : Child::Get()->SendSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing);
52 : }
53 0 : }
54 :
55 : static Child* sChild;
56 :
57 0 : Child* Child::Get()
58 : {
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 : }
64 0 : return sChild;
65 : }
66 :
67 0 : Child::Child()
68 0 : : mActorDestroyed(false)
69 : {
70 0 : LOG(("media::Child: %p", this));
71 0 : MOZ_COUNT_CTOR(Child);
72 0 : }
73 :
74 0 : Child::~Child()
75 : {
76 0 : LOG(("~media::Child: %p", this));
77 0 : sChild = nullptr;
78 0 : MOZ_COUNT_DTOR(Child);
79 0 : }
80 :
81 0 : void Child::ActorDestroy(ActorDestroyReason aWhy)
82 : {
83 0 : mActorDestroyed = true;
84 0 : }
85 :
86 : mozilla::ipc::IPCResult
87 0 : Child::RecvGetPrincipalKeyResponse(const uint32_t& aRequestId,
88 : const nsCString& aKey)
89 : {
90 0 : RefPtr<MediaManager> mgr = MediaManager::GetInstance();
91 0 : if (!mgr) {
92 0 : return IPC_FAIL_NO_REASON(this);
93 : }
94 : RefPtr<Pledge<nsCString>> pledge =
95 0 : mgr->mGetPrincipalKeyPledges.Remove(aRequestId);
96 0 : if (pledge) {
97 0 : pledge->Resolve(aKey);
98 : }
99 0 : return IPC_OK();
100 : }
101 :
102 : PMediaChild*
103 0 : AllocPMediaChild()
104 : {
105 0 : return new Child();
106 : }
107 :
108 : bool
109 0 : DeallocPMediaChild(media::PMediaChild *aActor)
110 : {
111 0 : delete static_cast<Child*>(aActor);
112 0 : return true;
113 : }
114 :
115 : } // namespace media
116 : } // namespace mozilla
|