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

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

Issue 314113008: Oilpan: have MediaController weakly refer to its media elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add FIXME (crbug.com/383072) Created 6 years, 6 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
« no previous file with comments | « Source/core/html/MediaController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/MediaController.cpp
diff --git a/Source/core/html/MediaController.cpp b/Source/core/html/MediaController.cpp
index 7835e2307a6efa23b6df4cd0c142aceec4d83362..0f2e3f33de9d09660f44e989f6fc248865c68223 100644
--- a/Source/core/html/MediaController.cpp
+++ b/Source/core/html/MediaController.cpp
@@ -38,9 +38,10 @@
#include "wtf/StdLibExtras.h"
#include "wtf/text/AtomicString.h"
-using namespace WebCore;
using namespace std;
+namespace WebCore {
+
PassRefPtrWillBeRawPtr<MediaController> MediaController::create(ExecutionContext* context)
{
return adoptRefWillBeRefCountedGarbageCollected(new MediaController(context));
@@ -73,7 +74,7 @@ void MediaController::addMediaElement(HTMLMediaElement* element)
ASSERT(element);
ASSERT(!m_mediaElements.contains(element));
- m_mediaElements.append(element);
+ m_mediaElements.add(element);
bringElementUpToSpeed(element);
}
@@ -92,9 +93,10 @@ PassRefPtr<TimeRanges> MediaController::buffered() const
// The buffered attribute must return a new static normalized TimeRanges object that represents
// the intersection of the ranges of the media resources of the slaved media elements that the
// user agent has buffered, at the time the attribute is evaluated.
- RefPtr<TimeRanges> bufferedRanges = m_mediaElements.first()->buffered();
- for (size_t index = 1; index < m_mediaElements.size(); ++index)
- bufferedRanges->intersectWith(m_mediaElements[index]->buffered().get());
+ MediaElementSequence::const_iterator it = m_mediaElements.begin();
+ RefPtr<TimeRanges> bufferedRanges = (*it)->buffered();
+ for (++it; it != m_mediaElements.end(); ++it)
+ bufferedRanges->intersectWith((*it)->buffered().get());
return bufferedRanges;
}
@@ -106,9 +108,10 @@ PassRefPtr<TimeRanges> MediaController::seekable() const
// The seekable attribute must return a new static normalized TimeRanges object that represents
// the intersection of the ranges of the media resources of the slaved media elements that the
// user agent is able to seek to, at the time the attribute is evaluated.
- RefPtr<TimeRanges> seekableRanges = m_mediaElements.first()->seekable();
- for (size_t index = 1; index < m_mediaElements.size(); ++index)
- seekableRanges->intersectWith(m_mediaElements[index]->seekable().get());
+ MediaElementSequence::const_iterator it = m_mediaElements.begin();
+ RefPtr<TimeRanges> seekableRanges = (*it)->seekable();
+ for (++it; it != m_mediaElements.end(); ++it)
+ seekableRanges->intersectWith((*it)->seekable().get());
return seekableRanges;
}
@@ -120,9 +123,10 @@ PassRefPtr<TimeRanges> MediaController::played()
// The played attribute must return a new static normalized TimeRanges object that represents
// the union of the ranges of the media resources of the slaved media elements that the
// user agent has so far rendered, at the time the attribute is evaluated.
- RefPtr<TimeRanges> playedRanges = m_mediaElements.first()->played();
- for (size_t index = 1; index < m_mediaElements.size(); ++index)
- playedRanges->unionWith(m_mediaElements[index]->played().get());
+ MediaElementSequence::const_iterator it = m_mediaElements.begin();
+ RefPtr<TimeRanges> playedRanges = (*it)->played();
+ for (++it; it != m_mediaElements.end(); ++it)
+ playedRanges->unionWith((*it)->played().get());
return playedRanges;
}
@@ -131,8 +135,8 @@ double MediaController::duration() const
// FIXME: Investigate caching the maximum duration and only updating the cached value
// when the slaved media elements' durations change.
double maxDuration = 0;
- for (size_t index = 0; index < m_mediaElements.size(); ++index) {
- double duration = m_mediaElements[index]->duration();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it) {
+ double duration = (*it)->duration();
if (std::isnan(duration))
continue;
maxDuration = max(maxDuration, duration);
@@ -170,8 +174,8 @@ void MediaController::setCurrentTime(double time, ExceptionState& exceptionState
m_clock->setCurrentTime(time);
// Seek each slaved media element to the new playback position relative to the media element timeline.
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->seek(time, exceptionState);
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->seek(time, exceptionState);
scheduleTimeupdateEvent();
}
@@ -194,8 +198,8 @@ void MediaController::play()
{
// When the play() method is invoked, the user agent must invoke the play method of each
// slaved media element in turn,
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->play();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->play();
// and then invoke the unpause method of the MediaController.
unpause();
@@ -242,8 +246,8 @@ void MediaController::setPlaybackRate(double rate)
// playback rate to the new value,
m_clock->setPlayRate(rate);
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->updatePlaybackRate();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->updatePlaybackRate();
// then queue a task to fire a simple event named ratechange at the MediaController.
scheduleEvent(EventTypeNames::ratechange);
@@ -268,8 +272,8 @@ void MediaController::setVolume(double level, ExceptionState& exceptionState)
// and queue a task to fire a simple event named volumechange at the MediaController.
scheduleEvent(EventTypeNames::volumechange);
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->updateVolume();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->updateVolume();
}
void MediaController::setMuted(bool flag)
@@ -284,8 +288,8 @@ void MediaController::setMuted(bool flag)
// and queue a task to fire a simple event named volumechange at the MediaController.
scheduleEvent(EventTypeNames::volumechange);
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->updateVolume();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->updateVolume();
}
static const AtomicString& playbackStateWaiting()
@@ -357,9 +361,10 @@ void MediaController::updateReadyState()
} else {
// Otherwise, let it have the lowest value of the readyState IDL attributes of all of its
// slaved media elements.
- newReadyState = m_mediaElements.first()->readyState();
- for (size_t index = 1; index < m_mediaElements.size(); ++index)
- newReadyState = min(newReadyState, m_mediaElements[index]->readyState());
+ MediaElementSequence::const_iterator it = m_mediaElements.begin();
+ newReadyState = (*it)->readyState();
+ for (++it; it != m_mediaElements.end(); ++it)
+ newReadyState = min(newReadyState, (*it)->readyState());
}
if (newReadyState == oldReadyState)
@@ -467,8 +472,8 @@ void MediaController::updatePlaybackState()
void MediaController::updateMediaElements()
{
- for (size_t index = 0; index < m_mediaElements.size(); ++index)
- m_mediaElements[index]->updatePlayState();
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it)
+ (*it)->updatePlayState();
}
void MediaController::bringElementUpToSpeed(HTMLMediaElement* element)
@@ -493,8 +498,8 @@ bool MediaController::isRestrained() const
bool anyAutoplayingAndPaused = false;
bool allPaused = true;
- for (size_t index = 0; index < m_mediaElements.size(); ++index) {
- HTMLMediaElement* element = m_mediaElements[index];
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it) {
+ HTMLMediaElement* element = *it;
// and none of its slaved media elements are blocked media elements,
if (element->isBlocked())
@@ -523,8 +528,8 @@ bool MediaController::isBlocked() const
return true;
bool allPaused = true;
- for (size_t index = 0; index < m_mediaElements.size(); ++index) {
- HTMLMediaElement* element = m_mediaElements[index];
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it) {
+ HTMLMediaElement* element = *it;
// or if any of its slaved media elements are blocked media elements,
if (element->isBlocked())
@@ -555,8 +560,8 @@ bool MediaController::hasEnded() const
return false;
bool allHaveEnded = true;
- for (size_t index = 0; index < m_mediaElements.size(); ++index) {
- if (!m_mediaElements[index]->ended())
+ for (MediaElementSequence::const_iterator it = m_mediaElements.begin(); it != m_mediaElements.end(); ++it) {
+ if (!(*it)->ended())
allHaveEnded = false;
}
return allHaveEnded;
@@ -605,3 +610,11 @@ void MediaController::scheduleTimeupdateEvent()
scheduleEvent(EventTypeNames::timeupdate);
m_previousTimeupdateTime = now;
}
+
+void MediaController::trace(Visitor* visitor)
+{
+ visitor->trace(m_mediaElements);
+ EventTargetWithInlineData::trace(visitor);
+}
+
+}
« no previous file with comments | « Source/core/html/MediaController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698