| 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 "JSMediaKeySystemConfiguration.h" |
| 26 | |
| 27 | #include "JSDOMConvertEnumeration.h" |
| 28 | #include "JSDOMConvertSequences.h" |
| 29 | #include "JSDOMConvertStrings.h" |
| 30 | #include "JSDOMGlobalObject.h" |
| 31 | #include "JSMediaKeySessionType.h" |
| 32 | #include "JSMediaKeySystemMediaCapability.h" |
| 33 | #include "JSMediaKeysRequirement.h" |
| 34 | #include <JavaScriptCore/JSArray.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <JavaScriptCore/ObjectConstructor.h> |
| 37 | |
| 38 | |
| 39 | namespace WebCore { |
| 40 | using namespace JSC; |
| 41 | |
| 42 | #if ENABLE(ENCRYPTED_MEDIA) |
| 43 | |
| 44 | template<> MediaKeySystemConfiguration convertDictionary<MediaKeySystemConfiguration>(ExecState& state, JSValue value) |
| 45 | { |
| 46 | VM& vm = state.vm(); |
| 47 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 48 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 49 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 50 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 51 | throwTypeError(&state, throwScope); |
| 52 | return { }; |
| 53 | } |
| 54 | MediaKeySystemConfiguration result; |
| 55 | JSValue audioCapabilitiesValue; |
| 56 | if (isNullOrUndefined) |
| 57 | audioCapabilitiesValue = jsUndefined(); |
| 58 | else { |
| 59 | audioCapabilitiesValue = object->get(&state, Identifier::fromString(&state, "audioCapabilities" )); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } |
| 62 | if (!audioCapabilitiesValue.isUndefined()) { |
| 63 | result.audioCapabilities = convert<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>(state, audioCapabilitiesValue); |
| 64 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 65 | } else |
| 66 | result.audioCapabilities = Converter<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>::ReturnType{ }; |
| 67 | JSValue distinctiveIdentifierValue; |
| 68 | if (isNullOrUndefined) |
| 69 | distinctiveIdentifierValue = jsUndefined(); |
| 70 | else { |
| 71 | distinctiveIdentifierValue = object->get(&state, Identifier::fromString(&state, "distinctiveIdentifier" )); |
| 72 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 73 | } |
| 74 | if (!distinctiveIdentifierValue.isUndefined()) { |
| 75 | result.distinctiveIdentifier = convert<IDLEnumeration<MediaKeysRequirement>>(state, distinctiveIdentifierValue); |
| 76 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 77 | } else |
| 78 | result.distinctiveIdentifier = MediaKeysRequirement::Optional; |
| 79 | JSValue initDataTypesValue; |
| 80 | if (isNullOrUndefined) |
| 81 | initDataTypesValue = jsUndefined(); |
| 82 | else { |
| 83 | initDataTypesValue = object->get(&state, Identifier::fromString(&state, "initDataTypes" )); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } |
| 86 | if (!initDataTypesValue.isUndefined()) { |
| 87 | result.initDataTypes = convert<IDLSequence<IDLDOMString>>(state, initDataTypesValue); |
| 88 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 89 | } else |
| 90 | result.initDataTypes = Converter<IDLSequence<IDLDOMString>>::ReturnType{ }; |
| 91 | JSValue labelValue; |
| 92 | if (isNullOrUndefined) |
| 93 | labelValue = jsUndefined(); |
| 94 | else { |
| 95 | labelValue = object->get(&state, Identifier::fromString(&state, "label" )); |
| 96 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 97 | } |
| 98 | if (!labelValue.isUndefined()) { |
| 99 | result.label = convert<IDLDOMString>(state, labelValue); |
| 100 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 101 | } else |
| 102 | result.label = emptyString(); |
| 103 | JSValue persistentStateValue; |
| 104 | if (isNullOrUndefined) |
| 105 | persistentStateValue = jsUndefined(); |
| 106 | else { |
| 107 | persistentStateValue = object->get(&state, Identifier::fromString(&state, "persistentState" )); |
| 108 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 109 | } |
| 110 | if (!persistentStateValue.isUndefined()) { |
| 111 | result.persistentState = convert<IDLEnumeration<MediaKeysRequirement>>(state, persistentStateValue); |
| 112 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 113 | } else |
| 114 | result.persistentState = MediaKeysRequirement::Optional; |
| 115 | JSValue sessionTypesValue; |
| 116 | if (isNullOrUndefined) |
| 117 | sessionTypesValue = jsUndefined(); |
| 118 | else { |
| 119 | sessionTypesValue = object->get(&state, Identifier::fromString(&state, "sessionTypes" )); |
| 120 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 121 | } |
| 122 | if (!sessionTypesValue.isUndefined()) { |
| 123 | result.sessionTypes = convert<IDLSequence<IDLEnumeration<MediaKeySessionType>>>(state, sessionTypesValue); |
| 124 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 125 | } |
| 126 | JSValue videoCapabilitiesValue; |
| 127 | if (isNullOrUndefined) |
| 128 | videoCapabilitiesValue = jsUndefined(); |
| 129 | else { |
| 130 | videoCapabilitiesValue = object->get(&state, Identifier::fromString(&state, "videoCapabilities" )); |
| 131 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 132 | } |
| 133 | if (!videoCapabilitiesValue.isUndefined()) { |
| 134 | result.videoCapabilities = convert<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>(state, videoCapabilitiesValue); |
| 135 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 136 | } else |
| 137 | result.videoCapabilities = Converter<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>::ReturnType{ }; |
| 138 | return result; |
| 139 | } |
| 140 | |
| 141 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const MediaKeySystemConfiguration& dictionary) |
| 142 | { |
| 143 | auto& vm = state.vm(); |
| 144 | |
| 145 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 146 | |
| 147 | auto audioCapabilitiesValue = toJS<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>(state, globalObject, dictionary.audioCapabilities); |
| 148 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "audioCapabilities" ), audioCapabilitiesValue); |
| 149 | auto distinctiveIdentifierValue = toJS<IDLEnumeration<MediaKeysRequirement>>(state, dictionary.distinctiveIdentifier); |
| 150 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "distinctiveIdentifier" ), distinctiveIdentifierValue); |
| 151 | auto initDataTypesValue = toJS<IDLSequence<IDLDOMString>>(state, globalObject, dictionary.initDataTypes); |
| 152 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "initDataTypes" ), initDataTypesValue); |
| 153 | auto labelValue = toJS<IDLDOMString>(state, dictionary.label); |
| 154 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "label" ), labelValue); |
| 155 | auto persistentStateValue = toJS<IDLEnumeration<MediaKeysRequirement>>(state, dictionary.persistentState); |
| 156 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "persistentState" ), persistentStateValue); |
| 157 | if (!IDLSequence<IDLEnumeration<MediaKeySessionType>>::isNullValue(dictionary.sessionTypes)) { |
| 158 | auto sessionTypesValue = toJS<IDLSequence<IDLEnumeration<MediaKeySessionType>>>(state, globalObject, IDLSequence<IDLEnumeration<MediaKeySessionType>>::extractValueFromNullable(dictionary.sessionTypes)); |
| 159 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "sessionTypes" ), sessionTypesValue); |
| 160 | } |
| 161 | auto videoCapabilitiesValue = toJS<IDLSequence<IDLDictionary<MediaKeySystemMediaCapability>>>(state, globalObject, dictionary.videoCapabilities); |
| 162 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "videoCapabilities" ), videoCapabilitiesValue); |
| 163 | return result; |
| 164 | } |
| 165 | |
| 166 | #endif |
| 167 | |
| 168 | } // namespace WebCore |
| 169 | |
| 170 | #endif // ENABLE(ENCRYPTED_MEDIA) |
| 171 | |