| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/imagecapture/ImageCapture.h" | 5 #include "modules/imagecapture/ImageCapture.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (!m_service) { | 85 if (!m_service) { |
| 86 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); | 86 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); |
| 87 return promise; | 87 return promise; |
| 88 } | 88 } |
| 89 | 89 |
| 90 m_serviceRequests.add(resolver); | 90 m_serviceRequests.add(resolver); |
| 91 | 91 |
| 92 // m_streamTrack->component()->source()->id() is the renderer "name" of the
camera; | 92 // m_streamTrack->component()->source()->id() is the renderer "name" of the
camera; |
| 93 // TODO(mcasas) consider sending the security origin as well: | 93 // TODO(mcasas) consider sending the security origin as well: |
| 94 // scriptState->getExecutionContext()->getSecurityOrigin()->toString() | 94 // scriptState->getExecutionContext()->getSecurityOrigin()->toString() |
| 95 m_service->GetCapabilities(m_streamTrack->component()->source()->id(), creat
eBaseCallback(bind<media::mojom::blink::PhotoCapabilitiesPtr>(&ImageCapture::onC
apabilities, this, resolver))); | 95 m_service->GetCapabilities(m_streamTrack->component()->source()->id(), creat
eBaseCallback(bind<media::mojom::blink::PhotoCapabilitiesPtr>(&ImageCapture::onC
apabilities, wrapCrossThreadPersistent(this), wrapCrossThreadPersistent(resolver
)))); |
| 96 return promise; | 96 return promise; |
| 97 } | 97 } |
| 98 | 98 |
| 99 ScriptPromise ImageCapture::takePhoto(ScriptState* scriptState, ExceptionState&
exceptionState) | 99 ScriptPromise ImageCapture::takePhoto(ScriptState* scriptState, ExceptionState&
exceptionState) |
| 100 { | 100 { |
| 101 | 101 |
| 102 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 102 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 103 ScriptPromise promise = resolver->promise(); | 103 ScriptPromise promise = resolver->promise(); |
| 104 | 104 |
| 105 if (trackIsInactive(*m_streamTrack)) { | 105 if (trackIsInactive(*m_streamTrack)) { |
| 106 resolver->reject(DOMException::create(InvalidStateError, "The associated
Track is in an invalid state.")); | 106 resolver->reject(DOMException::create(InvalidStateError, "The associated
Track is in an invalid state.")); |
| 107 return promise; | 107 return promise; |
| 108 } | 108 } |
| 109 | 109 |
| 110 if (!m_service) { | 110 if (!m_service) { |
| 111 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); | 111 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); |
| 112 return promise; | 112 return promise; |
| 113 } | 113 } |
| 114 | 114 |
| 115 m_serviceRequests.add(resolver); | 115 m_serviceRequests.add(resolver); |
| 116 | 116 |
| 117 // m_streamTrack->component()->source()->id() is the renderer "name" of the
camera; | 117 // m_streamTrack->component()->source()->id() is the renderer "name" of the
camera; |
| 118 // TODO(mcasas) consider sending the security origin as well: | 118 // TODO(mcasas) consider sending the security origin as well: |
| 119 // scriptState->getExecutionContext()->getSecurityOrigin()->toString() | 119 // scriptState->getExecutionContext()->getSecurityOrigin()->toString() |
| 120 m_service->TakePhoto(m_streamTrack->component()->source()->id(), createBaseC
allback(bind<String, mojo::WTFArray<uint8_t>>(&ImageCapture::onTakePhoto, this,
resolver))); | 120 m_service->TakePhoto(m_streamTrack->component()->source()->id(), createBaseC
allback(bind<String, mojo::WTFArray<uint8_t>>(&ImageCapture::onTakePhoto, wrapCr
ossThreadPersistent(this), wrapCrossThreadPersistent(resolver)))); |
| 121 return promise; | 121 return promise; |
| 122 } | 122 } |
| 123 | 123 |
| 124 ScriptPromise ImageCapture::grabFrame(ScriptState* scriptState, ExceptionState&
exceptionState) | 124 ScriptPromise ImageCapture::grabFrame(ScriptState* scriptState, ExceptionState&
exceptionState) |
| 125 { | 125 { |
| 126 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 126 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 127 ScriptPromise promise = resolver->promise(); | 127 ScriptPromise promise = resolver->promise(); |
| 128 | 128 |
| 129 if (trackIsInactive(*m_streamTrack)) { | 129 if (trackIsInactive(*m_streamTrack)) { |
| 130 resolver->reject(DOMException::create(InvalidStateError, "The associated
Track is in an invalid state.")); | 130 resolver->reject(DOMException::create(InvalidStateError, "The associated
Track is in an invalid state.")); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 202 |
| 203 DEFINE_TRACE(ImageCapture) | 203 DEFINE_TRACE(ImageCapture) |
| 204 { | 204 { |
| 205 visitor->trace(m_streamTrack); | 205 visitor->trace(m_streamTrack); |
| 206 visitor->trace(m_serviceRequests); | 206 visitor->trace(m_serviceRequests); |
| 207 EventTargetWithInlineData::trace(visitor); | 207 EventTargetWithInlineData::trace(visitor); |
| 208 ContextLifecycleObserver::trace(visitor); | 208 ContextLifecycleObserver::trace(visitor); |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |