/src/mozilla-central/dom/media/eme/MediaEncryptedEvent.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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "MediaEncryptedEvent.h" |
8 | | #include "mozilla/dom/MediaEncryptedEventBinding.h" |
9 | | #include "nsContentUtils.h" |
10 | | #include "jsfriendapi.h" |
11 | | #include "nsINode.h" |
12 | | #include "mozilla/dom/MediaKeys.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | NS_IMPL_CYCLE_COLLECTION_CLASS(MediaEncryptedEvent) |
18 | | |
19 | | NS_IMPL_ADDREF_INHERITED(MediaEncryptedEvent, Event) |
20 | | NS_IMPL_RELEASE_INHERITED(MediaEncryptedEvent, Event) |
21 | | |
22 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaEncryptedEvent, Event) |
23 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
24 | | |
25 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MediaEncryptedEvent, Event) |
26 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mInitData) |
27 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
28 | | |
29 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MediaEncryptedEvent, Event) |
30 | 0 | tmp->mInitData = nullptr; |
31 | 0 | mozilla::DropJSObjects(this); |
32 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
33 | | |
34 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaEncryptedEvent) |
35 | 0 | NS_INTERFACE_MAP_END_INHERITING(Event) |
36 | | |
37 | | MediaEncryptedEvent::MediaEncryptedEvent(EventTarget* aOwner) |
38 | | : Event(aOwner, nullptr, nullptr) |
39 | 0 | { |
40 | 0 | mozilla::HoldJSObjects(this); |
41 | 0 | } |
42 | | |
43 | | MediaEncryptedEvent::~MediaEncryptedEvent() |
44 | 0 | { |
45 | 0 | mInitData = nullptr; |
46 | 0 | mozilla::DropJSObjects(this); |
47 | 0 | } |
48 | | |
49 | | JSObject* |
50 | | MediaEncryptedEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
51 | 0 | { |
52 | 0 | return MediaEncryptedEvent_Binding::Wrap(aCx, this, aGivenProto); |
53 | 0 | } |
54 | | |
55 | | already_AddRefed<MediaEncryptedEvent> |
56 | | MediaEncryptedEvent::Constructor(EventTarget* aOwner) |
57 | 0 | { |
58 | 0 | RefPtr<MediaEncryptedEvent> e = new MediaEncryptedEvent(aOwner); |
59 | 0 | e->InitEvent(NS_LITERAL_STRING("encrypted"), CanBubble::eNo, Cancelable::eNo); |
60 | 0 | e->SetTrusted(true); |
61 | 0 | return e.forget(); |
62 | 0 | } |
63 | | |
64 | | already_AddRefed<MediaEncryptedEvent> |
65 | | MediaEncryptedEvent::Constructor(EventTarget* aOwner, |
66 | | const nsAString& aInitDataType, |
67 | | const nsTArray<uint8_t>& aInitData) |
68 | 0 | { |
69 | 0 | RefPtr<MediaEncryptedEvent> e = new MediaEncryptedEvent(aOwner); |
70 | 0 | e->InitEvent(NS_LITERAL_STRING("encrypted"), CanBubble::eNo, Cancelable::eNo); |
71 | 0 | e->mInitDataType = aInitDataType; |
72 | 0 | e->mRawInitData = aInitData; |
73 | 0 | e->SetTrusted(true); |
74 | 0 | return e.forget(); |
75 | 0 | } |
76 | | |
77 | | already_AddRefed<MediaEncryptedEvent> |
78 | | MediaEncryptedEvent::Constructor(const GlobalObject& aGlobal, |
79 | | const nsAString& aType, |
80 | | const MediaKeyNeededEventInit& aEventInitDict, |
81 | | ErrorResult& aRv) |
82 | 0 | { |
83 | 0 | nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports()); |
84 | 0 | RefPtr<MediaEncryptedEvent> e = new MediaEncryptedEvent(owner); |
85 | 0 | bool trusted = e->Init(owner); |
86 | 0 | e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); |
87 | 0 | e->mInitDataType = aEventInitDict.mInitDataType; |
88 | 0 | if (!aEventInitDict.mInitData.IsNull()) { |
89 | 0 | const auto& a = aEventInitDict.mInitData.Value(); |
90 | 0 | a.ComputeLengthAndData(); |
91 | 0 | e->mInitData = ArrayBuffer::Create(aGlobal.Context(), |
92 | 0 | a.Length(), |
93 | 0 | a.Data()); |
94 | 0 | if (!e->mInitData) { |
95 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
96 | 0 | return nullptr; |
97 | 0 | } |
98 | 0 | } |
99 | 0 | e->SetTrusted(trusted); |
100 | 0 | return e.forget(); |
101 | 0 | } |
102 | | |
103 | | void |
104 | | MediaEncryptedEvent::GetInitDataType(nsString& aRetVal) const |
105 | 0 | { |
106 | 0 | aRetVal = mInitDataType; |
107 | 0 | } |
108 | | |
109 | | void |
110 | | MediaEncryptedEvent::GetInitData(JSContext* cx, |
111 | | JS::MutableHandle<JSObject*> aData, |
112 | | ErrorResult& aRv) |
113 | 0 | { |
114 | 0 | if (mRawInitData.Length()) { |
115 | 0 | mInitData = ArrayBuffer::Create(cx, |
116 | 0 | this, |
117 | 0 | mRawInitData.Length(), |
118 | 0 | mRawInitData.Elements()); |
119 | 0 | if (!mInitData) { |
120 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
121 | 0 | return; |
122 | 0 | } |
123 | 0 | mRawInitData.Clear(); |
124 | 0 | } |
125 | 0 | aData.set(mInitData); |
126 | 0 | } |
127 | | |
128 | | } // namespace dom |
129 | | } // namespace mozilla |