1 | /* |
2 | This file is part of the WebKit open source project. |
3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #if ENABLE(ENCRYPTED_MEDIA) |
24 | |
25 | #include "JSMediaKeys.h" |
26 | |
27 | #include "JSDOMBinding.h" |
28 | #include "JSDOMConstructorNotConstructable.h" |
29 | #include "JSDOMConvertBufferSource.h" |
30 | #include "JSDOMConvertEnumeration.h" |
31 | #include "JSDOMConvertInterface.h" |
32 | #include "JSDOMConvertUnion.h" |
33 | #include "JSDOMExceptionHandling.h" |
34 | #include "JSDOMGlobalObject.h" |
35 | #include "JSDOMOperation.h" |
36 | #include "JSDOMOperationReturningPromise.h" |
37 | #include "JSDOMWrapperCache.h" |
38 | #include "JSMediaKeySession.h" |
39 | #include "JSMediaKeySessionType.h" |
40 | #include "ScriptExecutionContext.h" |
41 | #include <JavaScriptCore/FunctionPrototype.h> |
42 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
43 | #include <JavaScriptCore/JSCInlines.h> |
44 | #include <wtf/GetPtr.h> |
45 | #include <wtf/PointerPreparations.h> |
46 | #include <wtf/URL.h> |
47 | #include <wtf/Variant.h> |
48 | |
49 | |
50 | namespace WebCore { |
51 | using namespace JSC; |
52 | |
53 | // Functions |
54 | |
55 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaKeysPrototypeFunctionCreateSession(JSC::ExecState*); |
56 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaKeysPrototypeFunctionSetServerCertificate(JSC::ExecState*); |
57 | |
58 | // Attributes |
59 | |
60 | JSC::EncodedJSValue jsMediaKeysConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
61 | bool setJSMediaKeysConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
62 | |
63 | class JSMediaKeysPrototype : public JSC::JSNonFinalObject { |
64 | public: |
65 | using Base = JSC::JSNonFinalObject; |
66 | static JSMediaKeysPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
67 | { |
68 | JSMediaKeysPrototype* ptr = new (NotNull, JSC::allocateCell<JSMediaKeysPrototype>(vm.heap)) JSMediaKeysPrototype(vm, globalObject, structure); |
69 | ptr->finishCreation(vm); |
70 | return ptr; |
71 | } |
72 | |
73 | DECLARE_INFO; |
74 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
75 | { |
76 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
77 | } |
78 | |
79 | private: |
80 | JSMediaKeysPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
81 | : JSC::JSNonFinalObject(vm, structure) |
82 | { |
83 | } |
84 | |
85 | void finishCreation(JSC::VM&); |
86 | }; |
87 | |
88 | using JSMediaKeysConstructor = JSDOMConstructorNotConstructable<JSMediaKeys>; |
89 | |
90 | template<> JSValue JSMediaKeysConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
91 | { |
92 | UNUSED_PARAM(vm); |
93 | return globalObject.functionPrototype(); |
94 | } |
95 | |
96 | template<> void JSMediaKeysConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
97 | { |
98 | putDirect(vm, vm.propertyNames->prototype, JSMediaKeys::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
99 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MediaKeys"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
100 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
101 | } |
102 | |
103 | template<> const ClassInfo JSMediaKeysConstructor::s_info = { "MediaKeys" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeysConstructor) }; |
104 | |
105 | /* Hash table for prototype */ |
106 | |
107 | static const HashTableValue JSMediaKeysPrototypeTableValues[] = |
108 | { |
109 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaKeysConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaKeysConstructor) } }, |
110 | { "createSession" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaKeysPrototypeFunctionCreateSession), (intptr_t) (0) } }, |
111 | { "setServerCertificate" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaKeysPrototypeFunctionSetServerCertificate), (intptr_t) (1) } }, |
112 | }; |
113 | |
114 | const ClassInfo JSMediaKeysPrototype::s_info = { "MediaKeysPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeysPrototype) }; |
115 | |
116 | void JSMediaKeysPrototype::finishCreation(VM& vm) |
117 | { |
118 | Base::finishCreation(vm); |
119 | reifyStaticProperties(vm, JSMediaKeys::info(), JSMediaKeysPrototypeTableValues, *this); |
120 | } |
121 | |
122 | const ClassInfo JSMediaKeys::s_info = { "MediaKeys" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaKeys) }; |
123 | |
124 | JSMediaKeys::JSMediaKeys(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MediaKeys>&& impl) |
125 | : JSDOMWrapper<MediaKeys>(structure, globalObject, WTFMove(impl)) |
126 | { |
127 | } |
128 | |
129 | void JSMediaKeys::finishCreation(VM& vm) |
130 | { |
131 | Base::finishCreation(vm); |
132 | ASSERT(inherits(vm, info())); |
133 | |
134 | } |
135 | |
136 | JSObject* JSMediaKeys::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
137 | { |
138 | return JSMediaKeysPrototype::create(vm, &globalObject, JSMediaKeysPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
139 | } |
140 | |
141 | JSObject* JSMediaKeys::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
142 | { |
143 | return getDOMPrototype<JSMediaKeys>(vm, globalObject); |
144 | } |
145 | |
146 | JSValue JSMediaKeys::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
147 | { |
148 | return getDOMConstructor<JSMediaKeysConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
149 | } |
150 | |
151 | void JSMediaKeys::destroy(JSC::JSCell* cell) |
152 | { |
153 | JSMediaKeys* thisObject = static_cast<JSMediaKeys*>(cell); |
154 | thisObject->JSMediaKeys::~JSMediaKeys(); |
155 | } |
156 | |
157 | template<> inline JSMediaKeys* IDLOperation<JSMediaKeys>::cast(ExecState& state) |
158 | { |
159 | return jsDynamicCast<JSMediaKeys*>(state.vm(), state.thisValue()); |
160 | } |
161 | |
162 | EncodedJSValue jsMediaKeysConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
163 | { |
164 | VM& vm = state->vm(); |
165 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
166 | auto* prototype = jsDynamicCast<JSMediaKeysPrototype*>(vm, JSValue::decode(thisValue)); |
167 | if (UNLIKELY(!prototype)) |
168 | return throwVMTypeError(state, throwScope); |
169 | return JSValue::encode(JSMediaKeys::getConstructor(state->vm(), prototype->globalObject())); |
170 | } |
171 | |
172 | bool setJSMediaKeysConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
173 | { |
174 | VM& vm = state->vm(); |
175 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
176 | auto* prototype = jsDynamicCast<JSMediaKeysPrototype*>(vm, JSValue::decode(thisValue)); |
177 | if (UNLIKELY(!prototype)) { |
178 | throwVMTypeError(state, throwScope); |
179 | return false; |
180 | } |
181 | // Shadowing a built-in constructor |
182 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
183 | } |
184 | |
185 | static inline JSC::EncodedJSValue jsMediaKeysPrototypeFunctionCreateSessionBody(JSC::ExecState* state, typename IDLOperation<JSMediaKeys>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
186 | { |
187 | UNUSED_PARAM(state); |
188 | UNUSED_PARAM(throwScope); |
189 | auto& impl = castedThis->wrapped(); |
190 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
191 | if (UNLIKELY(!context)) |
192 | return JSValue::encode(jsUndefined()); |
193 | auto sessionType = state->argument(0).isUndefined() ? MediaKeySessionType::Temporary : convert<IDLEnumeration<MediaKeySessionType>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(state, scope, 0, "sessionType" , "MediaKeys" , "createSession" , expectedEnumerationValues<MediaKeySessionType>()); }); |
194 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
195 | return JSValue::encode(toJS<IDLInterface<MediaKeySession>>(*state, *castedThis->globalObject(), throwScope, impl.createSession(*context, WTFMove(sessionType)))); |
196 | } |
197 | |
198 | EncodedJSValue JSC_HOST_CALL jsMediaKeysPrototypeFunctionCreateSession(ExecState* state) |
199 | { |
200 | return IDLOperation<JSMediaKeys>::call<jsMediaKeysPrototypeFunctionCreateSessionBody>(*state, "createSession" ); |
201 | } |
202 | |
203 | static inline JSC::EncodedJSValue jsMediaKeysPrototypeFunctionSetServerCertificateBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSMediaKeys>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
204 | { |
205 | UNUSED_PARAM(state); |
206 | UNUSED_PARAM(throwScope); |
207 | auto& impl = castedThis->wrapped(); |
208 | if (UNLIKELY(state->argumentCount() < 1)) |
209 | return throwVMError(state, throwScope, createNotEnoughArgumentsError(state)); |
210 | auto serverCertificate = convert<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>(*state, state->uncheckedArgument(0)); |
211 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
212 | impl.setServerCertificate(WTFMove(serverCertificate), WTFMove(promise)); |
213 | return JSValue::encode(jsUndefined()); |
214 | } |
215 | |
216 | EncodedJSValue JSC_HOST_CALL jsMediaKeysPrototypeFunctionSetServerCertificate(ExecState* state) |
217 | { |
218 | return IDLOperationReturningPromise<JSMediaKeys>::call<jsMediaKeysPrototypeFunctionSetServerCertificateBody, PromiseExecutionScope::WindowOnly>(*state, "setServerCertificate" ); |
219 | } |
220 | |
221 | void JSMediaKeys::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
222 | { |
223 | auto* thisObject = jsCast<JSMediaKeys*>(cell); |
224 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
225 | if (thisObject->scriptExecutionContext()) |
226 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
227 | Base::heapSnapshot(cell, builder); |
228 | } |
229 | |
230 | bool JSMediaKeysOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
231 | { |
232 | UNUSED_PARAM(handle); |
233 | UNUSED_PARAM(visitor); |
234 | UNUSED_PARAM(reason); |
235 | return false; |
236 | } |
237 | |
238 | void JSMediaKeysOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
239 | { |
240 | auto* jsMediaKeys = static_cast<JSMediaKeys*>(handle.slot()->asCell()); |
241 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
242 | uncacheWrapper(world, &jsMediaKeys->wrapped(), jsMediaKeys); |
243 | } |
244 | |
245 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MediaKeys>&& impl) |
246 | { |
247 | // If you hit this failure the interface definition has the ImplementationLacksVTable |
248 | // attribute. You should remove that attribute. If the class has subclasses |
249 | // that may be passed through this toJS() function you should use the SkipVTableValidation |
250 | // attribute to MediaKeys. |
251 | static_assert(!std::is_polymorphic<MediaKeys>::value, "MediaKeys is polymorphic but the IDL claims it is not" ); |
252 | return createWrapper<MediaKeys>(globalObject, WTFMove(impl)); |
253 | } |
254 | |
255 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MediaKeys& impl) |
256 | { |
257 | return wrap(state, globalObject, impl); |
258 | } |
259 | |
260 | MediaKeys* JSMediaKeys::toWrapped(JSC::VM& vm, JSC::JSValue value) |
261 | { |
262 | if (auto* wrapper = jsDynamicCast<JSMediaKeys*>(vm, value)) |
263 | return &wrapper->wrapped(); |
264 | return nullptr; |
265 | } |
266 | |
267 | } |
268 | |
269 | #endif // ENABLE(ENCRYPTED_MEDIA) |
270 | |