summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp')
-rw-r--r--src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp145
1 files changed, 96 insertions, 49 deletions
diff --git a/src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp b/src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp
index 2409d3702d..729aceb209 100644
--- a/src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp
+++ b/src/3rdparty/webkit/WebCore/html/HTMLMediaElement.cpp
@@ -28,6 +28,9 @@
#if ENABLE(VIDEO)
#include "HTMLMediaElement.h"
+#include "ClientRect.h"
+#include "ClientRectList.h"
+#include "ChromeClient.h"
#include "CSSHelper.h"
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
@@ -39,6 +42,7 @@
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
+#include "FrameView.h"
#include "HTMLDocument.h"
#include "HTMLNames.h"
#include "HTMLSourceElement.h"
@@ -53,6 +57,7 @@
#include "Page.h"
#include "ProgressEvent.h"
#include "RenderVideo.h"
+#include "RenderView.h"
#include "ScriptEventListener.h"
#include "TimeRanges.h"
#include <limits>
@@ -111,6 +116,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* doc)
, m_sentEndEvent(false)
, m_pausedInternal(false)
, m_sendProgressEvents(true)
+ , m_isFullscreen(false)
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
, m_needWidgetUpdate(false)
#endif
@@ -161,6 +167,8 @@ void HTMLMediaElement::parseMappedAttribute(MappedAttribute* attr)
m_player->setAutobuffer(!attr->isNull());
} else if (attrName == onabortAttr)
setAttributeEventListener(eventNames().abortEvent, createAttributeEventListener(this, attr));
+ else if (attrName == onbeforeloadAttr)
+ setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
else if (attrName == oncanplayAttr)
setAttributeEventListener(eventNames().canplayEvent, createAttributeEventListener(this, attr));
else if (attrName == oncanplaythroughAttr)
@@ -179,8 +187,6 @@ void HTMLMediaElement::parseMappedAttribute(MappedAttribute* attr)
setAttributeEventListener(eventNames().loadeddataEvent, createAttributeEventListener(this, attr));
else if (attrName == onloadedmetadataAttr)
setAttributeEventListener(eventNames().loadedmetadataEvent, createAttributeEventListener(this, attr));
- else if (attrName == onloadendAttr)
- setAttributeEventListener(eventNames().loadendEvent, createAttributeEventListener(this, attr));
else if (attrName == onloadstartAttr)
setAttributeEventListener(eventNames().loadstartEvent, createAttributeEventListener(this, attr));
else if (attrName == onpauseAttr)
@@ -245,6 +251,8 @@ void HTMLMediaElement::removedFromDocument()
{
if (m_networkState > NETWORK_EMPTY)
pause();
+ if (m_isFullscreen)
+ exitFullscreen();
HTMLElement::removedFromDocument();
}
@@ -454,17 +462,15 @@ void HTMLMediaElement::loadInternal()
// 4 - If the media element's networkState is set to NETWORK_LOADING or NETWORK_IDLE, set
// the error attribute to a new MediaError object whose code attribute is set to
// MEDIA_ERR_ABORTED, fire a progress event called abort at the media element, in the
- // context of the fetching process that is in progress for the element, and fire a progress
- // event called loadend at the media element, in the context of the same fetching process.
+ // context of the fetching process that is in progress for the element.
if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE) {
m_error = MediaError::create(MediaError::MEDIA_ERR_ABORTED);
- // fire synchronous 'abort' and 'loadend'
+ // fire synchronous 'abort'
bool totalKnown = m_player && m_player->totalBytesKnown();
unsigned loaded = m_player ? m_player->bytesLoaded() : 0;
unsigned total = m_player ? m_player->totalBytes() : 0;
dispatchEvent(ProgressEvent::create(eventNames().abortEvent, totalKnown, loaded, total));
- dispatchEvent(ProgressEvent::create(eventNames().loadendEvent, totalKnown, loaded, total));
}
// 5
@@ -496,35 +502,34 @@ void HTMLMediaElement::loadInternal()
void HTMLMediaElement::selectMediaResource()
{
- // 1 - If the media element has neither a src attribute nor any source element children, run these substeps
+ // 1 - Set the networkState to NETWORK_NO_SOURCE
+ m_networkState = NETWORK_NO_SOURCE;
+
+ // 2 - Asynchronously await a stable state.
+
+ // 3 - If the media element has neither a src attribute nor any source element children, run these substeps
String mediaSrc = getAttribute(srcAttr);
if (!mediaSrc && !havePotentialSourceChild()) {
m_loadState = WaitingForSource;
- // 1 - Set the networkState to NETWORK_NO_SOURCE
- m_networkState = NETWORK_NO_SOURCE;
-
- // 2 - While the media element has neither a src attribute nor any source element children,
- // wait. (This steps might wait forever.)
-
- m_delayingTheLoadEvent = false;
+ // 1 - Set the networkState to NETWORK_EMPTY and abort these steps
+ m_networkState = NETWORK_EMPTY;
+ ASSERT(!m_delayingTheLoadEvent);
return;
}
- // 2
+ // 4
m_delayingTheLoadEvent = true;
-
- // 3
m_networkState = NETWORK_LOADING;
- // 4
+ // 5
scheduleProgressEvent(eventNames().loadstartEvent);
- // 5 - If the media element has a src attribute, then run these substeps
+ // 6 - If the media element has a src attribute, then run these substeps
ContentType contentType("");
- if (!mediaSrc.isEmpty()) {
+ if (!mediaSrc.isNull()) {
KURL mediaURL = document()->completeURL(mediaSrc);
- if (isSafeToLoadURL(mediaURL, Complain)) {
+ if (isSafeToLoadURL(mediaURL, Complain) && dispatchBeforeLoadEvent(mediaURL.string())) {
m_loadState = LoadingFromSrcAttr;
loadResource(mediaURL, contentType);
} else
@@ -553,9 +558,20 @@ void HTMLMediaElement::loadNextSourceChild()
loadResource(mediaURL, contentType);
}
-void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType)
+void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& contentType)
{
- ASSERT(isSafeToLoadURL(url, Complain));
+ ASSERT(isSafeToLoadURL(initialURL, Complain));
+
+ Frame* frame = document()->frame();
+ if (!frame)
+ return;
+ FrameLoader* loader = frame->loader();
+ if (!loader)
+ return;
+
+ KURL url(initialURL);
+ if (!loader->willLoadMediaElementURL(url))
+ return;
// The resource fetch algorithm
m_networkState = NETWORK_LOADING;
@@ -577,7 +593,13 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType)
updateVolume();
m_player->load(m_currentSrc, contentType);
-
+
+ if (isVideo() && m_player->canLoadPoster()) {
+ KURL posterUrl = static_cast<HTMLVideoElement*>(this)->poster();
+ if (!posterUrl.isEmpty())
+ m_player->setPoster(posterUrl);
+ }
+
if (renderer())
renderer()->updateFromElement();
}
@@ -588,7 +610,7 @@ bool HTMLMediaElement::isSafeToLoadURL(const KURL& url, InvalidSourceAction acti
FrameLoader* loader = frame ? frame->loader() : 0;
// don't allow remote to local urls, and check with the frame loader client.
- if (!loader || !loader->canLoad(url, String(), document()) || !loader->client()->shouldLoadMediaElementURL(url)) {
+ if (!loader || !SecurityOrigin::canLoad(url, String(), document())) {
if (actionIfInvalid == Complain)
FrameLoader::reportLocalLoadFailed(frame, url.string());
return false;
@@ -614,24 +636,19 @@ void HTMLMediaElement::noneSupported()
m_loadState = WaitingForSource;
m_currentSourceNode = 0;
- // 4 - Reaching this step indicates that either the URL failed to resolve, or the media
+ // 5 - Reaching this step indicates that either the URL failed to resolve, or the media
// resource failed to load. Set the error attribute to a new MediaError object whose
// code attribute is set to MEDIA_ERR_SRC_NOT_SUPPORTED.
m_error = MediaError::create(MediaError::MEDIA_ERR_SRC_NOT_SUPPORTED);
- // 5 - Set the element's networkState attribute to the NETWORK_NO_SOURCE value.
+ // 6 - Set the element's networkState attribute to the NETWORK_NO_SOURCE value.
m_networkState = NETWORK_NO_SOURCE;
- // 6 - Queue a task to fire a progress event called error at the media element, in
+ // 7 - Queue a task to fire a progress event called error at the media element, in
// the context of the fetching process that was used to try to obtain the media
// resource in the resource fetch algorithm.
scheduleProgressEvent(eventNames().errorEvent);
- // 7 - Queue a task to fire a progress event called loadend at the media element, in
- // the context of the fetching process that was used to try to obtain the media
- // resource in the resource fetch algorithm.
- scheduleProgressEvent(eventNames().loadendEvent);
-
// 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
m_delayingTheLoadEvent = false;
@@ -657,19 +674,15 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err)
// the context of the fetching process started by this instance of this algorithm.
scheduleProgressEvent(eventNames().errorEvent);
- // 4 - Queue a task to fire a progress event called loadend at the media element, in
- // the context of the fetching process started by this instance of this algorithm.
- scheduleProgressEvent(eventNames().loadendEvent);
-
- // 5 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a
+ // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a
// task to fire a simple event called emptied at the element.
m_networkState = NETWORK_EMPTY;
scheduleEvent(eventNames().emptiedEvent);
- // 6 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
+ // 5 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
m_delayingTheLoadEvent = false;
- // 7 - Abort the overall resource selection algorithm.
+ // 6 - Abort the overall resource selection algorithm.
m_currentSourceNode = 0;
}
@@ -756,7 +769,6 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state)
setReadyState(currentState);
scheduleProgressEvent(eventNames().loadEvent);
- scheduleProgressEvent(eventNames().loadendEvent);
}
}
}
@@ -1355,7 +1367,7 @@ KURL HTMLMediaElement::selectNextSourceChild(ContentType *contentType, InvalidSo
// Is it safe to load this url?
mediaURL = source->src();
- if (!mediaURL.isValid() || !isSafeToLoadURL(mediaURL, actionIfInvalid))
+ if (!mediaURL.isValid() || !isSafeToLoadURL(mediaURL, actionIfInvalid) || !dispatchBeforeLoadEvent(mediaURL.string()))
goto check_again;
// Making it this far means the <source> looks reasonable
@@ -1514,7 +1526,12 @@ PassRefPtr<TimeRanges> HTMLMediaElement::seekable() const
bool HTMLMediaElement::potentiallyPlaying() const
{
- return !paused() && m_readyState >= HAVE_FUTURE_DATA && !endedPlayback() && !stoppedDueToErrors() && !pausedForUserInteraction();
+ return m_readyState >= HAVE_FUTURE_DATA && couldPlayIfEnoughData();
+}
+
+bool HTMLMediaElement::couldPlayIfEnoughData() const
+{
+ return !paused() && !endedPlayback() && !stoppedDueToErrors() && !pausedForUserInteraction();
}
bool HTMLMediaElement::endedPlayback() const
@@ -1598,7 +1615,8 @@ void HTMLMediaElement::updatePlayState()
float time = currentTime();
if (time > m_lastSeekTime)
addPlayedRange(m_lastSeekTime, time);
- }
+ } else if (couldPlayIfEnoughData() && playerPaused)
+ m_player->prepareToPlay();
if (renderer())
renderer()->updateFromElement();
@@ -1629,17 +1647,13 @@ void HTMLMediaElement::userCancelledLoad()
#endif
stopPeriodicTimers();
- // 2 - Set the error attribute to a new MediaError object whose code attribute is set to MEDIA_ERR_ABORT.
+ // 2 - Set the error attribute to a new MediaError object whose code attribute is set to MEDIA_ERR_ABORTED.
m_error = MediaError::create(MediaError::MEDIA_ERR_ABORTED);
// 3 - Queue a task to fire a progress event called abort at the media element, in the context
// of the fetching process started by this instance of this algorithm.
scheduleProgressEvent(eventNames().abortEvent);
- // 4 - Queue a task to fire a progress event called loadend at the media element, in the context
- // of the fetching process started by this instance of this algorithm.
- scheduleProgressEvent(eventNames().loadendEvent);
-
// 5 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the
// element's networkState attribute to the NETWORK_EMPTY value and queue a task to fire a
// simple event called emptied at the element. Otherwise, set set the element's networkState
@@ -1660,6 +1674,9 @@ void HTMLMediaElement::userCancelledLoad()
void HTMLMediaElement::documentWillBecomeInactive()
{
+ if (m_isFullscreen)
+ exitFullscreen();
+
m_inActiveDocument = false;
userCancelledLoad();
@@ -1696,6 +1713,14 @@ void HTMLMediaElement::mediaVolumeDidChange()
updateVolume();
}
+const IntRect HTMLMediaElement::screenRect()
+{
+ IntRect elementRect;
+ if (renderer())
+ elementRect = renderer()->view()->frameView()->contentsToScreen(renderer()->absoluteBoundingBoxRect());
+ return elementRect;
+}
+
void HTMLMediaElement::defaultEventHandler(Event* event)
{
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
@@ -1768,6 +1793,28 @@ void HTMLMediaElement::finishParsingChildren()
#endif
+void HTMLMediaElement::enterFullscreen()
+{
+ ASSERT(!m_isFullscreen);
+ if (!renderer())
+ return;
+ if (document() && document()->page())
+ document()->page()->chrome()->client()->enterFullscreenForNode(this);
+ m_isFullscreen = true;
+}
+
+void HTMLMediaElement::exitFullscreen()
+{
+ ASSERT(m_isFullscreen);
+ if (document() && document()->page())
+ document()->page()->chrome()->client()->exitFullscreenForNode(this);
+ m_isFullscreen = false;
+}
+
+PlatformMedia HTMLMediaElement::platformMedia() const
+{
+ return m_player ? m_player->platformMedia() : NoPlatformMedia;
+}
}
#endif