Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp

Issue 1890313002: MediaStream Image Capture (1): idl and wireframe .h/.cpp/LayoutTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6df7e08bb8e49acd3841c9203cf9cefd96cfab18
--- /dev/null
+++ b/third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp
@@ -0,0 +1,81 @@
+// 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.");
+
+ ImageCapture* imageCapture = new ImageCapture(context, track);
+ imageCapture->suspendIfNeeded();
+ return imageCapture;
+}
+
+const AtomicString& ImageCapture::interfaceName() const
+{
+ return EventTargetNames::ImageCapture;
+}
+
+ExecutionContext* ImageCapture::getExecutionContext() const
+{
+ return ActiveDOMObject::getExecutionContext();
+}
+
+bool ImageCapture::hasPendingActivity() const
+{
+ if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStopped())
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.
+ return false;
+
+ // Prevents garbage collecting of this object when not hold by another
+ // object but still has listeners registered.
+ return hasEventListeners();
+}
+
+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)
+ , ActiveDOMObject(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);
+ ActiveDOMObject::trace(visitor);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698