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

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

Issue 1302793002: Refactor "options" argument to getUserMedia to be a dictionary (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/modules/mediastream/UserMediaRequest.h ('k') | Source/modules/modules.gypi » ('j') | 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 23 matching lines...) Expand all
34 #include "modules/mediastream/UserMediaRequest.h" 34 #include "modules/mediastream/UserMediaRequest.h"
35 35
36 #include "bindings/core/v8/Dictionary.h" 36 #include "bindings/core/v8/Dictionary.h"
37 #include "bindings/core/v8/ExceptionMessages.h" 37 #include "bindings/core/v8/ExceptionMessages.h"
38 #include "bindings/core/v8/ExceptionState.h" 38 #include "bindings/core/v8/ExceptionState.h"
39 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
40 #include "core/dom/ExceptionCode.h" 40 #include "core/dom/ExceptionCode.h"
41 #include "core/dom/SpaceSplitString.h" 41 #include "core/dom/SpaceSplitString.h"
42 #include "modules/mediastream/MediaConstraintsImpl.h" 42 #include "modules/mediastream/MediaConstraintsImpl.h"
43 #include "modules/mediastream/MediaStream.h" 43 #include "modules/mediastream/MediaStream.h"
44 #include "modules/mediastream/MediaStreamConstraints.h"
44 #include "modules/mediastream/UserMediaController.h" 45 #include "modules/mediastream/UserMediaController.h"
45 #include "platform/mediastream/MediaStreamCenter.h" 46 #include "platform/mediastream/MediaStreamCenter.h"
46 #include "platform/mediastream/MediaStreamDescriptor.h" 47 #include "platform/mediastream/MediaStreamDescriptor.h"
47 48
48 namespace blink { 49 namespace blink {
49 50
50 static WebMediaConstraints parseOptions(const Dictionary& options, const String& mediaType, ExceptionState& exceptionState) 51 static WebMediaConstraints parseOptions(const BooleanOrDictionary& options, Exce ptionState& exceptionState)
51 { 52 {
52 WebMediaConstraints constraints; 53 WebMediaConstraints constraints;
53 54
54 Dictionary constraintsDictionary; 55 Dictionary constraintsDictionary;
55 bool ok = options.get(mediaType, constraintsDictionary); 56 if (options.isDictionary()) {
56 if (ok && !constraintsDictionary.isUndefinedOrNull()) 57 constraints = MediaConstraintsImpl::create(options.getAsDictionary(), ex ceptionState);
57 constraints = MediaConstraintsImpl::create(constraintsDictionary, except ionState); 58 } else {
58 else { 59 if (options.getAsBoolean()) {
tommi (sloooow) - chröme 2015/08/20 08:05:28 } else if (options.getAsBoolean()) {
59 bool mediaRequested = false;
60 DictionaryHelper::get(options, mediaType, mediaRequested);
61 if (mediaRequested)
62 constraints = MediaConstraintsImpl::create(); 60 constraints = MediaConstraintsImpl::create();
61 }
63 } 62 }
tommi (sloooow) - chröme 2015/08/20 08:05:28 } else { ASSERT(false); } (assuming options wil
hta - Chromium 2015/08/20 08:20:32 options.getAsBoolean actually calls ASSERT(isBoole
64 63
65 return constraints; 64 return constraints;
66 } 65 }
67 66
68 UserMediaRequest* UserMediaRequest::create(ExecutionContext* context, UserMediaC ontroller* controller, const Dictionary& options, NavigatorUserMediaSuccessCallb ack* successCallback, NavigatorUserMediaErrorCallback* errorCallback, ExceptionS tate& exceptionState) 67 UserMediaRequest* UserMediaRequest::create(ExecutionContext* context, UserMediaC ontroller* controller, const MediaStreamConstraints& options, NavigatorUserMedia SuccessCallback* successCallback, NavigatorUserMediaErrorCallback* errorCallback , ExceptionState& exceptionState)
69 { 68 {
70 WebMediaConstraints audio = parseOptions(options, "audio", exceptionState); 69 WebMediaConstraints audio = parseOptions(options.audio(), exceptionState);
71 if (exceptionState.hadException()) 70 if (exceptionState.hadException())
72 return nullptr; 71 return nullptr;
73 72
74 WebMediaConstraints video = parseOptions(options, "video", exceptionState); 73 WebMediaConstraints video = parseOptions(options.video(), exceptionState);
75 if (exceptionState.hadException()) 74 if (exceptionState.hadException())
76 return nullptr; 75 return nullptr;
77 76
78 if (audio.isNull() && video.isNull()) { 77 if (audio.isNull() && video.isNull()) {
79 exceptionState.throwDOMException(SyntaxError, "At least one of audio and video must be requested"); 78 exceptionState.throwDOMException(SyntaxError, "At least one of audio and video must be requested");
80 return nullptr; 79 return nullptr;
81 } 80 }
82 81
83 return new UserMediaRequest(context, controller, audio, video, successCallba ck, errorCallback); 82 return new UserMediaRequest(context, controller, audio, video, successCallba ck, errorCallback);
84 } 83 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 186
188 DEFINE_TRACE(UserMediaRequest) 187 DEFINE_TRACE(UserMediaRequest)
189 { 188 {
190 visitor->trace(m_controller); 189 visitor->trace(m_controller);
191 visitor->trace(m_successCallback); 190 visitor->trace(m_successCallback);
192 visitor->trace(m_errorCallback); 191 visitor->trace(m_errorCallback);
193 ContextLifecycleObserver::trace(visitor); 192 ContextLifecycleObserver::trace(visitor);
194 } 193 }
195 194
196 } // namespace blink 195 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/mediastream/UserMediaRequest.h ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698