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(MEDIA_STREAM) |
24 | |
25 | #include "JSMediaDevices.h" |
26 | |
27 | #include "EventNames.h" |
28 | #include "JSDOMAttribute.h" |
29 | #include "JSDOMBinding.h" |
30 | #include "JSDOMConstructorNotConstructable.h" |
31 | #include "JSDOMConvertBoolean.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 "JSEventListener.h" |
39 | #include "JSMediaTrackConstraints.h" |
40 | #include "JSMediaTrackSupportedConstraints.h" |
41 | #include "RuntimeEnabledFeatures.h" |
42 | #include "ScriptExecutionContext.h" |
43 | #include "WebCoreJSClientData.h" |
44 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
45 | #include <JavaScriptCore/JSCInlines.h> |
46 | #include <JavaScriptCore/JSString.h> |
47 | #include <wtf/GetPtr.h> |
48 | #include <wtf/PointerPreparations.h> |
49 | #include <wtf/URL.h> |
50 | #include <wtf/Variant.h> |
51 | |
52 | |
53 | namespace WebCore { |
54 | using namespace JSC; |
55 | |
56 | #if ENABLE(MEDIA_STREAM) |
57 | |
58 | String convertEnumerationToString(MediaDevices::DisplayCaptureSurfaceType enumerationValue) |
59 | { |
60 | static const NeverDestroyed<String> values[] = { |
61 | MAKE_STATIC_STRING_IMPL("monitor" ), |
62 | MAKE_STATIC_STRING_IMPL("window" ), |
63 | MAKE_STATIC_STRING_IMPL("application" ), |
64 | MAKE_STATIC_STRING_IMPL("browser" ), |
65 | }; |
66 | static_assert(static_cast<size_t>(MediaDevices::DisplayCaptureSurfaceType::Monitor) == 0, "MediaDevices::DisplayCaptureSurfaceType::Monitor is not 0 as expected" ); |
67 | static_assert(static_cast<size_t>(MediaDevices::DisplayCaptureSurfaceType::Window) == 1, "MediaDevices::DisplayCaptureSurfaceType::Window is not 1 as expected" ); |
68 | static_assert(static_cast<size_t>(MediaDevices::DisplayCaptureSurfaceType::Application) == 2, "MediaDevices::DisplayCaptureSurfaceType::Application is not 2 as expected" ); |
69 | static_assert(static_cast<size_t>(MediaDevices::DisplayCaptureSurfaceType::Browser) == 3, "MediaDevices::DisplayCaptureSurfaceType::Browser is not 3 as expected" ); |
70 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
71 | return values[static_cast<size_t>(enumerationValue)]; |
72 | } |
73 | |
74 | template<> JSString* convertEnumerationToJS(ExecState& state, MediaDevices::DisplayCaptureSurfaceType enumerationValue) |
75 | { |
76 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
77 | } |
78 | |
79 | template<> Optional<MediaDevices::DisplayCaptureSurfaceType> parseEnumeration<MediaDevices::DisplayCaptureSurfaceType>(ExecState& state, JSValue value) |
80 | { |
81 | auto stringValue = value.toWTFString(&state); |
82 | if (stringValue == "monitor" ) |
83 | return MediaDevices::DisplayCaptureSurfaceType::Monitor; |
84 | if (stringValue == "window" ) |
85 | return MediaDevices::DisplayCaptureSurfaceType::Window; |
86 | if (stringValue == "application" ) |
87 | return MediaDevices::DisplayCaptureSurfaceType::Application; |
88 | if (stringValue == "browser" ) |
89 | return MediaDevices::DisplayCaptureSurfaceType::Browser; |
90 | return WTF::nullopt; |
91 | } |
92 | |
93 | template<> const char* expectedEnumerationValues<MediaDevices::DisplayCaptureSurfaceType>() |
94 | { |
95 | return "\"monitor\", \"window\", \"application\", \"browser\"" ; |
96 | } |
97 | |
98 | #endif |
99 | |
100 | #if ENABLE(MEDIA_STREAM) |
101 | |
102 | template<> MediaDevices::StreamConstraints convertDictionary<MediaDevices::StreamConstraints>(ExecState& state, JSValue value) |
103 | { |
104 | VM& vm = state.vm(); |
105 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
106 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
107 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
108 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
109 | throwTypeError(&state, throwScope); |
110 | return { }; |
111 | } |
112 | MediaDevices::StreamConstraints result; |
113 | JSValue audioValue; |
114 | if (isNullOrUndefined) |
115 | audioValue = jsUndefined(); |
116 | else { |
117 | audioValue = object->get(&state, Identifier::fromString(&state, "audio" )); |
118 | RETURN_IF_EXCEPTION(throwScope, { }); |
119 | } |
120 | if (!audioValue.isUndefined()) { |
121 | result.audio = convert<IDLUnion<IDLBoolean, IDLDictionary<MediaTrackConstraints>>>(state, audioValue); |
122 | RETURN_IF_EXCEPTION(throwScope, { }); |
123 | } else |
124 | result.audio = false; |
125 | JSValue videoValue; |
126 | if (isNullOrUndefined) |
127 | videoValue = jsUndefined(); |
128 | else { |
129 | videoValue = object->get(&state, Identifier::fromString(&state, "video" )); |
130 | RETURN_IF_EXCEPTION(throwScope, { }); |
131 | } |
132 | if (!videoValue.isUndefined()) { |
133 | result.video = convert<IDLUnion<IDLBoolean, IDLDictionary<MediaTrackConstraints>>>(state, videoValue); |
134 | RETURN_IF_EXCEPTION(throwScope, { }); |
135 | } else |
136 | result.video = false; |
137 | return result; |
138 | } |
139 | |
140 | #endif |
141 | |
142 | // Functions |
143 | |
144 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionEnumerateDevices(JSC::ExecState*); |
145 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetSupportedConstraints(JSC::ExecState*); |
146 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetUserMedia(JSC::ExecState*); |
147 | JSC::EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetDisplayMedia(JSC::ExecState*); |
148 | |
149 | // Attributes |
150 | |
151 | JSC::EncodedJSValue jsMediaDevicesConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
152 | bool setJSMediaDevicesConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
153 | JSC::EncodedJSValue jsMediaDevicesOndevicechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
154 | bool setJSMediaDevicesOndevicechange(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
155 | |
156 | class JSMediaDevicesPrototype : public JSC::JSNonFinalObject { |
157 | public: |
158 | using Base = JSC::JSNonFinalObject; |
159 | static JSMediaDevicesPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
160 | { |
161 | JSMediaDevicesPrototype* ptr = new (NotNull, JSC::allocateCell<JSMediaDevicesPrototype>(vm.heap)) JSMediaDevicesPrototype(vm, globalObject, structure); |
162 | ptr->finishCreation(vm); |
163 | return ptr; |
164 | } |
165 | |
166 | DECLARE_INFO; |
167 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
168 | { |
169 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
170 | } |
171 | |
172 | private: |
173 | JSMediaDevicesPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
174 | : JSC::JSNonFinalObject(vm, structure) |
175 | { |
176 | } |
177 | |
178 | void finishCreation(JSC::VM&); |
179 | }; |
180 | |
181 | using JSMediaDevicesConstructor = JSDOMConstructorNotConstructable<JSMediaDevices>; |
182 | |
183 | template<> JSValue JSMediaDevicesConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
184 | { |
185 | return JSEventTarget::getConstructor(vm, &globalObject); |
186 | } |
187 | |
188 | template<> void JSMediaDevicesConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
189 | { |
190 | putDirect(vm, vm.propertyNames->prototype, JSMediaDevices::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
191 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MediaDevices"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
192 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
193 | } |
194 | |
195 | template<> const ClassInfo JSMediaDevicesConstructor::s_info = { "MediaDevices" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaDevicesConstructor) }; |
196 | |
197 | /* Hash table for prototype */ |
198 | |
199 | static const HashTableValue JSMediaDevicesPrototypeTableValues[] = |
200 | { |
201 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaDevicesConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaDevicesConstructor) } }, |
202 | { "ondevicechange" , static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaDevicesOndevicechange), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaDevicesOndevicechange) } }, |
203 | { "enumerateDevices" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaDevicesPrototypeFunctionEnumerateDevices), (intptr_t) (0) } }, |
204 | { "getSupportedConstraints" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaDevicesPrototypeFunctionGetSupportedConstraints), (intptr_t) (0) } }, |
205 | { "getUserMedia" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaDevicesPrototypeFunctionGetUserMedia), (intptr_t) (0) } }, |
206 | { "getDisplayMedia" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaDevicesPrototypeFunctionGetDisplayMedia), (intptr_t) (0) } }, |
207 | }; |
208 | |
209 | const ClassInfo JSMediaDevicesPrototype::s_info = { "MediaDevicesPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaDevicesPrototype) }; |
210 | |
211 | void JSMediaDevicesPrototype::finishCreation(VM& vm) |
212 | { |
213 | Base::finishCreation(vm); |
214 | reifyStaticProperties(vm, JSMediaDevices::info(), JSMediaDevicesPrototypeTableValues, *this); |
215 | bool hasDisabledRuntimeProperties = false; |
216 | if (!RuntimeEnabledFeatures::sharedFeatures().screenCaptureEnabled()) { |
217 | hasDisabledRuntimeProperties = true; |
218 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("getDisplayMedia" ), strlen("getDisplayMedia" )); |
219 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
220 | JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName); |
221 | } |
222 | if (hasDisabledRuntimeProperties && structure()->isDictionary()) |
223 | flattenDictionaryObject(vm); |
224 | putDirect(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().getUserMediaPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsMediaDevicesPrototypeFunctionGetUserMedia), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
225 | } |
226 | |
227 | const ClassInfo JSMediaDevices::s_info = { "MediaDevices" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaDevices) }; |
228 | |
229 | JSMediaDevices::JSMediaDevices(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MediaDevices>&& impl) |
230 | : JSEventTarget(structure, globalObject, WTFMove(impl)) |
231 | { |
232 | } |
233 | |
234 | void JSMediaDevices::finishCreation(VM& vm) |
235 | { |
236 | Base::finishCreation(vm); |
237 | ASSERT(inherits(vm, info())); |
238 | |
239 | } |
240 | |
241 | JSObject* JSMediaDevices::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
242 | { |
243 | return JSMediaDevicesPrototype::create(vm, &globalObject, JSMediaDevicesPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject))); |
244 | } |
245 | |
246 | JSObject* JSMediaDevices::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
247 | { |
248 | return getDOMPrototype<JSMediaDevices>(vm, globalObject); |
249 | } |
250 | |
251 | JSValue JSMediaDevices::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
252 | { |
253 | return getDOMConstructor<JSMediaDevicesConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
254 | } |
255 | |
256 | template<> inline JSMediaDevices* IDLAttribute<JSMediaDevices>::cast(ExecState& state, EncodedJSValue thisValue) |
257 | { |
258 | return jsDynamicCast<JSMediaDevices*>(state.vm(), JSValue::decode(thisValue)); |
259 | } |
260 | |
261 | template<> inline JSMediaDevices* IDLOperation<JSMediaDevices>::cast(ExecState& state) |
262 | { |
263 | return jsDynamicCast<JSMediaDevices*>(state.vm(), state.thisValue()); |
264 | } |
265 | |
266 | EncodedJSValue jsMediaDevicesConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
267 | { |
268 | VM& vm = state->vm(); |
269 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
270 | auto* prototype = jsDynamicCast<JSMediaDevicesPrototype*>(vm, JSValue::decode(thisValue)); |
271 | if (UNLIKELY(!prototype)) |
272 | return throwVMTypeError(state, throwScope); |
273 | return JSValue::encode(JSMediaDevices::getConstructor(state->vm(), prototype->globalObject())); |
274 | } |
275 | |
276 | bool setJSMediaDevicesConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
277 | { |
278 | VM& vm = state->vm(); |
279 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
280 | auto* prototype = jsDynamicCast<JSMediaDevicesPrototype*>(vm, JSValue::decode(thisValue)); |
281 | if (UNLIKELY(!prototype)) { |
282 | throwVMTypeError(state, throwScope); |
283 | return false; |
284 | } |
285 | // Shadowing a built-in constructor |
286 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
287 | } |
288 | |
289 | static inline JSValue jsMediaDevicesOndevicechangeGetter(ExecState& state, JSMediaDevices& thisObject, ThrowScope& throwScope) |
290 | { |
291 | UNUSED_PARAM(throwScope); |
292 | UNUSED_PARAM(state); |
293 | return eventHandlerAttribute(thisObject.wrapped(), eventNames().devicechangeEvent, worldForDOMObject(thisObject)); |
294 | } |
295 | |
296 | EncodedJSValue jsMediaDevicesOndevicechange(ExecState* state, EncodedJSValue thisValue, PropertyName) |
297 | { |
298 | return IDLAttribute<JSMediaDevices>::get<jsMediaDevicesOndevicechangeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "ondevicechange" ); |
299 | } |
300 | |
301 | static inline bool setJSMediaDevicesOndevicechangeSetter(ExecState& state, JSMediaDevices& thisObject, JSValue value, ThrowScope& throwScope) |
302 | { |
303 | UNUSED_PARAM(throwScope); |
304 | setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().devicechangeEvent, value); |
305 | return true; |
306 | } |
307 | |
308 | bool setJSMediaDevicesOndevicechange(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
309 | { |
310 | return IDLAttribute<JSMediaDevices>::set<setJSMediaDevicesOndevicechangeSetter>(*state, thisValue, encodedValue, "ondevicechange" ); |
311 | } |
312 | |
313 | static inline JSC::EncodedJSValue jsMediaDevicesPrototypeFunctionEnumerateDevicesBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSMediaDevices>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
314 | { |
315 | UNUSED_PARAM(state); |
316 | UNUSED_PARAM(throwScope); |
317 | auto& impl = castedThis->wrapped(); |
318 | impl.enumerateDevices(WTFMove(promise)); |
319 | return JSValue::encode(jsUndefined()); |
320 | } |
321 | |
322 | EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionEnumerateDevices(ExecState* state) |
323 | { |
324 | return IDLOperationReturningPromise<JSMediaDevices>::call<jsMediaDevicesPrototypeFunctionEnumerateDevicesBody, PromiseExecutionScope::WindowOnly>(*state, "enumerateDevices" ); |
325 | } |
326 | |
327 | static inline JSC::EncodedJSValue jsMediaDevicesPrototypeFunctionGetSupportedConstraintsBody(JSC::ExecState* state, typename IDLOperation<JSMediaDevices>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
328 | { |
329 | UNUSED_PARAM(state); |
330 | UNUSED_PARAM(throwScope); |
331 | auto& impl = castedThis->wrapped(); |
332 | return JSValue::encode(toJS<IDLDictionary<MediaTrackSupportedConstraints>>(*state, *castedThis->globalObject(), impl.getSupportedConstraints())); |
333 | } |
334 | |
335 | EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetSupportedConstraints(ExecState* state) |
336 | { |
337 | return IDLOperation<JSMediaDevices>::call<jsMediaDevicesPrototypeFunctionGetSupportedConstraintsBody>(*state, "getSupportedConstraints" ); |
338 | } |
339 | |
340 | static inline JSC::EncodedJSValue jsMediaDevicesPrototypeFunctionGetUserMediaBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSMediaDevices>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
341 | { |
342 | UNUSED_PARAM(state); |
343 | UNUSED_PARAM(throwScope); |
344 | auto& impl = castedThis->wrapped(); |
345 | auto constraints = convert<IDLDictionary<MediaDevices::StreamConstraints>>(*state, state->argument(0)); |
346 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
347 | impl.getUserMedia(WTFMove(constraints), WTFMove(promise)); |
348 | return JSValue::encode(jsUndefined()); |
349 | } |
350 | |
351 | EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetUserMedia(ExecState* state) |
352 | { |
353 | return IDLOperationReturningPromise<JSMediaDevices>::call<jsMediaDevicesPrototypeFunctionGetUserMediaBody, PromiseExecutionScope::WindowOnly>(*state, "getUserMedia" ); |
354 | } |
355 | |
356 | static inline JSC::EncodedJSValue jsMediaDevicesPrototypeFunctionGetDisplayMediaBody(JSC::ExecState* state, typename IDLOperationReturningPromise<JSMediaDevices>::ClassParameter castedThis, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
357 | { |
358 | UNUSED_PARAM(state); |
359 | UNUSED_PARAM(throwScope); |
360 | auto& impl = castedThis->wrapped(); |
361 | auto constraints = convert<IDLDictionary<MediaDevices::StreamConstraints>>(*state, state->argument(0)); |
362 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
363 | impl.getDisplayMedia(WTFMove(constraints), WTFMove(promise)); |
364 | return JSValue::encode(jsUndefined()); |
365 | } |
366 | |
367 | EncodedJSValue JSC_HOST_CALL jsMediaDevicesPrototypeFunctionGetDisplayMedia(ExecState* state) |
368 | { |
369 | return IDLOperationReturningPromise<JSMediaDevices>::call<jsMediaDevicesPrototypeFunctionGetDisplayMediaBody, PromiseExecutionScope::WindowOnly>(*state, "getDisplayMedia" ); |
370 | } |
371 | |
372 | void JSMediaDevices::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
373 | { |
374 | auto* thisObject = jsCast<JSMediaDevices*>(cell); |
375 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
376 | if (thisObject->scriptExecutionContext()) |
377 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
378 | Base::heapSnapshot(cell, builder); |
379 | } |
380 | |
381 | bool JSMediaDevicesOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) |
382 | { |
383 | auto* jsMediaDevices = jsCast<JSMediaDevices*>(handle.slot()->asCell()); |
384 | if (jsMediaDevices->wrapped().hasPendingActivity()) { |
385 | if (UNLIKELY(reason)) |
386 | *reason = "ActiveDOMObject with pending activity" ; |
387 | return true; |
388 | } |
389 | if (jsMediaDevices->wrapped().isFiringEventListeners()) { |
390 | if (UNLIKELY(reason)) |
391 | *reason = "EventTarget firing event listeners" ; |
392 | return true; |
393 | } |
394 | UNUSED_PARAM(visitor); |
395 | UNUSED_PARAM(reason); |
396 | return false; |
397 | } |
398 | |
399 | void JSMediaDevicesOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context) |
400 | { |
401 | auto* jsMediaDevices = static_cast<JSMediaDevices*>(handle.slot()->asCell()); |
402 | auto& world = *static_cast<DOMWrapperWorld*>(context); |
403 | uncacheWrapper(world, &jsMediaDevices->wrapped(), jsMediaDevices); |
404 | } |
405 | |
406 | #if ENABLE(BINDING_INTEGRITY) |
407 | #if PLATFORM(WIN) |
408 | #pragma warning(disable: 4483) |
409 | extern "C" { extern void (*const __identifier("??_7MediaDevices@WebCore@@6B@" )[])(); } |
410 | #else |
411 | extern "C" { extern void* _ZTVN7WebCore12MediaDevicesE[]; } |
412 | #endif |
413 | #endif |
414 | |
415 | JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MediaDevices>&& impl) |
416 | { |
417 | |
418 | #if ENABLE(BINDING_INTEGRITY) |
419 | void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr())); |
420 | #if PLATFORM(WIN) |
421 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7MediaDevices@WebCore@@6B@" )); |
422 | #else |
423 | void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore12MediaDevicesE[2]); |
424 | #endif |
425 | |
426 | // If this fails MediaDevices does not have a vtable, so you need to add the |
427 | // ImplementationLacksVTable attribute to the interface definition |
428 | static_assert(std::is_polymorphic<MediaDevices>::value, "MediaDevices is not polymorphic" ); |
429 | |
430 | // If you hit this assertion you either have a use after free bug, or |
431 | // MediaDevices has subclasses. If MediaDevices has subclasses that get passed |
432 | // to toJS() we currently require MediaDevices you to opt out of binding hardening |
433 | // by adding the SkipVTableValidation attribute to the interface IDL definition |
434 | RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer); |
435 | #endif |
436 | return createWrapper<MediaDevices>(globalObject, WTFMove(impl)); |
437 | } |
438 | |
439 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MediaDevices& impl) |
440 | { |
441 | return wrap(state, globalObject, impl); |
442 | } |
443 | |
444 | MediaDevices* JSMediaDevices::toWrapped(JSC::VM& vm, JSC::JSValue value) |
445 | { |
446 | if (auto* wrapper = jsDynamicCast<JSMediaDevices*>(vm, value)) |
447 | return &wrapper->wrapped(); |
448 | return nullptr; |
449 | } |
450 | |
451 | } |
452 | |
453 | #endif // ENABLE(MEDIA_STREAM) |
454 | |