/src/mozilla-central/dom/media/eme/MediaKeyMessageEvent.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 "mozilla/dom/MediaKeyMessageEvent.h" |
8 | | #include "mozilla/dom/MediaKeyMessageEventBinding.h" |
9 | | #include "js/RootingAPI.h" |
10 | | #include "jsfriendapi.h" |
11 | | #include "mozilla/dom/Nullable.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/HoldDropJSObjects.h" |
14 | | #include "mozilla/dom/TypedArray.h" |
15 | | #include "nsContentUtils.h" |
16 | | #include "mozilla/dom/MediaKeys.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | NS_IMPL_CYCLE_COLLECTION_CLASS(MediaKeyMessageEvent) |
22 | | |
23 | | NS_IMPL_ADDREF_INHERITED(MediaKeyMessageEvent, Event) |
24 | | NS_IMPL_RELEASE_INHERITED(MediaKeyMessageEvent, Event) |
25 | | |
26 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaKeyMessageEvent, Event) |
27 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
28 | | |
29 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MediaKeyMessageEvent, Event) |
30 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMessage) |
31 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
32 | | |
33 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MediaKeyMessageEvent, Event) |
34 | 0 | tmp->mMessage = nullptr; |
35 | 0 | mozilla::DropJSObjects(this); |
36 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
37 | | |
38 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaKeyMessageEvent) |
39 | 0 | NS_INTERFACE_MAP_END_INHERITING(Event) |
40 | | |
41 | | MediaKeyMessageEvent::MediaKeyMessageEvent(EventTarget* aOwner) |
42 | | : Event(aOwner, nullptr, nullptr) |
43 | | , mMessageType(static_cast<MediaKeyMessageType>(0)) |
44 | 0 | { |
45 | 0 | mozilla::HoldJSObjects(this); |
46 | 0 | } |
47 | | |
48 | | MediaKeyMessageEvent::~MediaKeyMessageEvent() |
49 | 0 | { |
50 | 0 | mMessage = nullptr; |
51 | 0 | mozilla::DropJSObjects(this); |
52 | 0 | } |
53 | | |
54 | | MediaKeyMessageEvent* |
55 | | MediaKeyMessageEvent::AsMediaKeyMessageEvent() |
56 | 0 | { |
57 | 0 | return this; |
58 | 0 | } |
59 | | |
60 | | JSObject* |
61 | | MediaKeyMessageEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
62 | 0 | { |
63 | 0 | return MediaKeyMessageEvent_Binding::Wrap(aCx, this, aGivenProto); |
64 | 0 | } |
65 | | |
66 | | already_AddRefed<MediaKeyMessageEvent> |
67 | | MediaKeyMessageEvent::Constructor(EventTarget* aOwner, |
68 | | MediaKeyMessageType aMessageType, |
69 | | const nsTArray<uint8_t>& aMessage) |
70 | 0 | { |
71 | 0 | RefPtr<MediaKeyMessageEvent> e = new MediaKeyMessageEvent(aOwner); |
72 | 0 | e->InitEvent(NS_LITERAL_STRING("message"), false, false); |
73 | 0 | e->mMessageType = aMessageType; |
74 | 0 | e->mRawMessage = aMessage; |
75 | 0 | e->SetTrusted(true); |
76 | 0 | return e.forget(); |
77 | 0 | } |
78 | | |
79 | | already_AddRefed<MediaKeyMessageEvent> |
80 | | MediaKeyMessageEvent::Constructor(const GlobalObject& aGlobal, |
81 | | const nsAString& aType, |
82 | | const MediaKeyMessageEventInit& aEventInitDict, |
83 | | ErrorResult& aRv) |
84 | 0 | { |
85 | 0 | nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports()); |
86 | 0 | RefPtr<MediaKeyMessageEvent> e = new MediaKeyMessageEvent(owner); |
87 | 0 | bool trusted = e->Init(owner); |
88 | 0 | e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); |
89 | 0 | aEventInitDict.mMessage.ComputeLengthAndData(); |
90 | 0 | e->mMessage = ArrayBuffer::Create(aGlobal.Context(), |
91 | 0 | aEventInitDict.mMessage.Length(), |
92 | 0 | aEventInitDict.mMessage.Data()); |
93 | 0 | if (!e->mMessage) { |
94 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
95 | 0 | return nullptr; |
96 | 0 | } |
97 | 0 | e->mMessageType = aEventInitDict.mMessageType; |
98 | 0 | e->SetTrusted(trusted); |
99 | 0 | e->SetComposed(aEventInitDict.mComposed); |
100 | 0 | return e.forget(); |
101 | 0 | } |
102 | | |
103 | | void |
104 | | MediaKeyMessageEvent::GetMessage(JSContext* cx, |
105 | | JS::MutableHandle<JSObject*> aMessage, |
106 | | ErrorResult& aRv) |
107 | 0 | { |
108 | 0 | if (!mMessage) { |
109 | 0 | mMessage = ArrayBuffer::Create(cx, |
110 | 0 | this, |
111 | 0 | mRawMessage.Length(), |
112 | 0 | mRawMessage.Elements()); |
113 | 0 | if (!mMessage) { |
114 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
115 | 0 | return; |
116 | 0 | } |
117 | 0 | mRawMessage.Clear(); |
118 | 0 | } |
119 | 0 | aMessage.set(mMessage); |
120 | 0 | } |
121 | | |
122 | | } // namespace dom |
123 | | } // namespace mozilla |