Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 using namespace HTMLNames; | 121 using namespace HTMLNames; |
| 122 | 122 |
| 123 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; | 123 using WeakMediaElementSet = HeapHashSet<WeakMember<HTMLMediaElement>>; |
| 124 using DocumentElementSetMap = | 124 using DocumentElementSetMap = |
| 125 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>; | 125 HeapHashMap<WeakMember<Document>, Member<WeakMediaElementSet>>; |
| 126 | 126 |
| 127 namespace { | 127 namespace { |
| 128 | 128 |
| 129 constexpr float kMostlyFillViewportThreshold = 0.85f; | 129 constexpr float kMostlyFillViewportThreshold = 0.85f; |
| 130 constexpr double kMostlyFillViewportBecomeStableSeconds = 5; | 130 constexpr double kMostlyFillViewportBecomeStableSeconds = 5; |
| 131 constexpr double kCheckIntersectWhenPausedIntervalInSeconds = 2; | |
|
miu
2016/12/10 02:18:37
If the "stable" check is 5 seconds, the timer inte
xjz
2016/12/12 18:58:45
Done.
| |
| 131 | 132 |
| 132 enum MediaControlsShow { | 133 enum MediaControlsShow { |
| 133 MediaControlsShowAttribute = 0, | 134 MediaControlsShowAttribute = 0, |
| 134 MediaControlsShowFullscreen, | 135 MediaControlsShowFullscreen, |
| 135 MediaControlsShowNoScript, | 136 MediaControlsShowNoScript, |
| 136 MediaControlsShowNotShown, | 137 MediaControlsShowNotShown, |
| 137 MediaControlsShowMax | 138 MediaControlsShowMax |
| 138 }; | 139 }; |
| 139 | 140 |
| 140 String urlForLoggingMedia(const KURL& url) { | 141 String urlForLoggingMedia(const KURL& url) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 ActiveScriptWrappable(this), | 364 ActiveScriptWrappable(this), |
| 364 ActiveDOMObject(&document), | 365 ActiveDOMObject(&document), |
| 365 m_loadTimer(this, &HTMLMediaElement::loadTimerFired), | 366 m_loadTimer(this, &HTMLMediaElement::loadTimerFired), |
| 366 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired), | 367 m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired), |
| 367 m_playbackProgressTimer(this, | 368 m_playbackProgressTimer(this, |
| 368 &HTMLMediaElement::playbackProgressTimerFired), | 369 &HTMLMediaElement::playbackProgressTimerFired), |
| 369 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired), | 370 m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired), |
| 370 m_viewportFillDebouncerTimer( | 371 m_viewportFillDebouncerTimer( |
| 371 this, | 372 this, |
| 372 &HTMLMediaElement::viewportFillDebouncerTimerFired), | 373 &HTMLMediaElement::viewportFillDebouncerTimerFired), |
| 374 m_checkIntersectionWhenPausedTimer( | |
| 375 this, | |
| 376 &HTMLMediaElement::checkIntersectionWhenPausedTimerFired), | |
| 373 m_playedTimeRanges(), | 377 m_playedTimeRanges(), |
| 374 m_asyncEventQueue(GenericEventQueue::create(this)), | 378 m_asyncEventQueue(GenericEventQueue::create(this)), |
| 375 m_playbackRate(1.0f), | 379 m_playbackRate(1.0f), |
| 376 m_defaultPlaybackRate(1.0f), | 380 m_defaultPlaybackRate(1.0f), |
| 377 m_networkState(kNetworkEmpty), | 381 m_networkState(kNetworkEmpty), |
| 378 m_readyState(kHaveNothing), | 382 m_readyState(kHaveNothing), |
| 379 m_readyStateMaximum(kHaveNothing), | 383 m_readyStateMaximum(kHaveNothing), |
| 380 m_volume(1.0f), | 384 m_volume(1.0f), |
| 381 m_lastSeekTime(0), | 385 m_lastSeekTime(0), |
| 382 m_previousProgressTime(std::numeric_limits<double>::max()), | 386 m_previousProgressTime(std::numeric_limits<double>::max()), |
| (...skipping 2864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3247 | 3251 |
| 3248 if (!isPlaying) { | 3252 if (!isPlaying) { |
| 3249 // Set rate, muted before calling play in case they were set before the | 3253 // Set rate, muted before calling play in case they were set before the |
| 3250 // media engine was setup. The media engine should just stash the rate | 3254 // media engine was setup. The media engine should just stash the rate |
| 3251 // and muted values since it isn't already playing. | 3255 // and muted values since it isn't already playing. |
| 3252 webMediaPlayer()->setRate(playbackRate()); | 3256 webMediaPlayer()->setRate(playbackRate()); |
| 3253 webMediaPlayer()->setVolume(effectiveMediaVolume()); | 3257 webMediaPlayer()->setVolume(effectiveMediaVolume()); |
| 3254 webMediaPlayer()->play(); | 3258 webMediaPlayer()->play(); |
| 3255 } | 3259 } |
| 3256 | 3260 |
| 3261 m_checkIntersectionWhenPausedTimer.stop(); | |
| 3257 startPlaybackProgressTimer(); | 3262 startPlaybackProgressTimer(); |
| 3258 m_playing = true; | 3263 m_playing = true; |
| 3259 } else { // Should not be playing right now | 3264 } else { // Should not be playing right now |
| 3260 if (isPlaying) { | 3265 if (isPlaying) { |
| 3261 webMediaPlayer()->pause(); | 3266 webMediaPlayer()->pause(); |
| 3262 } | 3267 } |
| 3263 | 3268 |
| 3264 m_playbackProgressTimer.stop(); | 3269 m_playbackProgressTimer.stop(); |
| 3270 startCheckIntersectionWhenPausedTimer(); | |
| 3265 m_playing = false; | 3271 m_playing = false; |
| 3266 double time = currentTime(); | 3272 double time = currentTime(); |
| 3267 if (time > m_lastSeekTime) | 3273 if (time > m_lastSeekTime) |
| 3268 addPlayedRange(m_lastSeekTime, time); | 3274 addPlayedRange(m_lastSeekTime, time); |
| 3269 } | 3275 } |
| 3270 | 3276 |
| 3271 if (layoutObject()) | 3277 if (layoutObject()) |
| 3272 layoutObject()->updateFromElement(); | 3278 layoutObject()->updateFromElement(); |
| 3273 } | 3279 } |
| 3274 | 3280 |
| 3275 void HTMLMediaElement::stopPeriodicTimers() { | 3281 void HTMLMediaElement::stopPeriodicTimers() { |
| 3276 m_progressEventTimer.stop(); | 3282 m_progressEventTimer.stop(); |
| 3277 m_playbackProgressTimer.stop(); | 3283 m_playbackProgressTimer.stop(); |
| 3284 m_checkIntersectionWhenPausedTimer.stop(); | |
|
miu
2016/12/10 02:18:37
If you take my advice below, this extra stop() cal
xjz
2016/12/12 18:58:45
Done.
| |
| 3278 } | 3285 } |
| 3279 | 3286 |
| 3280 void HTMLMediaElement:: | 3287 void HTMLMediaElement:: |
| 3281 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking() { | 3288 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking() { |
| 3282 getAudioSourceProvider().setClient(nullptr); | 3289 getAudioSourceProvider().setClient(nullptr); |
| 3283 if (m_webMediaPlayer) { | 3290 if (m_webMediaPlayer) { |
| 3284 m_audioSourceProvider.wrap(nullptr); | 3291 m_audioSourceProvider.wrap(nullptr); |
| 3285 m_webMediaPlayer.reset(); | 3292 m_webMediaPlayer.reset(); |
| 3286 } | 3293 } |
| 3287 } | 3294 } |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4026 } | 4033 } |
| 4027 | 4034 |
| 4028 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) { | 4035 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) { |
| 4029 visitor->trace(m_client); | 4036 visitor->trace(m_client); |
| 4030 } | 4037 } |
| 4031 | 4038 |
| 4032 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) { | 4039 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) { |
| 4033 visitor->trace(m_client); | 4040 visitor->trace(m_client); |
| 4034 } | 4041 } |
| 4035 | 4042 |
| 4043 void HTMLMediaElement::enableMonitorViewportIntersection(bool enable) { | |
| 4044 m_enableMonitorViewportIntersection = enable; | |
|
miu
2016/12/10 02:18:37
IMHO, this would all be simpler if we didn't have
xjz
2016/12/12 18:58:45
Done.
| |
| 4045 } | |
| 4046 | |
| 4036 void HTMLMediaElement::checkViewportIntersectionChanged() { | 4047 void HTMLMediaElement::checkViewportIntersectionChanged() { |
| 4037 // TODO(xjz): Early return if we not in tab mirroring. | 4048 if (!m_enableMonitorViewportIntersection) |
| 4049 return; | |
| 4038 | 4050 |
| 4039 IntersectionGeometry geometry( | 4051 IntersectionGeometry geometry( |
| 4040 document().frame()->localFrameRoot()->document(), this, Vector<Length>(), | 4052 document().frame()->localFrameRoot()->document(), this, Vector<Length>(), |
| 4041 IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds); | 4053 IntersectionGeometry::ReportRootBounds::kShouldReportRootBounds); |
| 4042 geometry.computeGeometry(); | 4054 geometry.computeGeometry(); |
| 4043 IntRect intersectRect = geometry.intersectionIntRect(); | 4055 IntRect intersectRect = geometry.intersectionIntRect(); |
| 4044 if (m_currentIntersectRect == intersectRect) | 4056 if (m_currentIntersectRect == intersectRect) |
| 4045 return; | 4057 return; |
| 4046 | 4058 |
| 4047 m_currentIntersectRect = intersectRect; | 4059 m_currentIntersectRect = intersectRect; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4064 m_viewportFillDebouncerTimer.startOneShot( | 4076 m_viewportFillDebouncerTimer.startOneShot( |
| 4065 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); | 4077 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); |
| 4066 } | 4078 } |
| 4067 | 4079 |
| 4068 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { | 4080 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { |
| 4069 m_mostlyFillingViewport = true; | 4081 m_mostlyFillingViewport = true; |
| 4070 if (m_webMediaPlayer) | 4082 if (m_webMediaPlayer) |
| 4071 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); | 4083 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); |
| 4072 } | 4084 } |
| 4073 | 4085 |
| 4086 void HTMLMediaElement::checkIntersectionWhenPausedTimerFired(TimerBase*) { | |
| 4087 checkViewportIntersectionChanged(); | |
| 4088 } | |
| 4089 | |
| 4090 void HTMLMediaElement::startCheckIntersectionWhenPausedTimer() { | |
| 4091 if (m_checkIntersectionWhenPausedTimer.isActive()) | |
| 4092 return; | |
| 4093 | |
| 4094 m_checkIntersectionWhenPausedTimer.startRepeating( | |
| 4095 kCheckIntersectWhenPausedIntervalInSeconds, BLINK_FROM_HERE); | |
| 4096 } | |
| 4097 | |
| 4074 } // namespace blink | 4098 } // namespace blink |
| OLD | NEW |