Chromium Code Reviews| Index: third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp |
| diff --git a/third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp b/third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..127ed5a92a65816dfa3deb2350c4cc587418929e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/imagecapture/ImageCapture.h" |
| + |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "core/dom/DOMException.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "modules/EventTargetModules.h" |
| +#include "modules/mediastream/MediaStreamTrack.h" |
| +#include "public/platform/Platform.h" |
| + |
| +namespace blink { |
| + |
| +ImageCapture* ImageCapture::create(ExecutionContext* context, MediaStreamTrack* track, ExceptionState& exceptionState) |
| +{ |
| + if (track->kind() != "video") |
| + exceptionState.throwDOMException(NotSupportedError, "Cannot create an ImageCapturer from a non-video Track."); |
|
haraken
2016/04/20 00:41:04
You're throwing an exception but creating a new Im
mcasas
2016/04/20 00:53:41
Oops, no, it isn't, sorry.
|
| + |
| + return new ImageCapture(context, track); |
| +} |
| + |
| +const AtomicString& ImageCapture::interfaceName() const |
| +{ |
| + return EventTargetNames::ImageCapture; |
| +} |
| + |
| +ExecutionContext* ImageCapture::getExecutionContext() const |
| +{ |
| + return ContextLifecycleObserver::getExecutionContext(); |
| +} |
| + |
| +bool ImageCapture::hasPendingActivity() const |
| +{ |
| + return hasEventListeners(); |
|
haraken
2016/04/20 00:41:04
Can we add a test to check that ImageCapture is ke
mcasas
2016/04/20 00:53:42
Added one in contextDestroyed() and in the dtor.
|
| +} |
| + |
| +void ImageCapture::contextDestroyed() |
| +{ |
| + removeAllEventListeners(); |
| +} |
| + |
| +ScriptPromise ImageCapture::grabFrame(ScriptState* scriptState, ExceptionState& exceptionState) |
| +{ |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + // Spec instructs to return an exception if the track's ready state is not "live". Also reject if the track is disabled or muted. |
| + if (m_streamTrack->readyState() != "live" || !m_streamTrack->enabled() || m_streamTrack->muted()) { |
| + resolver->reject(DOMException::create(InvalidStateError, "The associated Track is in an invalid state.")); |
| + return promise; |
| + } |
| + |
| + resolver->reject(DOMException::create(NotSupportedError, "Not implemented yet")); |
| + return promise; |
| +} |
| + |
| +ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) |
| + : ActiveScriptWrappable(this) |
| + , ContextLifecycleObserver(context) |
| + , m_streamTrack(track) |
| +{ |
| + DCHECK(m_streamTrack); |
| +} |
| + |
| +bool ImageCapture::addEventListenerInternal(const AtomicString& eventType, EventListener* listener, const EventListenerOptions& options) |
| +{ |
| + return EventTarget::addEventListenerInternal(eventType, listener, options); |
| +} |
| + |
| +DEFINE_TRACE(ImageCapture) |
| +{ |
| + visitor->trace(m_streamTrack); |
| + EventTargetWithInlineData::trace(visitor); |
| + ContextLifecycleObserver::trace(visitor); |
| +} |
| + |
| +} // namespace blink |