Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: Source/modules/mediastream/UserMediaRequest.cpp

Issue 173893009: MediaStream API: Update getUserMedia to match the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/mediastream/NavigatorMediaStream.idl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Ericsson AB. All rights reserved. 2 * Copyright (C) 2011 Ericsson AB. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 16 matching lines...) Expand all
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 33
34 #include "modules/mediastream/UserMediaRequest.h" 34 #include "modules/mediastream/UserMediaRequest.h"
35 35
36 #include "bindings/v8/Dictionary.h" 36 #include "bindings/v8/Dictionary.h"
37 #include "bindings/v8/ExceptionMessages.h"
37 #include "bindings/v8/ExceptionState.h" 38 #include "bindings/v8/ExceptionState.h"
38 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
40 #include "core/dom/ExceptionCode.h"
39 #include "core/dom/SpaceSplitString.h" 41 #include "core/dom/SpaceSplitString.h"
40 #include "modules/mediastream/MediaConstraintsImpl.h" 42 #include "modules/mediastream/MediaConstraintsImpl.h"
41 #include "modules/mediastream/MediaStream.h" 43 #include "modules/mediastream/MediaStream.h"
42 #include "modules/mediastream/UserMediaController.h" 44 #include "modules/mediastream/UserMediaController.h"
43 #include "platform/mediastream/MediaStreamCenter.h" 45 #include "platform/mediastream/MediaStreamCenter.h"
44 #include "platform/mediastream/MediaStreamDescriptor.h" 46 #include "platform/mediastream/MediaStreamDescriptor.h"
45 47
46 namespace WebCore { 48 namespace WebCore {
47 49
48 static blink::WebMediaConstraints parseOptions(const Dictionary& options, const String& mediaType, ExceptionState& exceptionState) 50 static blink::WebMediaConstraints parseOptions(const Dictionary& options, const String& mediaType, ExceptionState& exceptionState)
49 { 51 {
50 blink::WebMediaConstraints constraints; 52 blink::WebMediaConstraints constraints;
51 53
52 Dictionary constraintsDictionary; 54 Dictionary constraintsDictionary;
53 bool ok = options.get(mediaType, constraintsDictionary); 55 bool ok = options.get(mediaType, constraintsDictionary);
54 if (ok && !constraintsDictionary.isUndefinedOrNull()) 56 if (ok && !constraintsDictionary.isUndefinedOrNull())
55 constraints = MediaConstraintsImpl::create(constraintsDictionary, except ionState); 57 constraints = MediaConstraintsImpl::create(constraintsDictionary, except ionState);
56 else { 58 else {
57 bool mediaRequested = false; 59 bool mediaRequested = false;
58 options.get(mediaType, mediaRequested); 60 options.get(mediaType, mediaRequested);
59 if (mediaRequested) 61 if (mediaRequested)
60 constraints = MediaConstraintsImpl::create(); 62 constraints = MediaConstraintsImpl::create();
61 } 63 }
62 64
63 return constraints; 65 return constraints;
64 } 66 }
65 67
66 PassRefPtr<UserMediaRequest> UserMediaRequest::create(ExecutionContext* context, UserMediaController* controller, const Dictionary& options, PassOwnPtr<Navigato rUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUserMediaErrorCa llback> errorCallback, ExceptionState& exceptionState) 68 PassRefPtr<UserMediaRequest> UserMediaRequest::create(ExecutionContext* context, UserMediaController* controller, const Dictionary& options, PassOwnPtr<Navigato rUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUserMediaErrorCa llback> errorCallback, ExceptionState& exceptionState)
67 { 69 {
70 if (!successCallback) {
71 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(2, "NavigatorUserMediaSuccessCallback"));
sof 2014/02/21 15:15:59 This isn't correct, I think - shouldn't it be Type
72 return nullptr;
73 }
74
75 if (!errorCallback) {
76 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(3, "NavigatorUserMediaErrorCallback"));
77 return nullptr;
78 }
79
68 blink::WebMediaConstraints audio = parseOptions(options, "audio", exceptionS tate); 80 blink::WebMediaConstraints audio = parseOptions(options, "audio", exceptionS tate);
69 if (exceptionState.hadException()) 81 if (exceptionState.hadException())
70 return nullptr; 82 return nullptr;
71 83
72 blink::WebMediaConstraints video = parseOptions(options, "video", exceptionS tate); 84 blink::WebMediaConstraints video = parseOptions(options, "video", exceptionS tate);
73 if (exceptionState.hadException()) 85 if (exceptionState.hadException())
74 return nullptr; 86 return nullptr;
75 87
76 if (audio.isNull() && video.isNull()) 88 if (audio.isNull() && video.isNull()) {
89 exceptionState.throwDOMException(SyntaxError, "At least one of audio and video must be requested");
77 return nullptr; 90 return nullptr;
91 }
78 92
79 return adoptRef(new UserMediaRequest(context, controller, audio, video, succ essCallback, errorCallback)); 93 return adoptRef(new UserMediaRequest(context, controller, audio, video, succ essCallback, errorCallback));
80 } 94 }
81 95
82 UserMediaRequest::UserMediaRequest(ExecutionContext* context, UserMediaControlle r* controller, blink::WebMediaConstraints audio, blink::WebMediaConstraints vide o, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<Nav igatorUserMediaErrorCallback> errorCallback) 96 UserMediaRequest::UserMediaRequest(ExecutionContext* context, UserMediaControlle r* controller, blink::WebMediaConstraints audio, blink::WebMediaConstraints vide o, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<Nav igatorUserMediaErrorCallback> errorCallback)
83 : ContextLifecycleObserver(context) 97 : ContextLifecycleObserver(context)
84 , m_audio(audio) 98 , m_audio(audio)
85 , m_video(video) 99 , m_video(video)
86 , m_controller(controller) 100 , m_controller(controller)
87 , m_successCallback(successCallback) 101 , m_successCallback(successCallback)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 160 }
147 161
148 m_successCallback->handleEvent(stream.get()); 162 m_successCallback->handleEvent(stream.get());
149 } 163 }
150 164
151 void UserMediaRequest::fail(const String& description) 165 void UserMediaRequest::fail(const String& description)
152 { 166 {
153 if (!executionContext()) 167 if (!executionContext())
154 return; 168 return;
155 169
156 if (m_errorCallback) { 170 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(Navi gatorUserMediaError::NamePermissionDenied, description, String());
157 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create( NavigatorUserMediaError::NamePermissionDenied, description, String()); 171 m_errorCallback->handleEvent(error.get());
158 m_errorCallback->handleEvent(error.get());
159 }
160 } 172 }
161 173
162 void UserMediaRequest::failConstraint(const String& constraintName, const String & description) 174 void UserMediaRequest::failConstraint(const String& constraintName, const String & description)
163 { 175 {
164 ASSERT(!constraintName.isEmpty()); 176 ASSERT(!constraintName.isEmpty());
165 if (!executionContext()) 177 if (!executionContext())
166 return; 178 return;
167 179
168 if (m_errorCallback) { 180 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(Navi gatorUserMediaError::NameConstraintNotSatisfied, description, constraintName);
169 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create( NavigatorUserMediaError::NameConstraintNotSatisfied, description, constraintName ); 181 m_errorCallback->handleEvent(error.get());
170 m_errorCallback->handleEvent(error.get());
171 }
172 } 182 }
173 183
174 void UserMediaRequest::contextDestroyed() 184 void UserMediaRequest::contextDestroyed()
175 { 185 {
176 RefPtr<UserMediaRequest> protect(this); 186 RefPtr<UserMediaRequest> protect(this);
177 187
178 if (m_controller) { 188 if (m_controller) {
179 m_controller->cancelUserMediaRequest(this); 189 m_controller->cancelUserMediaRequest(this);
180 m_controller = 0; 190 m_controller = 0;
181 } 191 }
182 192
183 ContextLifecycleObserver::contextDestroyed(); 193 ContextLifecycleObserver::contextDestroyed();
184 } 194 }
185 195
186 } // namespace WebCore 196 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/mediastream/NavigatorMediaStream.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698