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

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 177123006: Reduce HTMLMediaElement BehaviorRestrictions to a single state bit (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 , m_readyStateMaximum(HAVE_NOTHING) 268 , m_readyStateMaximum(HAVE_NOTHING)
269 , m_volume(1.0f) 269 , m_volume(1.0f)
270 , m_lastSeekTime(0) 270 , m_lastSeekTime(0)
271 , m_previousProgressTime(numeric_limits<double>::max()) 271 , m_previousProgressTime(numeric_limits<double>::max())
272 , m_duration(numeric_limits<double>::quiet_NaN()) 272 , m_duration(numeric_limits<double>::quiet_NaN())
273 , m_lastTimeUpdateEventWallTime(0) 273 , m_lastTimeUpdateEventWallTime(0)
274 , m_lastTimeUpdateEventMovieTime(numeric_limits<double>::max()) 274 , m_lastTimeUpdateEventMovieTime(numeric_limits<double>::max())
275 , m_loadState(WaitingForSource) 275 , m_loadState(WaitingForSource)
276 , m_webLayer(0) 276 , m_webLayer(0)
277 , m_opaque(false) 277 , m_opaque(false)
278 , m_restrictions(NoRestrictions)
279 , m_preload(MediaPlayer::Auto) 278 , m_preload(MediaPlayer::Auto)
280 , m_displayMode(Unknown) 279 , m_displayMode(Unknown)
281 , m_cachedTime(MediaPlayer::invalidTime()) 280 , m_cachedTime(MediaPlayer::invalidTime())
282 , m_cachedTimeWallClockUpdateTime(0) 281 , m_cachedTimeWallClockUpdateTime(0)
283 , m_minimumWallClockTimeToCacheMediaTime(0) 282 , m_minimumWallClockTimeToCacheMediaTime(0)
284 , m_fragmentStartTime(MediaPlayer::invalidTime()) 283 , m_fragmentStartTime(MediaPlayer::invalidTime())
285 , m_fragmentEndTime(MediaPlayer::invalidTime()) 284 , m_fragmentEndTime(MediaPlayer::invalidTime())
286 , m_pendingActionFlags(0) 285 , m_pendingActionFlags(0)
286 , m_userGestureRequiredForPlay(false)
287 , m_playing(false) 287 , m_playing(false)
288 , m_shouldDelayLoadEvent(false) 288 , m_shouldDelayLoadEvent(false)
289 , m_haveFiredLoadedData(false) 289 , m_haveFiredLoadedData(false)
290 , m_active(true) 290 , m_active(true)
291 , m_autoplaying(true) 291 , m_autoplaying(true)
292 , m_muted(false) 292 , m_muted(false)
293 , m_paused(true) 293 , m_paused(true)
294 , m_seeking(false) 294 , m_seeking(false)
295 , m_sentStalledEvent(false) 295 , m_sentStalledEvent(false)
296 , m_sentEndEvent(false) 296 , m_sentEndEvent(false)
(...skipping 10 matching lines...) Expand all
307 #if ENABLE(WEB_AUDIO) 307 #if ENABLE(WEB_AUDIO)
308 , m_audioSourceNode(0) 308 , m_audioSourceNode(0)
309 #endif 309 #endif
310 , m_emeMode(EmeModeNotSelected) 310 , m_emeMode(EmeModeNotSelected)
311 { 311 {
312 ASSERT(RuntimeEnabledFeatures::mediaEnabled()); 312 ASSERT(RuntimeEnabledFeatures::mediaEnabled());
313 313
314 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement"); 314 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement");
315 ScriptWrappable::init(this); 315 ScriptWrappable::init(this);
316 316
317 if (document.settings()) { 317 if (document.settings() && document.settings()->mediaPlaybackRequiresUserGes ture())
318 if (document.settings()->mediaPlaybackRequiresUserGesture()) 318 m_userGestureRequiredForPlay = true;
319 addBehaviorRestriction(RequireUserGestureForPlayRestriction);
320 }
321 319
322 // We must always have a ShadowRoot so children like <source> will not rende r 320 // We must always have a ShadowRoot so children like <source> will not rende r
323 // as they never have an insertion point. 321 // as they never have an insertion point.
324 ensureUserAgentShadowRoot(); 322 ensureUserAgentShadowRoot();
325 setHasCustomStyleCallbacks(); 323 setHasCustomStyleCallbacks();
326 addElementToDocumentMap(this, &document); 324 addElementToDocumentMap(this, &document);
327 } 325 }
328 326
329 HTMLMediaElement::~HTMLMediaElement() 327 HTMLMediaElement::~HTMLMediaElement()
330 { 328 {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 return canPlay; 612 return canPlay;
615 } 613 }
616 614
617 void HTMLMediaElement::load() 615 void HTMLMediaElement::load()
618 { 616 {
619 RefPtr<HTMLMediaElement> protect(this); // loadInternal may result in a 'bef oreload' event, which can make arbitrary DOM mutations. 617 RefPtr<HTMLMediaElement> protect(this); // loadInternal may result in a 'bef oreload' event, which can make arbitrary DOM mutations.
620 618
621 WTF_LOG(Media, "HTMLMediaElement::load()"); 619 WTF_LOG(Media, "HTMLMediaElement::load()");
622 620
623 if (UserGestureIndicator::processingUserGesture()) 621 if (UserGestureIndicator::processingUserGesture())
624 removeBehaviorsRestrictionsAfterFirstUserGesture(); 622 m_userGestureRequiredForPlay = false;
625 623
626 prepareForLoad(); 624 prepareForLoad();
627 loadInternal(); 625 loadInternal();
628 prepareToPlay(); 626 prepareToPlay();
629 } 627 }
630 628
631 void HTMLMediaElement::prepareForLoad() 629 void HTMLMediaElement::prepareForLoad()
632 { 630 {
633 WTF_LOG(Media, "HTMLMediaElement::prepareForLoad"); 631 WTF_LOG(Media, "HTMLMediaElement::prepareForLoad");
634 632
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 m_muted = true; 849 m_muted = true;
852 updateVolume(); 850 updateVolume();
853 851
854 ASSERT(!m_mediaSource); 852 ASSERT(!m_mediaSource);
855 853
856 bool attemptLoad = true; 854 bool attemptLoad = true;
857 855
858 if (url.protocolIs(mediaSourceBlobProtocol)) { 856 if (url.protocolIs(mediaSourceBlobProtocol)) {
859 if (isMediaStreamURL(url.string())) { 857 if (isMediaStreamURL(url.string())) {
860 loadType = blink::WebMediaPlayer::LoadTypeMediaStream; 858 loadType = blink::WebMediaPlayer::LoadTypeMediaStream;
861 removeBehaviorRestriction(RequireUserGestureForPlayRestriction); 859 m_userGestureRequiredForPlay = false;
862 } else { 860 } else {
863 m_mediaSource = HTMLMediaSource::lookup(url.string()); 861 m_mediaSource = HTMLMediaSource::lookup(url.string());
864 862
865 if (m_mediaSource) { 863 if (m_mediaSource) {
866 loadType = blink::WebMediaPlayer::LoadTypeMediaSource; 864 loadType = blink::WebMediaPlayer::LoadTypeMediaSource;
867 865
868 if (!m_mediaSource->attachToElement(this)) { 866 if (!m_mediaSource->attachToElement(this)) {
869 // Forget our reference to the MediaSource, so we leave it a lone 867 // Forget our reference to the MediaSource, so we leave it a lone
870 // while processing remainder of load failure. 868 // while processing remainder of load failure.
871 m_mediaSource = nullptr; 869 m_mediaSource = nullptr;
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 shouldUpdateDisplayState = true; 1599 shouldUpdateDisplayState = true;
1602 } 1600 }
1603 1601
1604 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { 1602 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) {
1605 if (oldState <= HAVE_CURRENT_DATA) { 1603 if (oldState <= HAVE_CURRENT_DATA) {
1606 scheduleEvent(EventTypeNames::canplay); 1604 scheduleEvent(EventTypeNames::canplay);
1607 if (isPotentiallyPlaying) 1605 if (isPotentiallyPlaying)
1608 scheduleEvent(EventTypeNames::playing); 1606 scheduleEvent(EventTypeNames::playing);
1609 } 1607 }
1610 1608
1611 if (m_autoplaying && m_paused && autoplay() && !document().isSandboxed(S andboxAutomaticFeatures) && !userGestureRequiredForPlay()) { 1609 if (m_autoplaying && m_paused && autoplay() && !document().isSandboxed(S andboxAutomaticFeatures) && !m_userGestureRequiredForPlay) {
1612 m_paused = false; 1610 m_paused = false;
1613 invalidateCachedTime(); 1611 invalidateCachedTime();
1614 scheduleEvent(EventTypeNames::play); 1612 scheduleEvent(EventTypeNames::play);
1615 scheduleEvent(EventTypeNames::playing); 1613 scheduleEvent(EventTypeNames::playing);
1616 } 1614 }
1617 1615
1618 scheduleEvent(EventTypeNames::canplaythrough); 1616 scheduleEvent(EventTypeNames::canplaythrough);
1619 1617
1620 shouldUpdateDisplayState = true; 1618 shouldUpdateDisplayState = true;
1621 } 1619 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 void HTMLMediaElement::setPreload(const AtomicString& preload) 2117 void HTMLMediaElement::setPreload(const AtomicString& preload)
2120 { 2118 {
2121 WTF_LOG(Media, "HTMLMediaElement::setPreload(%s)", preload.utf8().data()); 2119 WTF_LOG(Media, "HTMLMediaElement::setPreload(%s)", preload.utf8().data());
2122 setAttribute(preloadAttr, preload); 2120 setAttribute(preloadAttr, preload);
2123 } 2121 }
2124 2122
2125 void HTMLMediaElement::play() 2123 void HTMLMediaElement::play()
2126 { 2124 {
2127 WTF_LOG(Media, "HTMLMediaElement::play()"); 2125 WTF_LOG(Media, "HTMLMediaElement::play()");
2128 2126
2129 if (userGestureRequiredForPlay() && !UserGestureIndicator::processingUserGes ture()) 2127 if (m_userGestureRequiredForPlay && !UserGestureIndicator::processingUserGes ture())
2130 return; 2128 return;
2131 if (UserGestureIndicator::processingUserGesture()) 2129 if (UserGestureIndicator::processingUserGesture())
2132 removeBehaviorsRestrictionsAfterFirstUserGesture(); 2130 m_userGestureRequiredForPlay = false;
2133 2131
2134 playInternal(); 2132 playInternal();
2135 } 2133 }
2136 2134
2137 void HTMLMediaElement::playInternal() 2135 void HTMLMediaElement::playInternal()
2138 { 2136 {
2139 WTF_LOG(Media, "HTMLMediaElement::playInternal"); 2137 WTF_LOG(Media, "HTMLMediaElement::playInternal");
2140 2138
2141 // 4.8.10.9. Playing the media resource 2139 // 4.8.10.9. Playing the media resource
2142 if (!m_player || m_networkState == NETWORK_EMPTY) 2140 if (!m_player || m_networkState == NETWORK_EMPTY)
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3866 MediaPlayerClient::CORSMode HTMLMediaElement::mediaPlayerCORSMode() const 3864 MediaPlayerClient::CORSMode HTMLMediaElement::mediaPlayerCORSMode() const
3867 { 3865 {
3868 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr); 3866 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr);
3869 if (crossOriginMode.isNull()) 3867 if (crossOriginMode.isNull())
3870 return Unspecified; 3868 return Unspecified;
3871 if (equalIgnoringCase(crossOriginMode, "use-credentials")) 3869 if (equalIgnoringCase(crossOriginMode, "use-credentials"))
3872 return UseCredentials; 3870 return UseCredentials;
3873 return Anonymous; 3871 return Anonymous;
3874 } 3872 }
3875 3873
3876 void HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture()
3877 {
3878 m_restrictions = NoRestrictions;
3879 }
3880
3881 void HTMLMediaElement::mediaPlayerSetWebLayer(blink::WebLayer* webLayer) 3874 void HTMLMediaElement::mediaPlayerSetWebLayer(blink::WebLayer* webLayer)
3882 { 3875 {
3883 if (webLayer == m_webLayer) 3876 if (webLayer == m_webLayer)
3884 return; 3877 return;
3885 3878
3886 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc. 3879 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc.
3887 if (!m_webLayer || !webLayer) 3880 if (!m_webLayer || !webLayer)
3888 scheduleLayerUpdate(); 3881 scheduleLayerUpdate();
3889 3882
3890 if (m_webLayer) 3883 if (m_webLayer)
(...skipping 16 matching lines...) Expand all
3907 { 3900 {
3908 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); 3901 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource));
3909 } 3902 }
3910 3903
3911 bool HTMLMediaElement::isInteractiveContent() const 3904 bool HTMLMediaElement::isInteractiveContent() const
3912 { 3905 {
3913 return fastHasAttribute(controlsAttr); 3906 return fastHasAttribute(controlsAttr);
3914 } 3907 }
3915 3908
3916 } 3909 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698