Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/imagecapture/ImageCapture.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 8 #include "core/dom/DOMException.h" | |
| 9 #include "core/dom/ExceptionCode.h" | |
| 10 #include "modules/EventTargetModules.h" | |
| 11 #include "modules/mediastream/MediaStreamTrack.h" | |
| 12 #include "public/platform/Platform.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState) | |
| 17 { | |
| 18 if (track->kind() != "video") | |
| 19 exceptionState.throwDOMException(NotSupportedError, "Cannot create an Im ageCapturer from a non-video Track."); | |
| 20 | |
| 21 ImageCapture* imageCapture = new ImageCapture(context, track); | |
| 22 imageCapture->suspendIfNeeded(); | |
| 23 return imageCapture; | |
| 24 } | |
| 25 | |
| 26 const AtomicString& ImageCapture::interfaceName() const | |
| 27 { | |
| 28 return EventTargetNames::ImageCapture; | |
| 29 } | |
| 30 | |
| 31 ExecutionContext* ImageCapture::getExecutionContext() const | |
| 32 { | |
| 33 return ActiveDOMObject::getExecutionContext(); | |
| 34 } | |
| 35 | |
| 36 bool ImageCapture::hasPendingActivity() const | |
| 37 { | |
| 38 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop ped()) | |
|
haraken
2016/04/19 23:50:56
A better way to do this would be:
- Make ImageCap
mcasas
2016/04/20 00:31:51
Done, I think.
| |
| 39 return false; | |
| 40 | |
| 41 // Prevents garbage collecting of this object when not hold by another | |
| 42 // object but still has listeners registered. | |
| 43 return hasEventListeners(); | |
| 44 } | |
| 45 | |
| 46 ScriptPromise ImageCapture::grabFrame(ScriptState* scriptState, ExceptionState& exceptionState) | |
| 47 { | |
| 48 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 49 ScriptPromise promise = resolver->promise(); | |
| 50 | |
| 51 // Spec instructs to return an exception if the track's ready state is not " live". Also reject if the track is disabled or muted. | |
| 52 if (m_streamTrack->readyState() != "live" || !m_streamTrack->enabled() || m_ streamTrack->muted()) { | |
| 53 resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state.")); | |
| 54 return promise; | |
| 55 } | |
| 56 | |
| 57 resolver->reject(DOMException::create(NotSupportedError, "Not implemented ye t")); | |
| 58 return promise; | |
| 59 } | |
| 60 | |
| 61 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) | |
| 62 : ActiveScriptWrappable(this) | |
| 63 , ActiveDOMObject(context) | |
| 64 , m_streamTrack(track) | |
| 65 { | |
| 66 DCHECK(m_streamTrack); | |
| 67 } | |
| 68 | |
| 69 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options) | |
| 70 { | |
| 71 return EventTarget::addEventListenerInternal(eventType, listener, options); | |
| 72 } | |
| 73 | |
| 74 DEFINE_TRACE(ImageCapture) | |
| 75 { | |
| 76 visitor->trace(m_streamTrack); | |
| 77 EventTargetWithInlineData::trace(visitor); | |
| 78 ActiveDOMObject::trace(visitor); | |
| 79 } | |
| 80 | |
| 81 } // namespace blink | |
| OLD | NEW |