コード例 #1
0
static WebMediaConstraints createFromNamedConstraints(WebVector<WebMediaConstraint>& mandatory, const WebVector<WebMediaConstraint>& optional, MediaErrorState& errorState)
{
    WebMediaTrackConstraintSet basic;
    WebMediaTrackConstraintSet advanced;
    WebMediaConstraints constraints;
    if (RuntimeEnabledFeatures::mediaConstraintsEnabled()) {
        parseOldStyleNames(mandatory, basic, errorState);
        if (errorState.hadException())
            return constraints;
        // We ignore errors in optional constraints.
        MediaErrorState ignoredErrorState;
        parseOldStyleNames(optional, advanced, ignoredErrorState);
    }
    WebVector<WebMediaTrackConstraintSet> advancedVector(&advanced, 1);
    // Use the 4-argument initializer until Chrome has been converted.
    constraints.initialize(optional, mandatory, basic, advancedVector);
    return constraints;
}
コード例 #2
0
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();
}