void NavigatorMediaStream::webkitGetUserMedia(Navigator& navigator, const MediaStreamConstraints& options, NavigatorUserMediaSuccessCallback* successCallback, NavigatorUserMediaErrorCallback* errorCallback, ExceptionState& exceptionState) { if (!successCallback) return; UserMediaController* userMedia = UserMediaController::from(navigator.frame()); if (!userMedia) { exceptionState.throwDOMException(NotSupportedError, "No user media controller available; is this a detached window?"); return; } String errorMessage; if (navigator.frame()->document()->isPrivilegedContext(errorMessage)) { UseCounter::count(navigator.frame(), UseCounter::GetUserMediaSecureOrigin); } else { UseCounter::countDeprecation(navigator.frame(), UseCounter::GetUserMediaInsecureOrigin); OriginsUsingFeatures::countAnyWorld(*navigator.frame()->document(), OriginsUsingFeatures::Feature::GetUserMediaInsecureOrigin); if (navigator.frame()->settings()->strictPowerfulFeatureRestrictions()) { exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("webkitGetUserMedia", "Navigator", errorMessage)); return; } } UserMediaRequest* request = UserMediaRequest::create(navigator.frame()->document(), userMedia, options, successCallback, errorCallback, exceptionState); if (!request) { ASSERT(exceptionState.hadException()); return; } request->start(); }
void NavigatorMediaStream::webkitGetUserMedia(Navigator& navigator, const Dictionary& options, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUserMediaErrorCallback> errorCallback, ExceptionState& exceptionState) { if (!successCallback) return; UserMediaController* userMedia = UserMediaController::from(navigator.frame()); if (!userMedia) { exceptionState.throwDOMException(NotSupportedError, "No user media controller available; is this a detached window?"); return; } UserMediaRequest* request = UserMediaRequest::create(navigator.frame()->document(), userMedia, options, successCallback, errorCallback, exceptionState); if (!request) { ASSERT(exceptionState.hadException()); return; } request->start(); }
ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const MediaStreamConstraints& options, ExceptionState& exceptionState) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallback(resolver); NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(resolver); Document* document = toDocument(scriptState->getExecutionContext()); UserMediaController* userMedia = UserMediaController::from(document->frame()); if (!userMedia) return ScriptPromise::rejectWithDOMException( scriptState, DOMException::create(NotSupportedError, "No media device controller available; is this a " "detached window?")); MediaErrorState errorState; UserMediaRequest* request = UserMediaRequest::create( document, userMedia, options, successCallback, errorCallback, errorState); if (!request) { DCHECK(errorState.hadException()); if (errorState.canGenerateException()) { errorState.raiseException(exceptionState); return exceptionState.reject(scriptState); } ScriptPromise rejectedPromise = resolver->promise(); resolver->reject(errorState.createError()); return rejectedPromise; } String errorMessage; if (!request->isSecureContextUse(errorMessage)) { return ScriptPromise::rejectWithDOMException( scriptState, DOMException::create(NotSupportedError, errorMessage)); } request->start(); return resolver->promise(); }
ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Dictionary& options, ExceptionState& exceptionState) { RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallback(resolver); NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(resolver); Document* document = toDocument(scriptState->executionContext()); UserMediaController* userMedia = UserMediaController::from(document->frame()); if (!userMedia) return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "No media device controller available; is this a detached window?")); UserMediaRequest* request = UserMediaRequest::create(document, userMedia, options, successCallback, errorCallback, exceptionState); if (!request) { ASSERT(exceptionState.hadException()); return exceptionState.reject(scriptState); } request->start(); return resolver->promise(); }