Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MediaKeysRequestStatus.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "MediaKeysRequestStatusBinding.h"
5 : #include "jsapi.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/NonRefcountedDOMObject.h"
9 : #include "mozilla/dom/ScriptSettings.h"
10 : #include "mozilla/dom/SimpleGlobalObject.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 : namespace MediaKeySystemStatusValues {
16 : extern const EnumEntry strings[7] = {
17 : {"available", 9},
18 : {"api-disabled", 12},
19 : {"cdm-disabled", 12},
20 : {"cdm-not-supported", 17},
21 : {"cdm-not-installed", 17},
22 : {"cdm-created", 11},
23 : { nullptr, 0 }
24 : };
25 : } // namespace MediaKeySystemStatusValues
26 :
27 : bool
28 0 : ToJSValue(JSContext* aCx, MediaKeySystemStatus aArgument, JS::MutableHandle<JS::Value> aValue)
29 : {
30 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaKeySystemStatusValues::strings));
31 : JSString* resultStr =
32 0 : JS_NewStringCopyN(aCx, MediaKeySystemStatusValues::strings[uint32_t(aArgument)].value,
33 0 : MediaKeySystemStatusValues::strings[uint32_t(aArgument)].length);
34 0 : if (!resultStr) {
35 0 : return false;
36 : }
37 0 : aValue.setString(resultStr);
38 0 : return true;
39 : }
40 :
41 :
42 :
43 0 : RequestMediaKeySystemAccessNotification::RequestMediaKeySystemAccessNotification()
44 : {
45 : // Safe to pass a null context if we pass a null value
46 0 : Init(nullptr, JS::NullHandleValue);
47 0 : }
48 :
49 :
50 :
51 : bool
52 0 : RequestMediaKeySystemAccessNotification::InitIds(JSContext* cx, RequestMediaKeySystemAccessNotificationAtoms* atomsCache)
53 : {
54 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
55 :
56 : // Initialize these in reverse order so that any failure leaves the first one
57 : // uninitialized.
58 0 : if (!atomsCache->status_id.init(cx, "status") ||
59 0 : !atomsCache->keySystem_id.init(cx, "keySystem")) {
60 0 : return false;
61 : }
62 0 : return true;
63 : }
64 :
65 : bool
66 0 : RequestMediaKeySystemAccessNotification::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
67 : {
68 : // Passing a null JSContext is OK only if we're initing from null,
69 : // Since in that case we will not have to do any property gets
70 : // Also evaluate isNullOrUndefined in order to avoid false-positive
71 : // checkers by static analysis tools
72 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
73 0 : RequestMediaKeySystemAccessNotificationAtoms* atomsCache = nullptr;
74 0 : if (cx) {
75 0 : atomsCache = GetAtomCache<RequestMediaKeySystemAccessNotificationAtoms>(cx);
76 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
77 0 : return false;
78 : }
79 : }
80 :
81 0 : if (!IsConvertibleToDictionary(val)) {
82 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
83 : }
84 :
85 0 : bool isNull = val.isNullOrUndefined();
86 : // We only need these if !isNull, in which case we have |cx|.
87 0 : Maybe<JS::Rooted<JSObject *> > object;
88 0 : Maybe<JS::Rooted<JS::Value> > temp;
89 0 : if (!isNull) {
90 0 : MOZ_ASSERT(cx);
91 0 : object.emplace(cx, &val.toObject());
92 0 : temp.emplace(cx);
93 : }
94 0 : if (!isNull) {
95 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->keySystem_id, temp.ptr())) {
96 0 : return false;
97 : }
98 : }
99 0 : if (!isNull && !temp->isUndefined()) {
100 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mKeySystem)) {
101 0 : return false;
102 : }
103 0 : mIsAnyMemberPresent = true;
104 0 : } else if (cx) {
105 : // Don't error out if we have no cx. In that
106 : // situation the caller is default-constructing us and we'll
107 : // just assume they know what they're doing.
108 0 : return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
109 0 : "'keySystem' member of RequestMediaKeySystemAccessNotification");
110 : }
111 :
112 0 : if (!isNull) {
113 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->status_id, temp.ptr())) {
114 0 : return false;
115 : }
116 : }
117 0 : if (!isNull && !temp->isUndefined()) {
118 : {
119 : int index;
120 0 : if (!FindEnumStringIndex<true>(cx, temp.ref(), MediaKeySystemStatusValues::strings, "MediaKeySystemStatus", "'status' member of RequestMediaKeySystemAccessNotification", &index)) {
121 0 : return false;
122 : }
123 0 : MOZ_ASSERT(index >= 0);
124 0 : mStatus = static_cast<MediaKeySystemStatus>(index);
125 : }
126 0 : mIsAnyMemberPresent = true;
127 0 : } else if (cx) {
128 : // Don't error out if we have no cx. In that
129 : // situation the caller is default-constructing us and we'll
130 : // just assume they know what they're doing.
131 0 : return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
132 0 : "'status' member of RequestMediaKeySystemAccessNotification");
133 : }
134 0 : return true;
135 : }
136 :
137 : bool
138 0 : RequestMediaKeySystemAccessNotification::Init(const nsAString& aJSON)
139 : {
140 0 : AutoJSAPI jsapi;
141 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
142 0 : if (!cleanGlobal) {
143 0 : return false;
144 : }
145 0 : if (!jsapi.Init(cleanGlobal)) {
146 0 : return false;
147 : }
148 0 : JSContext* cx = jsapi.cx();
149 0 : JS::Rooted<JS::Value> json(cx);
150 0 : bool ok = ParseJSON(cx, aJSON, &json);
151 0 : NS_ENSURE_TRUE(ok, false);
152 0 : return Init(cx, json);
153 : }
154 :
155 : bool
156 0 : RequestMediaKeySystemAccessNotification::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
157 : {
158 0 : RequestMediaKeySystemAccessNotificationAtoms* atomsCache = GetAtomCache<RequestMediaKeySystemAccessNotificationAtoms>(cx);
159 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
160 0 : return false;
161 : }
162 :
163 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
164 0 : if (!obj) {
165 0 : return false;
166 : }
167 0 : rval.set(JS::ObjectValue(*obj));
168 :
169 : do {
170 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
171 0 : JS::Rooted<JS::Value> temp(cx);
172 0 : nsString const & currentValue = mKeySystem;
173 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
174 0 : return false;
175 : }
176 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->keySystem_id, temp, JSPROP_ENUMERATE)) {
177 0 : return false;
178 : }
179 0 : break;
180 : } while(0);
181 :
182 : do {
183 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
184 0 : JS::Rooted<JS::Value> temp(cx);
185 0 : MediaKeySystemStatus const & currentValue = mStatus;
186 0 : if (!ToJSValue(cx, currentValue, &temp)) {
187 0 : return false;
188 : }
189 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->status_id, temp, JSPROP_ENUMERATE)) {
190 0 : return false;
191 : }
192 0 : break;
193 : } while(0);
194 :
195 0 : return true;
196 : }
197 :
198 : bool
199 0 : RequestMediaKeySystemAccessNotification::ToJSON(nsAString& aJSON) const
200 : {
201 0 : AutoJSAPI jsapi;
202 0 : jsapi.Init();
203 0 : JSContext *cx = jsapi.cx();
204 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
205 : // because we'll only be creating objects, in ways that have no
206 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
207 : // which likewise guarantees no side-effects for the sorts of
208 : // things we will pass it.
209 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
210 0 : JS::Rooted<JS::Value> val(cx);
211 0 : if (!ToObjectInternal(cx, &val)) {
212 0 : return false;
213 : }
214 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
215 0 : return StringifyToJSON(cx, obj, aJSON);
216 : }
217 :
218 : void
219 0 : RequestMediaKeySystemAccessNotification::TraceDictionary(JSTracer* trc)
220 : {
221 0 : }
222 :
223 : RequestMediaKeySystemAccessNotification&
224 0 : RequestMediaKeySystemAccessNotification::operator=(const RequestMediaKeySystemAccessNotification& aOther)
225 : {
226 0 : mKeySystem = aOther.mKeySystem;
227 0 : mStatus = aOther.mStatus;
228 0 : return *this;
229 : }
230 :
231 : namespace binding_detail {
232 : } // namespace binding_detail
233 :
234 :
235 : } // namespace dom
236 : } // namespace mozilla
|