1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * 3. Neither the name of Google Inc. nor the names of its contributors 15 * may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "config.h" 32 33 #include "modules/mediastream/RTCSessionDescription.h" 34 35 #include "bindings/v8/Dictionary.h" 36 #include "bindings/v8/ExceptionState.h" 37 #include "core/dom/ExceptionCode.h" 38 39 namespace WebCore { 40 41 static bool verifyType(const String& type) 42 { 43 return type == "offer" || type == "pranswer" || type == "answer"; 44 } 45 46 static String constructIllegalTypeExceptionMessage(const String& type) 47 { 48 return "Illegal value of attribute 'type' : " + type; 49 } 50 51 PassRefPtr<RTCSessionDescription> RTCSessionDescription::create(const Dictionary& descriptionInitDict, ExceptionState& exceptionState) 52 { 53 String type; 54 bool ok = descriptionInitDict.get("type", type); 55 if (ok && !verifyType(type)) { 56 exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type)); 57 return 0; 58 } 59 60 String sdp; 61 descriptionInitDict.get("sdp", sdp); 62 63 return adoptRef(new RTCSessionDescription(blink::WebRTCSessionDescription(type, sdp))); 64 } 65 66 PassRefPtr<RTCSessionDescription> RTCSessionDescription::create(blink::WebRTCSessionDescription webSessionDescription) 67 { 68 return adoptRef(new RTCSessionDescription(webSessionDescription)); 69 } 70 71 RTCSessionDescription::RTCSessionDescription(blink::WebRTCSessionDescription webSessionDescription) 72 : m_webSessionDescription(webSessionDescription) 73 { 74 ScriptWrappable::init(this); 75 } 76 77 String RTCSessionDescription::type() 78 { 79 return m_webSessionDescription.type(); 80 } 81 82 void RTCSessionDescription::setType(const String& type, ExceptionState& exceptionState) 83 { 84 if (verifyType(type)) 85 m_webSessionDescription.setType(type); 86 else 87 exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type)); 88 } 89 90 String RTCSessionDescription::sdp() 91 { 92 return m_webSessionDescription.sdp(); 93 } 94 95 void RTCSessionDescription::setSdp(const String& sdp) 96 { 97 m_webSessionDescription.setSDP(sdp); 98 } 99 100 blink::WebRTCSessionDescription RTCSessionDescription::webSessionDescription() 101 { 102 return m_webSessionDescription; 103 } 104 105 } // namespace WebCore 106