Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / mediastream / RTCSessionDescription.cpp
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 #include "modules/mediastream/RTCSessionDescription.h"
33
34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/ExceptionState.h"
36 #include "core/dom/ExceptionCode.h"
37
38 namespace blink {
39
40 static bool verifyType(const String& type)
41 {
42     return type == "offer" || type == "pranswer" || type == "answer";
43 }
44
45 static String constructIllegalTypeExceptionMessage(const String& type)
46 {
47     return "Illegal value of attribute 'type' : " + type;
48 }
49
50 RTCSessionDescription* RTCSessionDescription::create(const Dictionary& descriptionInitDict, ExceptionState& exceptionState)
51 {
52     String type;
53     bool ok = DictionaryHelper::get(descriptionInitDict, "type", type);
54     if (ok && !verifyType(type)) {
55         exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
56         return nullptr;
57     }
58
59     String sdp;
60     DictionaryHelper::get(descriptionInitDict, "sdp", sdp);
61
62     return new RTCSessionDescription(WebRTCSessionDescription(type, sdp));
63 }
64
65 RTCSessionDescription* RTCSessionDescription::create(WebRTCSessionDescription webSessionDescription)
66 {
67     return new RTCSessionDescription(webSessionDescription);
68 }
69
70 RTCSessionDescription::RTCSessionDescription(WebRTCSessionDescription webSessionDescription)
71     : m_webSessionDescription(webSessionDescription)
72 {
73     ScriptWrappable::init(this);
74 }
75
76 String RTCSessionDescription::type()
77 {
78     return m_webSessionDescription.type();
79 }
80
81 void RTCSessionDescription::setType(const String& type, ExceptionState& exceptionState)
82 {
83     if (verifyType(type))
84         m_webSessionDescription.setType(type);
85     else
86         exceptionState.throwDOMException(TypeMismatchError, constructIllegalTypeExceptionMessage(type));
87 }
88
89 String RTCSessionDescription::sdp()
90 {
91     return m_webSessionDescription.sdp();
92 }
93
94 void RTCSessionDescription::setSdp(const String& sdp)
95 {
96     m_webSessionDescription.setSDP(sdp);
97 }
98
99 WebRTCSessionDescription RTCSessionDescription::webSessionDescription()
100 {
101     return m_webSessionDescription;
102 }
103
104 } // namespace blink