OLD | NEW |
---|---|
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 void didMoveToNewDocument(Document& oldDocument) override; | 279 void didMoveToNewDocument(Document& oldDocument) override; |
280 virtual KURL posterImageURL() const { return KURL(); } | 280 virtual KURL posterImageURL() const { return KURL(); } |
281 | 281 |
282 enum DisplayMode { Unknown, Poster, Video }; | 282 enum DisplayMode { Unknown, Poster, Video }; |
283 DisplayMode displayMode() const { return m_displayMode; } | 283 DisplayMode displayMode() const { return m_displayMode; } |
284 virtual void setDisplayMode(DisplayMode mode) { m_displayMode = mode; } | 284 virtual void setDisplayMode(DisplayMode mode) { m_displayMode = mode; } |
285 | 285 |
286 void setControllerInternal(MediaController*); | 286 void setControllerInternal(MediaController*); |
287 | 287 |
288 private: | 288 private: |
289 // These values are used for a histogram. Do not reorder. | |
290 enum AutoplayMetrics { | |
291 // Media element with autoplay seen. | |
292 AutoplayMediaFound = 0, | |
293 // Autoplay enabled and user stopped media play at any point. | |
294 AutoplayStopped = 1, | |
295 // Autoplay enabled but user bailed out on media play early. | |
296 AutoplayBailout = 2, | |
297 // Autoplay disabled but user manually started media. | |
298 AutoplayManualStart = 3, | |
299 // Autoplay was (re)enabled through a user-gesture triggered load() | |
300 AutoplayEnabledThroughLoad = 4, | |
301 // Autoplay disabled by sandbox flags. | |
302 AutoplayDisabledBySandbox = 5, | |
303 | |
304 // These metrics indicate "no gesture but gesture requirement was | |
305 // overridden by experiment". They do not include cases where no | |
306 // user gesture is required (!m_userGestureRequiredForPlay). | |
307 // Gestureless playback when media scrolled into view. We don't | |
308 // record whether it was a javascript or attribute autoplay request. | |
309 GesturelessPlaybackStartedByScroll = 6, | |
310 // Autoplay started by experiment override during initial load. | |
311 GesturelessPlaybackStartedByLoad = 7, | |
312 // Autoplay started by experiment override in play() call. | |
313 GesturelessPlaybackStartedByPlayMethod = 8, | |
314 | |
315 // play() failed to play due to gesture requirement. | |
316 PlayMethodFailed = 9, | |
317 | |
318 // Some play, whether user initiated or not, started. | |
319 AnyPlaybackStarted = 10, | |
320 // Some play, whether user initiated or not, stopped. | |
321 AnyPlaybackStopped = 11, | |
322 // Some playback, whether user initiated or not, bailed out early. | |
323 AnyPlaybackBailout = 12, | |
324 | |
325 // This enum value must be last. | |
326 NumberOfAutoplayMetrics, | |
327 }; | |
328 | |
289 void resetMediaPlayerAndMediaSource(); | 329 void resetMediaPlayerAndMediaSource(); |
290 | 330 |
291 bool alwaysCreateUserAgentShadowRoot() const final { return true; } | 331 bool alwaysCreateUserAgentShadowRoot() const final { return true; } |
292 bool areAuthorShadowsAllowed() const final { return false; } | 332 bool areAuthorShadowsAllowed() const final { return false; } |
293 | 333 |
294 bool supportsFocus() const final; | 334 bool supportsFocus() const final; |
295 bool isMouseFocusable() const final; | 335 bool isMouseFocusable() const final; |
296 bool layoutObjectIsNeeded(const ComputedStyle&) override; | 336 bool layoutObjectIsNeeded(const ComputedStyle&) override; |
297 LayoutObject* createLayoutObject(const ComputedStyle&) override; | 337 LayoutObject* createLayoutObject(const ComputedStyle&) override; |
298 InsertionNotificationRequest insertedInto(ContainerNode*) final; | 338 InsertionNotificationRequest insertedInto(ContainerNode*) final; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 void executeDeferredLoad(); | 423 void executeDeferredLoad(); |
384 void deferredLoadTimerFired(Timer<HTMLMediaElement>*); | 424 void deferredLoadTimerFired(Timer<HTMLMediaElement>*); |
385 | 425 |
386 HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const; | 426 HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const; |
387 | 427 |
388 void markCaptionAndSubtitleTracksAsUnconfigured(); | 428 void markCaptionAndSubtitleTracksAsUnconfigured(); |
389 | 429 |
390 // This does not check user gesture restrictions. | 430 // This does not check user gesture restrictions. |
391 void playInternal(); | 431 void playInternal(); |
392 | 432 |
393 void gesturelessInitialPlayHalted(); | 433 // If we are about to enter a stopped state, call this to record |
434 // autoplay metrics. If we were already in a stopped state, then | |
435 // this does nothing. | |
436 void recordMetricsIfStopping(); | |
437 // Could stopping at this point be considered a bailout of playback? | |
438 // (as in, "The user really didn't want to play this"). | |
439 bool isBailout() const; | |
dglazkov
2015/08/06 20:55:23
This seems like it could be a separate CL.
| |
394 void autoplayMediaEncountered(); | 440 void autoplayMediaEncountered(); |
395 void allowVideoRendering(); | 441 void allowVideoRendering(); |
396 | 442 |
397 void updateVolume(); | 443 void updateVolume(); |
398 void updatePlayState(); | 444 void updatePlayState(); |
399 bool potentiallyPlaying() const; | 445 bool potentiallyPlaying() const; |
400 bool stoppedDueToErrors() const; | 446 bool stoppedDueToErrors() const; |
401 bool couldPlayIfEnoughData() const; | 447 bool couldPlayIfEnoughData() const; |
402 | 448 |
403 // Generally the presence of the loop attribute should be considered to mean playback | 449 // Generally the presence of the loop attribute should be considered to mean playback |
(...skipping 15 matching lines...) Expand all Loading... | |
419 | 465 |
420 void changeNetworkStateFromLoadingToIdle(); | 466 void changeNetworkStateFromLoadingToIdle(); |
421 | 467 |
422 const AtomicString& mediaGroup() const; | 468 const AtomicString& mediaGroup() const; |
423 void setMediaGroup(const AtomicString&); | 469 void setMediaGroup(const AtomicString&); |
424 void updateMediaController(); | 470 void updateMediaController(); |
425 bool isBlocked() const; | 471 bool isBlocked() const; |
426 bool isBlockedOnMediaController() const; | 472 bool isBlockedOnMediaController() const; |
427 bool isAutoplaying() const { return m_autoplaying; } | 473 bool isAutoplaying() const { return m_autoplaying; } |
428 | 474 |
475 void recordAutoplayMetric(AutoplayMetrics); | |
476 | |
477 // vvvv Helpers for clank autoplay investigation vvvv | |
dglazkov
2015/08/06 20:55:23
Please no ASCII art -___-
liberato (no reviews please)
2015/08/07 21:53:16
.-'''-.
______
| |
478 | |
479 // Install an event listener to check for changes in visibility. If a | |
480 // listener is already installed, then this does nothing. | |
481 void autoplayExperimentInstallEventListenerIfNeeded(); | |
dglazkov
2015/08/06 20:55:23
I would like to avoid spamming already-large class
liberato (no reviews please)
2015/08/07 21:53:16
this change makes me happy. PS19 has most of the
| |
482 | |
483 // Remove any event listener. It's okay to call this if one isn't | |
484 // installed already. | |
485 void autoplayExperimentClearEventListenerIfNeeded(); | |
486 | |
487 // Return true if any only if this player meets (most) of the eligibility | |
488 // requirements for the experiment to override the need for a user | |
489 // gesture. This includes everything except the visibility test. | |
490 bool autoplayExperimentIsEligible() const; | |
491 | |
492 // Return true if and only if the player is visible. | |
493 bool autoplayExperimentIsInViewportIfNeeded(); | |
494 | |
495 // Set the mute flag on the media if we're in an experiment mode that | |
496 // requires it, else do nothing. | |
497 void autoplayExperimentMuteIfNeeded(); | |
498 | |
499 // Maybe override the requirement for a user gesture, and start playing | |
500 // autoplay media. Returns true if only if it starts playback. | |
501 bool autoplayExperimentMaybeStartPlaying(); | |
502 | |
503 // Configure internal state to record that the autoplay experiment is | |
504 // going to start playback. This doesn't actually start playback, since | |
505 // there are several different cases. | |
506 void autoplayExperimentPrepareToPlay(AutoplayMetrics); | |
507 | |
508 // Begin (or start over) a periodic check for visibility. We will poll | |
509 // during this check to see if the video is in the viewport. | |
510 void notifyScrolled(); | |
511 | |
512 // Process a timer for checking visibility. | |
513 void viewportTimerFired(Timer<HTMLMediaElement>*); | |
514 // ^^^^ Helpers for clank autoplay investigation ^^^^ | |
515 | |
429 WebMediaPlayer::CORSMode corsMode() const; | 516 WebMediaPlayer::CORSMode corsMode() const; |
430 | 517 |
431 // Returns the "direction of playback" value as specified in the HTML5 spec. | 518 // Returns the "direction of playback" value as specified in the HTML5 spec. |
432 enum DirectionOfPlayback { Backward, Forward }; | 519 enum DirectionOfPlayback { Backward, Forward }; |
433 DirectionOfPlayback directionOfPlayback() const; | 520 DirectionOfPlayback directionOfPlayback() const; |
434 | 521 |
435 // Returns the "effective playback rate" value as specified in the HTML5 spe c. | 522 // Returns the "effective playback rate" value as specified in the HTML5 spe c. |
436 double effectivePlaybackRate() const; | 523 double effectivePlaybackRate() const; |
437 | 524 |
438 // Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaP layer objects | 525 // Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaP layer objects |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 bool m_playingRemotely : 1; | 634 bool m_playingRemotely : 1; |
548 bool m_isFinalizing : 1; | 635 bool m_isFinalizing : 1; |
549 bool m_initialPlayWithoutUserGestures : 1; | 636 bool m_initialPlayWithoutUserGestures : 1; |
550 bool m_autoplayMediaCounted : 1; | 637 bool m_autoplayMediaCounted : 1; |
551 | 638 |
552 PersistentWillBeMember<AudioTrackList> m_audioTracks; | 639 PersistentWillBeMember<AudioTrackList> m_audioTracks; |
553 PersistentWillBeMember<VideoTrackList> m_videoTracks; | 640 PersistentWillBeMember<VideoTrackList> m_videoTracks; |
554 PersistentWillBeMember<TextTrackList> m_textTracks; | 641 PersistentWillBeMember<TextTrackList> m_textTracks; |
555 PersistentHeapVectorWillBeHeapVector<Member<TextTrack>> m_textTracksWhenReso urceSelectionBegan; | 642 PersistentHeapVectorWillBeHeapVector<Member<TextTrack>> m_textTracksWhenReso urceSelectionBegan; |
556 | 643 |
644 // Autoplay experiment state. | |
645 // True if we've received a play() without a pause(). | |
646 bool m_autoplayExperimentPlayPending : 1; | |
647 | |
648 // Autoplay experiment state. | |
649 // True if and only if we initiated playback because of the autoplay | |
650 // experiment. Once set, this is never unset. | |
651 bool m_autoplayExperimentStartedByExperiment : 1; | |
652 | |
653 // Autoplay experiment state. | |
654 // Scroll listener for the autoplay experiment, to help us determine when | |
655 // the user has scrolled the player into the viewport. | |
656 class AutoplayExperimentScrollListener; | |
657 friend class AutoplayExperimentScrollListener; | |
658 RefPtrWillBeMember<EventListener> m_autoplayExperimentScrollListener; | |
659 | |
660 enum AutoplayExperimentMode { | |
661 ExperimentOff = 0, | |
662 ExperimentEnabled = 1 << 0, | |
663 ExperimentIfViewport = 1 << 1, | |
664 ExperimentIfMuted = 1 << 2, | |
665 ExperimentIfMobile = 1 << 3, | |
666 ExperimentPlayMuted = 1 << 4 | |
667 }; | |
668 int m_autoplayExperimentMode; // Bitwise-or of AutoplayExperimentMode | |
669 | |
557 OwnPtrWillBeMember<CueTimeline> m_cueTimeline; | 670 OwnPtrWillBeMember<CueTimeline> m_cueTimeline; |
558 | 671 |
559 #if ENABLE(WEB_AUDIO) | 672 #if ENABLE(WEB_AUDIO) |
560 // This is a weak reference, since m_audioSourceNode holds a reference to us . | 673 // This is a weak reference, since m_audioSourceNode holds a reference to us . |
561 // FIXME: Oilpan: Consider making this a strongly traced pointer with oilpan where strong cycles are not a problem. | 674 // FIXME: Oilpan: Consider making this a strongly traced pointer with oilpan where strong cycles are not a problem. |
562 GC_PLUGIN_IGNORE("http://crbug.com/404577") | 675 GC_PLUGIN_IGNORE("http://crbug.com/404577") |
563 RawPtrWillBeWeakMember<AudioSourceProviderClient> m_audioSourceNode; | 676 RawPtrWillBeWeakMember<AudioSourceProviderClient> m_audioSourceNode; |
564 | 677 |
565 // AudioClientImpl wraps an AudioSourceProviderClient. | 678 // AudioClientImpl wraps an AudioSourceProviderClient. |
566 // When the audio format is known, Chromium calls setFormat(). | 679 // When the audio format is known, Chromium calls setFormat(). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 | 718 |
606 private: | 719 private: |
607 WebAudioSourceProvider* m_webAudioSourceProvider; | 720 WebAudioSourceProvider* m_webAudioSourceProvider; |
608 PersistentWillBeMember<AudioClientImpl> m_client; | 721 PersistentWillBeMember<AudioClientImpl> m_client; |
609 Mutex provideInputLock; | 722 Mutex provideInputLock; |
610 }; | 723 }; |
611 | 724 |
612 AudioSourceProviderImpl m_audioSourceProvider; | 725 AudioSourceProviderImpl m_audioSourceProvider; |
613 #endif | 726 #endif |
614 | 727 |
728 Timer<HTMLMediaElement> m_autoplayViewportTimer; | |
dglazkov
2015/08/06 20:55:23
Using timers here seems bad. Why?
liberato (no reviews please)
2015/08/07 21:53:17
we want to know when a scroll has (probably) ended
ojan
2015/08/11 02:45:21
I think having a timer is good. The problem is wha
liberato (no reviews please)
2015/09/01 06:54:19
thanks for the detailed description! the most rec
| |
729 double m_autoplayLastScrollX; | |
730 double m_autoplayLastScrollY; | |
731 double m_autoplayViewportTimerSpan; | |
732 | |
615 friend class MediaController; | 733 friend class MediaController; |
616 PersistentWillBeMember<MediaController> m_mediaController; | 734 PersistentWillBeMember<MediaController> m_mediaController; |
617 | 735 |
618 friend class Internals; | 736 friend class Internals; |
619 friend class TrackDisplayUpdateScope; | 737 friend class TrackDisplayUpdateScope; |
620 | 738 |
621 static URLRegistry* s_mediaStreamRegistry; | 739 static URLRegistry* s_mediaStreamRegistry; |
622 }; | 740 }; |
623 | 741 |
624 inline bool isHTMLMediaElement(const HTMLElement& element) | 742 inline bool isHTMLMediaElement(const HTMLElement& element) |
625 { | 743 { |
626 return isHTMLAudioElement(element) || isHTMLVideoElement(element); | 744 return isHTMLAudioElement(element) || isHTMLVideoElement(element); |
627 } | 745 } |
628 | 746 |
629 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement); | 747 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement); |
630 | 748 |
631 } // namespace blink | 749 } // namespace blink |
632 | 750 |
633 #endif // HTMLMediaElement_h | 751 #endif // HTMLMediaElement_h |
OLD | NEW |