2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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
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.
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.
32 #include "modules/mediastream/RTCSessionDescription.h"
34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/ExceptionState.h"
36 #include "core/dom/ExceptionCode.h"
40 static bool verifyType(const String& type)
42 return type == "offer" || type == "pranswer" || type == "answer";
45 static String constructIllegalTypeExceptionMessage(const String& type)
47 return "Illegal value of attribute 'type' : " + type;
50 RTCSessionDescription* RTCSessionDescription::create(const Dictionary& descriptionInitDict, ExceptionState& exceptionState)
53 bool ok = DictionaryHelper::get(descriptionInitDict, "type", type);
54 if (ok && !verifyType(type)) {
55 exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
60 DictionaryHelper::get(descriptionInitDict, "sdp", sdp);
62 return new RTCSessionDescription(WebRTCSessionDescription(type, sdp));
65 RTCSessionDescription* RTCSessionDescription::create(WebRTCSessionDescription webSessionDescription)
67 return new RTCSessionDescription(webSessionDescription);
70 RTCSessionDescription::RTCSessionDescription(WebRTCSessionDescription webSessionDescription)
71 : m_webSessionDescription(webSessionDescription)
75 String RTCSessionDescription::type()
77 return m_webSessionDescription.type();
80 void RTCSessionDescription::setType(const String& type, ExceptionState& exceptionState)
83 m_webSessionDescription.setType(type);
85 exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
88 String RTCSessionDescription::sdp()
90 return m_webSessionDescription.sdp();
93 void RTCSessionDescription::setSdp(const String& sdp)
95 m_webSessionDescription.setSDP(sdp);
98 WebRTCSessionDescription RTCSessionDescription::webSessionDescription()
100 return m_webSessionDescription;