Index: third_party/WebKit/Source/modules/mediacapturefromelement/HTMLMediaElementCapture.cpp |
diff --git a/third_party/WebKit/Source/modules/mediacapturefromelement/HTMLMediaElementCapture.cpp b/third_party/WebKit/Source/modules/mediacapturefromelement/HTMLMediaElementCapture.cpp |
index aad4dab4c61a1e4856448a4223b901f9342494eb..471b13446362d8234242fcac75d03590161cf8e7 100644 |
--- a/third_party/WebKit/Source/modules/mediacapturefromelement/HTMLMediaElementCapture.cpp |
+++ b/third_party/WebKit/Source/modules/mediacapturefromelement/HTMLMediaElementCapture.cpp |
@@ -5,6 +5,7 @@ |
#include "modules/mediacapturefromelement/HTMLMediaElementCapture.h" |
#include "core/dom/ExceptionCode.h" |
+#include "core/events/EventListener.h" |
#include "core/html/HTMLMediaElement.h" |
#include "core/html/track/AudioTrackList.h" |
#include "core/html/track/VideoTrackList.h" |
@@ -19,6 +20,47 @@ |
namespace blink { |
+namespace { |
+ |
+// EventListener class to catch the HTMLMediaElement onEnded event and terminate |
+// the MediaStream passed on construction. |
+class HTMLMediaElementOnEndedEventListener : public EventListener { |
haraken
2016/06/29 00:46:59
It looks strange that you have to subclass the Eve
foolip
2016/06/29 10:31:04
If this is all that this API does, do we really ne
|
+public: |
+ static HTMLMediaElementOnEndedEventListener* create(MediaStream* stream) |
+ { |
+ return new HTMLMediaElementOnEndedEventListener(stream); |
+ } |
+ |
+ bool operator==(const EventListener& other) const override |
+ { |
+ return this == &other; |
+ } |
+ |
+ void handleEvent(ExecutionContext*, Event* event) override |
+ { |
+ DCHECK_EQ(EventTypeNames::ended, event->type()); |
+ if (m_stream) |
+ m_stream->streamEnded(); |
foolip
2016/06/29 10:31:04
I think that creating an ended event with scripts
|
+ } |
+ |
+ DEFINE_INLINE_TRACE() |
+ { |
+ visitor->trace(m_stream); |
+ EventListener::trace(visitor); |
+ } |
+ |
+private: |
+ explicit HTMLMediaElementOnEndedEventListener(MediaStream* stream) |
+ : EventListener(CPPEventListenerType) |
+ , m_stream(stream) |
+ { |
+ } |
+ |
+ WeakMember<MediaStream> m_stream; |
+}; |
+ |
+} // anonymous namespace |
+ |
// static |
MediaStream* HTMLMediaElementCapture::captureStream(HTMLMediaElement& element, ExceptionState& exceptionState) |
{ |
@@ -50,4 +92,15 @@ MediaStream* HTMLMediaElementCapture::captureStream(HTMLMediaElement& element, E |
return MediaStream::create(element.getExecutionContext(), webStream); |
} |
+// static |
+MediaStream* HTMLMediaElementCapture::captureStreamUntilEnded(HTMLMediaElement& element, ExceptionState& exceptionState) |
+{ |
+ MediaStream* stream = captureStream(element, exceptionState); |
+ |
+ element.addEventListener(EventTypeNames::ended, HTMLMediaElementOnEndedEventListener::create(stream), false); |
+ |
+ return stream; |
+} |
+ |
+ |
} // namespace blink |