| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/mediastream/MediaDevices.h" | 6 #include "modules/mediastream/MediaDevices.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 UserMediaController* userMedia = UserMediaController::from(document->frame()
); | 25 UserMediaController* userMedia = UserMediaController::from(document->frame()
); |
| 26 if (!userMedia) | 26 if (!userMedia) |
| 27 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "No media device controller available; is this a detac
hed window?")); | 27 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "No media device controller available; is this a detac
hed window?")); |
| 28 | 28 |
| 29 MediaDevicesRequest* request = MediaDevicesRequest::create(scriptState, user
Media); | 29 MediaDevicesRequest* request = MediaDevicesRequest::create(scriptState, user
Media); |
| 30 return request->start(); | 30 return request->start(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 class PromiseSuccessCallback : public NavigatorUserMediaSuccessCallback { | 35 class PromiseSuccessCallback final : public NavigatorUserMediaSuccessCallback { |
| 36 public: | 36 public: |
| 37 PromiseSuccessCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolve
r) | 37 PromiseSuccessCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolve
r) |
| 38 : m_resolver(resolver) | 38 : m_resolver(resolver) |
| 39 { | 39 { |
| 40 } | 40 } |
| 41 | 41 |
| 42 ~PromiseSuccessCallback() | 42 ~PromiseSuccessCallback() |
| 43 { | 43 { |
| 44 } | 44 } |
| 45 | 45 |
| 46 void handleEvent(MediaStream* stream) | 46 void handleEvent(MediaStream* stream) |
| 47 { | 47 { |
| 48 m_resolver->resolve(stream); | 48 m_resolver->resolve(stream); |
| 49 } | 49 } |
| 50 |
| 51 DEFINE_INLINE_VIRTUAL_TRACE() |
| 52 { |
| 53 visitor->trace(m_resolver); |
| 54 NavigatorUserMediaSuccessCallback::trace(visitor); |
| 55 } |
| 56 |
| 50 private: | 57 private: |
| 51 RefPtrWillBeRawPtr<ScriptPromiseResolver> m_resolver; | 58 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
| 52 }; | 59 }; |
| 53 | 60 |
| 54 class PromiseErrorCallback : public NavigatorUserMediaErrorCallback { | 61 class PromiseErrorCallback final : public NavigatorUserMediaErrorCallback { |
| 55 public: | 62 public: |
| 56 PromiseErrorCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver) | 63 PromiseErrorCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver) |
| 57 : m_resolver(resolver) | 64 : m_resolver(resolver) |
| 58 { | 65 { |
| 59 } | 66 } |
| 60 | 67 |
| 61 ~PromiseErrorCallback() | 68 ~PromiseErrorCallback() |
| 62 { | 69 { |
| 63 } | 70 } |
| 64 | 71 |
| 65 void handleEvent(NavigatorUserMediaError* error) | 72 void handleEvent(NavigatorUserMediaError* error) |
| 66 { | 73 { |
| 67 m_resolver->reject(error); | 74 m_resolver->reject(error); |
| 68 } | 75 } |
| 76 |
| 77 DEFINE_INLINE_VIRTUAL_TRACE() |
| 78 { |
| 79 visitor->trace(m_resolver); |
| 80 NavigatorUserMediaErrorCallback::trace(visitor); |
| 81 } |
| 82 |
| 69 private: | 83 private: |
| 70 RefPtrWillBeRawPtr<ScriptPromiseResolver> m_resolver; | 84 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
| 71 }; | 85 }; |
| 72 | 86 |
| 73 } // namespace | 87 } // namespace |
| 74 | 88 |
| 75 ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Diction
ary& options, ExceptionState& exceptionState) | 89 ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Diction
ary& options, ExceptionState& exceptionState) |
| 76 { | 90 { |
| 77 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 91 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 78 | 92 |
| 79 NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallb
ack(resolver); | 93 NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallb
ack(resolver); |
| 80 NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(re
solver); | 94 NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(re
solver); |
| 81 | 95 |
| 82 Document* document = toDocument(scriptState->executionContext()); | 96 Document* document = toDocument(scriptState->executionContext()); |
| 83 UserMediaController* userMedia = UserMediaController::from(document->frame()
); | 97 UserMediaController* userMedia = UserMediaController::from(document->frame()
); |
| 84 if (!userMedia) | 98 if (!userMedia) |
| 85 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "No media device controller available; is this a detac
hed window?")); | 99 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "No media device controller available; is this a detac
hed window?")); |
| 86 | 100 |
| 87 UserMediaRequest* request = UserMediaRequest::create(document, userMedia, op
tions, successCallback, errorCallback, exceptionState); | 101 UserMediaRequest* request = UserMediaRequest::create(document, userMedia, op
tions, successCallback, errorCallback, exceptionState); |
| 88 if (!request) { | 102 if (!request) { |
| 89 ASSERT(exceptionState.hadException()); | 103 ASSERT(exceptionState.hadException()); |
| 90 return exceptionState.reject(scriptState); | 104 return exceptionState.reject(scriptState); |
| 91 } | 105 } |
| 92 | 106 |
| 93 request->start(); | 107 request->start(); |
| 94 return resolver->promise(); | 108 return resolver->promise(); |
| 95 } | 109 } |
| 96 | 110 |
| 97 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |