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 return nullptr; | |
| 21 } | |
| 22 | |
| 23 return new ImageCapture(context, track); | |
| 24 } | |
| 25 | |
| 26 ImageCapture::~ImageCapture() | |
| 27 { | |
| 28 DCHECK(!hasEventListeners()); | |
| 29 } | |
| 30 | |
| 31 const AtomicString& ImageCapture::interfaceName() const | |
| 32 { | |
| 33 return EventTargetNames::ImageCapture; | |
| 34 } | |
| 35 | |
| 36 ExecutionContext* ImageCapture::getExecutionContext() const | |
| 37 { | |
| 38 return ContextLifecycleObserver::getExecutionContext(); | |
| 39 } | |
| 40 | |
| 41 bool ImageCapture::hasPendingActivity() const | |
|
haraken
2016/04/20 01:01:41
I meant, it would be better to add a layout test t
| |
| 42 { | |
| 43 return hasEventListeners(); | |
| 44 } | |
| 45 | |
| 46 void ImageCapture::contextDestroyed() | |
| 47 { | |
| 48 removeAllEventListeners(); | |
| 49 DCHECK(!hasEventListeners()); | |
| 50 } | |
| 51 | |
| 52 ScriptPromise ImageCapture::grabFrame(ScriptState* scriptState, ExceptionState& exceptionState) | |
| 53 { | |
| 54 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 55 ScriptPromise promise = resolver->promise(); | |
| 56 | |
| 57 // Spec instructs to return an exception if the track's ready state is not " live". Also reject if the track is disabled or muted. | |
| 58 if (m_streamTrack->readyState() != "live" || !m_streamTrack->enabled() || m_ streamTrack->muted()) { | |
| 59 resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state.")); | |
| 60 return promise; | |
| 61 } | |
| 62 | |
| 63 resolver->reject(DOMException::create(NotSupportedError, "Not implemented ye t")); | |
| 64 return promise; | |
| 65 } | |
| 66 | |
| 67 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) | |
| 68 : ActiveScriptWrappable(this) | |
| 69 , ContextLifecycleObserver(context) | |
| 70 , m_streamTrack(track) | |
| 71 { | |
| 72 DCHECK(m_streamTrack); | |
| 73 } | |
| 74 | |
| 75 bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, Event Listener* listener, const EventListenerOptions& options) | |
| 76 { | |
| 77 return EventTarget::addEventListenerInternal(eventType, listener, options); | |
| 78 } | |
| 79 | |
| 80 DEFINE_TRACE(ImageCapture) | |
| 81 { | |
| 82 visitor->trace(m_streamTrack); | |
| 83 EventTargetWithInlineData::trace(visitor); | |
| 84 ContextLifecycleObserver::trace(visitor); | |
| 85 } | |
| 86 | |
| 87 } // namespace blink | |
| OLD | NEW |