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

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

Issue 545933002: Implement HTMLMediaElement::srcObject. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Now uses Functional. Created 6 years, 3 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: Source/core/html/HTMLMediaElement.cpp
diff --git a/Source/core/html/HTMLMediaElement.cpp b/Source/core/html/HTMLMediaElement.cpp
index 91ef6708e6f5e78594ef9b36ad751aec9955cc39..7091070161a06ee81ebe6d13c4a33a10d2ec2d6c 100644
--- a/Source/core/html/HTMLMediaElement.cpp
+++ b/Source/core/html/HTMLMediaElement.cpp
@@ -48,6 +48,7 @@
#include "core/html/MediaController.h"
#include "core/html/MediaError.h"
#include "core/html/MediaFragmentURIParser.h"
+#include "core/html/MediaProvider.h"
#include "core/html/TimeRanges.h"
#include "core/html/shadow/MediaControls.h"
#include "core/html/track/AudioTrack.h"
@@ -325,6 +326,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
, m_lastTimeUpdateEventWallTime(0)
, m_lastTimeUpdateEventMovieTime(std::numeric_limits<double>::max())
, m_loadState(WaitingForSource)
+ , m_srcObject(std::nullptr_t())
philipj_slow 2014/09/16 13:39:50 You don't need to explicitly init these smart poin
perkj_chrome 2014/09/17 19:26:13 Well, WTF::RawPtr does not allow you to not set a
, m_deferredLoadState(NotDeferred)
, m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired)
, m_webLayer(0)
@@ -682,6 +684,19 @@ PassRefPtrWillBeRawPtr<MediaError> HTMLMediaElement::error() const
return m_error;
}
+void HTMLMediaElement::setSrcObject(RawPtr<MediaProvider> mediaProvider)
+{
+ WTF_LOG(Media, "HTMLMediaElement::setSrcObject()");
philipj_slow 2014/09/16 13:39:50 Please include the %p this pointer as well.
perkj_chrome 2014/09/17 19:26:13 Done.
+ m_srcObject = mediaProvider;
+ clearMediaPlayer(LoadMediaResource);
+ scheduleDelayedAction(LoadMediaResource);
philipj_slow 2014/09/16 13:39:50 The spec says "On setting, it must set the element
perkj_chrome 2014/09/17 19:26:13 Now calls load() and test is added to mediastream-
+}
+
+MediaProvider* HTMLMediaElement::srcObject() const
philipj_slow 2014/09/16 13:39:50 Please invert order here too.
perkj_chrome 2014/09/17 19:26:13 Done.
+{
+ return m_srcObject.get();
+}
+
void HTMLMediaElement::setSrc(const AtomicString& url)
{
setAttribute(srcAttr, url);
@@ -855,29 +870,32 @@ void HTMLMediaElement::selectMediaResource()
{
WTF_LOG(Media, "HTMLMediaElement::selectMediaResource");
- 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);
- m_networkState = NETWORK_EMPTY;
+ enum Mode {Object, Attribute, Children};
+
+ // 3 - Decide which source to load.
philipj_slow 2014/09/16 13:39:51 Please copy the steps from the spec. This should b
perkj_chrome 2014/09/17 19:26:13 Done.
+ // If the media element has a srcObject let the mode be object.
+ // If it has a src attribute, let the mode be attribute.
+ // If it has a source element, let the mode be Children.
+ Mode mode = Object;
philipj_slow 2014/09/16 13:39:51 Remove the default init unless it's needed to squa
perkj_chrome 2014/09/17 19:26:13 I can try. I am afraid it will hit me on one platf
+ if (srcObject()) {
+ mode = Object;
+ } else if (fastHasAttribute(srcAttr)) {
+ mode = Attribute;
+ } else if (Traversal<HTMLSourceElement>::firstChild(*this)) {
+ mode = Children;
+ HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChild(*this);
+ m_nextChildNodeToConsider = element;
+ m_currentSourceNode = nullptr;
+ } else {
+ // Otherwise the media element has no source.
+ // set the networkState to NETWORK_EMPTY, and abort these steps; the
+ // synchronous section ends.
+ m_loadState = WaitingForSource;
+ setShouldDelayLoadEvent(false);
+ m_networkState = NETWORK_EMPTY;
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, nothing to load");
- return;
- }
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, nothing to load");
+ return;
}
// 4 - Set the media element's delaying-the-load-event flag to true (this delays the load event),
@@ -888,34 +906,64 @@ void HTMLMediaElement::selectMediaResource()
// 5 - 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;
+ // 6 - Load the correct source.
philipj_slow 2014/09/16 13:39:50 Should say "Run the appropriate steps from the fol
perkj_chrome 2014/09/17 19:26:13 Done.
+ switch (mode) {
+ case Object:
+ loadSourceFromObject();
philipj_slow 2014/09/16 13:39:50 I think just loadFromObject() and loadFromAttribut
perkj_chrome 2014/09/17 19:26:13 Done.
+ break;
+ case Attribute:
+ loadSourceFromAttribute();
+ break;
+ case Children:
+ loadNextSourceChild();
+ break;
+ }
+}
+
+void HTMLMediaElement::loadSourceFromObject()
+{
+ m_loadState = LoadingFromSrcObject;
philipj_slow 2014/09/16 13:39:50 Can you annotate this function with comments from
perkj_chrome 2014/09/17 19:26:13 Added test of currentSrc to mediastream-srcobject.
- // If the src attribute's value is the empty string ... jump down to the failed step below
- KURL mediaURL = getNonEmptyURLAttribute(srcAttr);
- if (mediaURL.isEmpty()) {
- mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'");
- return;
- }
+ KURL mediaURL = document().completeURL(m_srcObject->getObjectUrl());
philipj_slow 2014/09/16 13:39:51 This is a little bit peculiar, since the point of
perkj_chrome 2014/09/17 19:26:13 Agree, this cl adds the interface MediaProvider so
- if (!isSafeToLoadURL(mediaURL, Complain)) {
- mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
- return;
- }
+ if (!isSafeToLoadURL(mediaURL, Complain)) {
+ mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
philipj_slow 2014/09/16 13:39:51 This bit needs a test. It can cause HTMLMediaEleme
perkj_chrome 2014/09/17 19:26:13 I don't see how it would ever return anything but
+ return;
+ }
+
+ // No type or key system information is available when the url comes
philipj_slow 2014/09/16 13:39:51 This is repeated, can you add a shared void loadRe
perkj_chrome 2014/09/17 19:26:13 Done.
+ // from the 'srcObject' so MediaPlayer
+ // will have to pick a media engine based on the file extension.
+ ContentType contentType((String()));
+ loadResource(mediaURL, contentType, String());
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'srcObject' attribute.");
+ return;
+}
+
+void HTMLMediaElement::loadSourceFromAttribute()
+{
+ m_loadState = LoadingFromSrcAttr;
+
+ // If the src attribute's value is the empty string ... jump down to the failed step below
+ KURL mediaURL = getNonEmptyURLAttribute(srcAttr);
+ if (mediaURL.isEmpty()) {
+ mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'");
+ return;
+ }
- // No type or key system information 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, String());
- WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attribute url");
+ if (!isSafeToLoadURL(mediaURL, Complain)) {
+ mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
return;
}
- // Otherwise, the source elements will be used
- loadNextSourceChild();
+ // No type or key system information 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, String());
+ WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attribute url");
+ return;
}
void HTMLMediaElement::loadNextSourceChild()

Powered by Google App Engine
This is Rietveld 408576698