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

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 1815033003: Add srcObject attribute of type MediaStream to HTMLMediaElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: haraken's comments + extra test Created 4 years, 9 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/core/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index 5a14ea40e1bed286a555021ffa380d58d79e775f..a091b899d24fb69894bdff796aa08f77eaced9ab 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -651,6 +651,16 @@ void HTMLMediaElement::setSrc(const AtomicString& url)
setAttribute(srcAttr, url);
}
+void HTMLMediaElement::setSrcObjectURL(const AtomicString& url)
+{
+ // The srcObject IDL attribute, on setting, must set the element's assigned
+ // media provider object to the new value, and then invoke the element's
+ // media element load algorithm.
+ m_srcObjectURL = url;
+ m_currentSrc = KURL();
+ invokeLoadAlgorithm();
+}
+
HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const
{
return m_networkState;
@@ -858,68 +868,101 @@ void HTMLMediaElement::selectMediaResource()
{
WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this);
- enum Mode { attribute, children };
-
- // 3 - If the media element has a src attribute, then let mode be attribute.
- Mode mode = attribute;
- if (!fastHasAttribute(srcAttr)) {
- // Otherwise, if the media element does not have a src attribute but has a source
- // element child, then let mode be children and let candidate be the first such
- // source element child in tree order.
- if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChild(*this)) {
- mode = children;
- m_nextChildNodeToConsider = element;
- m_currentSourceNode = nullptr;
- } else {
- // Otherwise the media element has neither a src attribute nor a source element
- // child: set the networkState to NETWORK_EMPTY, and abort these steps; the
- // synchronous section ends.
- m_loadState = WaitingForSource;
- setShouldDelayLoadEvent(false);
- setNetworkState(NETWORK_EMPTY);
- updateDisplayState();
+ enum Mode { Object, Attribute, Children, Nothing };
+ Mode mode = Nothing;
+
+ // 6 - If the media element has an assigned media provider object, then let
+ // mode be object.
+ if (!m_srcObjectURL.isEmpty()) {
+ mode = Object;
+ } else if (fastHasAttribute(srcAttr)) {
+ // Otherwise, if the media element has no assigned media provider object
+ // but has a src attribute, then let mode be attribute.
+ mode = Attribute;
+ } else if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChild(*this)) {
+ // Otherwise, if the media element does not have an assigned media
+ // provider object and does not have a src attribute, but does have a
+ // source element child, then let mode be children and let candidate be
+ // the first such source element child in tree order.
+ mode = Children;
+ m_nextChildNodeToConsider = element;
+ m_currentSourceNode = nullptr;
+ } else {
+ // Otherwise the media element has no assigned media provider object and
+ // has neither a src attribute nor a source element child: set the
+ // networkState to NETWORK_EMPTY, and abort these steps; the synchronous
+ // section ends.
+ m_loadState = WaitingForSource;
+ setShouldDelayLoadEvent(false);
+ setNetworkState(NETWORK_EMPTY);
+ updateDisplayState();
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing to load", this);
- return;
- }
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing to load", this);
+ return;
}
- // 4 - Set the media element's delaying-the-load-event flag to true (this delays the load event),
- // and set its networkState to NETWORK_LOADING.
- setShouldDelayLoadEvent(true);
+ // 7 - Set the media element's networkState to NETWORK_LOADING.
setNetworkState(NETWORK_LOADING);
- // 5 - Queue a task to fire a simple event named loadstart at the media element.
+ // 8 - Queue a task to fire a simple event named loadstart at the media element.
scheduleEvent(EventTypeNames::loadstart);
- // 6 - If mode is attribute, then run these substeps
- if (mode == attribute) {
- m_loadState = LoadingFromSrcAttr;
+ // 9 - Run the appropriate steps...
+ switch (mode) {
+ case Object:
+ loadSourceFromObject();
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'srcObject' attribute", this);
+ break;
+ case Attribute:
+ loadSourceFromAttribute();
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' attribute url", this);
+ break;
+ case Children:
+ loadNextSourceChild();
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using source element", this);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+}
- const AtomicString& srcValue = fastGetAttribute(srcAttr);
- // If the src attribute's value is the empty string ... jump down to the failed step below
- if (srcValue.isEmpty()) {
- mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'src'", this);
- return;
- }
+void HTMLMediaElement::loadSourceFromObject()
+{
+ ASSERT(!m_srcObjectURL.isEmpty());
+ m_loadState = LoadingFromSrcObject;
+ loadSourceFromURL(m_srcObjectURL);
+}
- KURL mediaURL = document().completeURL(srcValue);
- if (!isSafeToLoadURL(mediaURL, Complain)) {
- mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
- return;
- }
+void HTMLMediaElement::loadSourceFromAttribute()
+{
+ m_loadState = LoadingFromSrcAttr;
+ const AtomicString& srcValue = fastGetAttribute(srcAttr);
- // No type is available when the url comes from the 'src' attribute so MediaPlayer
- // will have to pick a media engine based on the file extension.
- ContentType contentType((String()));
- loadResource(mediaURL, contentType);
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' attribute url", this);
+ // If the src attribute's value is the empty string ... jump down to the failed step below
+ if (srcValue.isEmpty()) {
+ mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'src'", this);
+ return;
+ }
+
+ loadSourceFromURL(srcValue);
+}
+
+void HTMLMediaElement::loadSourceFromURL(const AtomicString& url)
+{
+ m_loadState = LoadingFromSrcAttr;
+
+ KURL mediaURL = document().completeURL(url);
+ if (!isSafeToLoadURL(mediaURL, Complain)) {
+ mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
return;
}
- // Otherwise, the source elements will be used
- loadNextSourceChild();
+ // No type is available when the url comes from the 'src' or 'srcObject'
+ // attribute so MediaPlayer will have to pick a media engine based on the
+ // file extension.
+ ContentType contentType((String()));
+ loadResource(mediaURL, contentType);
}
void HTMLMediaElement::loadNextSourceChild()

Powered by Google App Engine
This is Rietveld 408576698