Changeset 185903 in webkit
- Timestamp:
- Jun 24, 2015 12:42:55 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r185897 r185903 1 2015-06-24 Youenn Fablet <youenn.fablet@crf.canon.fr> 2 3 Refactor UserMediaRequest to share more codes between MediaDevices.getUserMedia and legacy webkitGetUserMedia 4 https://bugs.webkit.org/show_bug.cgi?id=146237 5 6 Reviewed by Darin Adler. 7 8 Covered by existing tests, no change in behavior. 9 10 * Modules/mediastream/MediaConstraintsImpl.cpp: 11 (WebCore::MediaConstraintsImpl::create): Simplified error handling by removing exception code parameter. 12 * Modules/mediastream/MediaConstraintsImpl.h: Ditto. 13 * Modules/mediastream/MediaDevices.cpp: 14 (WebCore::MediaDevices::getUserMedia): Removed code now in UserMediaRequest::start. 15 * Modules/mediastream/NavigatorUserMedia.cpp: 16 (WebCore::NavigatorUserMedia::webkitGetUserMedia): Ditto. 17 * Modules/mediastream/UserMediaRequest.cpp: 18 (WebCore::parseOptions): Simplified error handling by removing exception code parameter. 19 (WebCore::UserMediaRequest::start): Renamed create in start and added common code. 20 * Modules/mediastream/UserMediaRequest.h: 21 1 22 2015-06-23 Andreas Kling <akling@apple.com> 2 23 -
trunk/Source/WebCore/Modules/mediastream/MediaConstraintsImpl.cpp
r185101 r185903 42 42 namespace WebCore { 43 43 44 RefPtr<MediaConstraintsImpl> MediaConstraintsImpl::create(const Dictionary& constraints , ExceptionCode& ec)44 RefPtr<MediaConstraintsImpl> MediaConstraintsImpl::create(const Dictionary& constraints) 45 45 { 46 46 RefPtr<MediaConstraintsImpl> object = adoptRef(*new MediaConstraintsImpl()); 47 if (!object->initialize(constraints)) { 48 ec = TYPE_MISMATCH_ERR; 47 if (!object->initialize(constraints)) 49 48 return nullptr; 50 }51 49 return object; 52 50 } -
trunk/Source/WebCore/Modules/mediastream/MediaConstraintsImpl.h
r185091 r185903 45 45 public: 46 46 static Ref<MediaConstraintsImpl> create(); 47 static RefPtr<MediaConstraintsImpl> create(const Dictionary& , ExceptionCode&);47 static RefPtr<MediaConstraintsImpl> create(const Dictionary&); 48 48 49 49 virtual ~MediaConstraintsImpl(); -
trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp
r185873 r185903 63 63 void MediaDevices::getUserMedia(const Dictionary& options, Promise&& promise, ExceptionCode& ec) const 64 64 { 65 if (!options.isObject()) { 66 ec = TypeError; 67 return; 68 } 69 70 UserMediaController* userMedia = UserMediaController::from(document() ? document()->page() : nullptr); 71 if (!userMedia) { 72 // FIXME: We probably want to return a MediaStreamError here using the rejectCallback, and get rid off the ExceptionCode parameter. 73 ec = NOT_SUPPORTED_ERR; 74 return; 75 } 76 77 RefPtr<UserMediaRequest> request = UserMediaRequest::create(document(), userMedia, options, WTF::move(promise), ec); 78 if (!request) { 79 ec = NOT_SUPPORTED_ERR; 80 return; 81 } 82 83 request->start(); 65 UserMediaRequest::start(document(), options, WTF::move(promise), ec); 84 66 } 85 67 -
trunk/Source/WebCore/Modules/mediastream/NavigatorUserMedia.cpp
r185873 r185903 57 57 } 58 58 59 UserMediaController* userMedia = UserMediaController::from(navigator->frame() ? navigator->frame()->page() : 0);60 if (!userMedia) {61 ec = NOT_SUPPORTED_ERR;62 return;63 }64 65 59 // We do not need to protect the context (i.e. document) here as UserMediaRequest is observing context destruction and will check validity before resolving/rejecting promise. 66 60 Document* document = navigator->frame()->document(); … … 81 75 }; 82 76 83 auto request = UserMediaRequest::create(navigator->frame()->document(), userMedia, options, MediaDevices::Promise(WTF::move(resolveCallback), WTF::move(rejectCallback)), ec); 84 if (!request) { 85 ec = NOT_SUPPORTED_ERR; 86 return; 87 } 88 89 request->start(); 77 UserMediaRequest::start(navigator->frame()->document(), options, MediaDevices::Promise(WTF::move(resolveCallback), WTF::move(rejectCallback)), ec); 90 78 } 91 79 -
trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
r185873 r185903 56 56 namespace WebCore { 57 57 58 static PassRefPtr<MediaConstraints> parseOptions(const Dictionary& options, const String& mediaType, ExceptionCode& ec) 59 { 60 RefPtr<MediaConstraints> constraints; 61 58 static RefPtr<MediaConstraints> parseOptions(const Dictionary& options, const String& mediaType) 59 { 62 60 Dictionary constraintsDictionary; 63 bool ok = options.get(mediaType, constraintsDictionary); 64 if (ok && !constraintsDictionary.isUndefinedOrNull()) 65 constraints = MediaConstraintsImpl::create(constraintsDictionary, ec); 66 else { 67 bool mediaRequested = false; 68 options.get(mediaType, mediaRequested); 69 if (mediaRequested) 70 constraints = MediaConstraintsImpl::create(); 71 } 72 73 return constraints.release(); 74 } 75 76 RefPtr<UserMediaRequest> UserMediaRequest::create(ScriptExecutionContext* context, UserMediaController* controller, const Dictionary& options, MediaDevices::Promise&& promise, ExceptionCode& ec) 77 { 78 RefPtr<MediaConstraints> audioConstraints = parseOptions(options, AtomicString("audio", AtomicString::ConstructFromLiteral), ec); 79 if (ec) 61 if (options.get(mediaType, constraintsDictionary) && !constraintsDictionary.isUndefinedOrNull()) 62 return MediaConstraintsImpl::create(constraintsDictionary); 63 64 bool mediaRequested = false; 65 if (!options.get(mediaType, mediaRequested) || !mediaRequested) 80 66 return nullptr; 81 67 82 RefPtr<MediaConstraints> videoConstraints = parseOptions(options, AtomicString("video", AtomicString::ConstructFromLiteral), ec); 83 if (ec) 84 return nullptr; 85 86 if (!audioConstraints && !videoConstraints) 87 return nullptr; 88 89 return adoptRef(*new UserMediaRequest(context, controller, audioConstraints.release(), videoConstraints.release(), WTF::move(promise))); 68 return MediaConstraintsImpl::create(); 69 } 70 71 void UserMediaRequest::start(Document* document, const Dictionary& options, MediaDevices::Promise&& promise, ExceptionCode& ec) 72 { 73 if (!options.isObject()) { 74 ec = TypeError; 75 return; 76 } 77 78 UserMediaController* userMedia = UserMediaController::from(document ? document->page() : nullptr); 79 if (!userMedia) { 80 ec = NOT_SUPPORTED_ERR; 81 return; 82 } 83 84 RefPtr<MediaConstraints> audioConstraints = parseOptions(options, AtomicString("audio", AtomicString::ConstructFromLiteral)); 85 RefPtr<MediaConstraints> videoConstraints = parseOptions(options, AtomicString("video", AtomicString::ConstructFromLiteral)); 86 87 if (!audioConstraints && !videoConstraints) { 88 ec = NOT_SUPPORTED_ERR; 89 return; 90 } 91 92 Ref<UserMediaRequest> request = adoptRef(*new UserMediaRequest(document, userMedia, audioConstraints.release(), videoConstraints.release(), WTF::move(promise))); 93 request->start(); 90 94 } 91 95 -
trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h
r185873 r185903 59 59 class UserMediaRequest : public MediaStreamCreationClient, public ContextDestructionObserver { 60 60 public: 61 static RefPtr<UserMediaRequest> create(ScriptExecutionContext*, UserMediaController*, const Dictionary& options, MediaDevices::Promise&&, ExceptionCode&);61 static void start(Document*, const Dictionary&, MediaDevices::Promise&&, ExceptionCode&); 62 62 ~UserMediaRequest(); 63 63
Note: See TracChangeset
for help on using the changeset viewer.