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

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

Issue 2075563003: [Android, Media] Don't unlock MediaStream elements; instead allow MS to autoplay without a gesture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 , m_seeking(false) 434 , m_seeking(false)
435 , m_sentStalledEvent(false) 435 , m_sentStalledEvent(false)
436 , m_ignorePreloadNone(false) 436 , m_ignorePreloadNone(false)
437 , m_textTracksVisible(false) 437 , m_textTracksVisible(false)
438 , m_shouldPerformAutomaticTrackSelection(true) 438 , m_shouldPerformAutomaticTrackSelection(true)
439 , m_tracksAreReady(true) 439 , m_tracksAreReady(true)
440 , m_processingPreferenceChange(false) 440 , m_processingPreferenceChange(false)
441 , m_remoteRoutesAvailable(false) 441 , m_remoteRoutesAvailable(false)
442 , m_playingRemotely(false) 442 , m_playingRemotely(false)
443 , m_inOverlayFullscreenVideo(false) 443 , m_inOverlayFullscreenVideo(false)
444 , m_unlockedUserGestureForMediaStream(false)
444 , m_audioTracks(AudioTrackList::create(*this)) 445 , m_audioTracks(AudioTrackList::create(*this))
445 , m_videoTracks(VideoTrackList::create(*this)) 446 , m_videoTracks(VideoTrackList::create(*this))
446 , m_textTracks(nullptr) 447 , m_textTracks(nullptr)
447 , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaEl ement::resolveScheduledPlayPromises)) 448 , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaEl ement::resolveScheduledPlayPromises))
448 , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaEle ment::rejectScheduledPlayPromises)) 449 , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaEle ment::rejectScheduledPlayPromises))
449 , m_audioSourceNode(nullptr) 450 , m_audioSourceNode(nullptr)
450 , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)) 451 , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this))
451 , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.g et())) 452 , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.g et()))
452 , m_remotePlaybackClient(nullptr) 453 , m_remotePlaybackClient(nullptr)
453 { 454 {
454 ThreadState::current()->registerPreFinalizer(this); 455 ThreadState::current()->registerPreFinalizer(this);
455 456
456 DVLOG(MEDIA_LOG_LEVEL) << "HTMLMediaElement(" << (void*)this << ")"; 457 DVLOG(MEDIA_LOG_LEVEL) << "HTMLMediaElement(" << (void*)this << ")";
457 458
458 // If any experiment is enabled, then we want to enable a user gesture by 459 m_lockedPendingUserGesture = needToLockPendingUserGesture(document);
459 // default, otherwise the experiment does nothing.
460 if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGe sture())
461 || m_autoplayHelper->isExperimentEnabled()) {
462 m_lockedPendingUserGesture = true;
463 }
464 460
465 setHasCustomStyleCallbacks(); 461 setHasCustomStyleCallbacks();
466 addElementToDocumentMap(this, &document); 462 addElementToDocumentMap(this, &document);
467 463
468 UseCounter::count(document, UseCounter::HTMLMediaElement); 464 UseCounter::count(document, UseCounter::HTMLMediaElement);
469 } 465 }
470 466
471 HTMLMediaElement::~HTMLMediaElement() 467 HTMLMediaElement::~HTMLMediaElement()
472 { 468 {
473 DVLOG(MEDIA_LOG_LEVEL) << "~HTMLMediaElement(" << (void*)this << ")"; 469 DVLOG(MEDIA_LOG_LEVEL) << "~HTMLMediaElement(" << (void*)this << ")";
(...skipping 18 matching lines...) Expand all
492 // Also see http://crbug.com/275223 for more details. 488 // Also see http://crbug.com/275223 for more details.
493 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); 489 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
494 } 490 }
495 491
496 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) 492 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
497 { 493 {
498 DVLOG(MEDIA_LOG_LEVEL) << "didMoveToNewDocument(" << (void*)this << ")"; 494 DVLOG(MEDIA_LOG_LEVEL) << "didMoveToNewDocument(" << (void*)this << ")";
499 495
500 // If any experiment is enabled, then we want to enable a user gesture by 496 // If any experiment is enabled, then we want to enable a user gesture by
501 // default, otherwise the experiment does nothing. 497 // default, otherwise the experiment does nothing.
502 bool oldDocumentRequiresUserGesture = (oldDocument.settings() && oldDocument .settings()->mediaPlaybackRequiresUserGesture()) 498 bool oldDocumentRequiresUserGesture = needToLockPendingUserGesture(oldDocume nt);
503 || m_autoplayHelper->isExperimentEnabled(); 499 bool newDocumentRequiresUserGesture = needToLockPendingUserGesture(document( ));
504 bool newDocumentRequiresUserGesture = (document().settings() && document().s ettings()->mediaPlaybackRequiresUserGesture())
505 || m_autoplayHelper->isExperimentEnabled();
506 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) { 500 if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) {
507 m_lockedPendingUserGesture = true; 501 m_lockedPendingUserGesture = true;
508 } 502 }
509 503
510 if (m_shouldDelayLoadEvent) { 504 if (m_shouldDelayLoadEvent) {
511 document().incrementLoadEventDelayCount(); 505 document().incrementLoadEventDelayCount();
512 // Note: Keeping the load event delay count increment on oldDocument tha t was added 506 // Note: Keeping the load event delay count increment on oldDocument tha t was added
513 // when m_shouldDelayLoadEvent was set so that destruction of m_webMedia Player can not 507 // when m_shouldDelayLoadEvent was set so that destruction of m_webMedia Player can not
514 // cause load event dispatching in oldDocument. 508 // cause load event dispatching in oldDocument.
515 } else { 509 } else {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 683 }
690 684
691 void HTMLMediaElement::setSrc(const AtomicString& url) 685 void HTMLMediaElement::setSrc(const AtomicString& url)
692 { 686 {
693 setAttribute(srcAttr, url); 687 setAttribute(srcAttr, url);
694 } 688 }
695 689
696 void HTMLMediaElement::setSrcObject(MediaStreamDescriptor* srcObject) 690 void HTMLMediaElement::setSrcObject(MediaStreamDescriptor* srcObject)
697 { 691 {
698 DVLOG(MEDIA_LOG_LEVEL) << "setSrcObject(" << (void*)this << ")"; 692 DVLOG(MEDIA_LOG_LEVEL) << "setSrcObject(" << (void*)this << ")";
693
699 m_srcObject = srcObject; 694 m_srcObject = srcObject;
695
696 if (m_unlockedUserGestureForMediaStream)
697 lockUserGesture();
698
700 invokeLoadAlgorithm(); 699 invokeLoadAlgorithm();
701 } 700 }
702 701
703 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const 702 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const
704 { 703 {
705 return m_networkState; 704 return m_networkState;
706 } 705 }
707 706
708 String HTMLMediaElement::canPlayType(const String& mimeType) const 707 String HTMLMediaElement::canPlayType(const String& mimeType) const
709 { 708 {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 1003
1005 // The resource fetch algorithm 1004 // The resource fetch algorithm
1006 setNetworkState(NETWORK_LOADING); 1005 setNetworkState(NETWORK_LOADING);
1007 1006
1008 m_autoplayHelper->loadingStarted(); 1007 m_autoplayHelper->loadingStarted();
1009 1008
1010 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app 1009 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app
1011 // cache is an internal detail not exposed through the media element API. 1010 // cache is an internal detail not exposed through the media element API.
1012 m_currentSrc = url; 1011 m_currentSrc = url;
1013 1012
1013 if (m_unlockedUserGestureForMediaStream)
1014 lockUserGesture();
1015
1014 if (m_audioSourceNode) 1016 if (m_audioSourceNode)
1015 m_audioSourceNode->onCurrentSrcChanged(m_currentSrc); 1017 m_audioSourceNode->onCurrentSrcChanged(m_currentSrc);
1016 1018
1017 DVLOG(MEDIA_LOG_LEVEL) << "loadResource(" << (void*)this << ") - m_currentSr c -> " << urlForLoggingMedia(m_currentSrc); 1019 DVLOG(MEDIA_LOG_LEVEL) << "loadResource(" << (void*)this << ") - m_currentSr c -> " << urlForLoggingMedia(m_currentSrc);
1018 1020
1019 startProgressEventTimer(); 1021 startProgressEventTimer();
1020 1022
1021 // Reset display mode to force a recalculation of what to show because we ar e resetting the player. 1023 // Reset display mode to force a recalculation of what to show because we ar e resetting the player.
1022 setDisplayMode(Unknown); 1024 setDisplayMode(Unknown);
1023 1025
1024 setPlayerPreload(); 1026 setPlayerPreload();
1025 1027
1026 if (fastHasAttribute(mutedAttr)) 1028 if (fastHasAttribute(mutedAttr))
1027 m_muted = true; 1029 m_muted = true;
1028 updateVolume(); 1030 updateVolume();
1029 1031
1030 DCHECK(!m_mediaSource); 1032 DCHECK(!m_mediaSource);
1031 1033
1032 bool attemptLoad = true; 1034 bool attemptLoad = true;
1033 1035
1034 bool isStreamOrBlobUrl = source.isMediaStream() || url.protocolIs(mediaSourc eBlobProtocol); 1036 bool isStreamOrBlobUrl = source.isMediaStream() || url.protocolIs(mediaSourc eBlobProtocol);
1035 if (isStreamOrBlobUrl) { 1037 if (isStreamOrBlobUrl) {
1036 bool isMediaStream = source.isMediaStream() || (source.isURL() && isMedi aStreamURL(url.getString())); 1038 bool isMediaStream = source.isMediaStream() || (source.isURL() && isMedi aStreamURL(url.getString()));
1037 if (isMediaStream) { 1039 if (isMediaStream) {
1038 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByStre am); 1040 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByStre am);
1041 m_unlockedUserGestureForMediaStream = true;
1039 } else { 1042 } else {
1040 m_mediaSource = HTMLMediaSource::lookup(url.getString()); 1043 m_mediaSource = HTMLMediaSource::lookup(url.getString());
1041 1044
1042 if (m_mediaSource) { 1045 if (m_mediaSource) {
1043 if (!m_mediaSource->attachToElement(this)) { 1046 if (!m_mediaSource->attachToElement(this)) {
1044 // Forget our reference to the MediaSource, so we leave it a lone 1047 // Forget our reference to the MediaSource, so we leave it a lone
1045 // while processing remainder of load failure. 1048 // while processing remainder of load failure.
1046 m_mediaSource = nullptr; 1049 m_mediaSource = nullptr;
1047 attemptLoad = false; 1050 attemptLoad = false;
1048 } 1051 }
(...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after
3692 } 3695 }
3693 3696
3694 bool HTMLMediaElement::isLockedPendingUserGesture() const 3697 bool HTMLMediaElement::isLockedPendingUserGesture() const
3695 { 3698 {
3696 return m_lockedPendingUserGesture; 3699 return m_lockedPendingUserGesture;
3697 } 3700 }
3698 3701
3699 void HTMLMediaElement::unlockUserGesture() 3702 void HTMLMediaElement::unlockUserGesture()
3700 { 3703 {
3701 m_lockedPendingUserGesture = false; 3704 m_lockedPendingUserGesture = false;
3705 m_unlockedUserGestureForMediaStream = false;
3706 }
3707
3708 void HTMLMediaElement::lockUserGesture()
3709 {
3710 m_lockedPendingUserGesture = needToLockPendingUserGesture(document());
3711 m_unlockedUserGestureForMediaStream = false;
3712 }
3713
3714 bool HTMLMediaElement::needToLockPendingUserGesture(const Document& document) co nst
3715 {
3716 return (document.settings() && document.settings()->mediaPlaybackRequiresUse rGesture())
3717 || m_autoplayHelper->isExperimentEnabled();
3702 } 3718 }
3703 3719
3704 bool HTMLMediaElement::isGestureNeededForPlayback() const 3720 bool HTMLMediaElement::isGestureNeededForPlayback() const
3705 { 3721 {
3706 if (!m_lockedPendingUserGesture) 3722 if (!m_lockedPendingUserGesture)
3707 return false; 3723 return false;
3708 3724
3709 // We want to allow muted video to autoplay if: 3725 // We want to allow muted video to autoplay if:
3710 // - the flag is enabled; 3726 // - the flag is enabled;
3711 // - Data Saver is not enabled; 3727 // - Data Saver is not enabled;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
3984 4000
3985 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 4001 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
3986 { 4002 {
3987 IntRect result; 4003 IntRect result;
3988 if (LayoutObject* object = m_element->layoutObject()) 4004 if (LayoutObject* object = m_element->layoutObject())
3989 result = object->absoluteBoundingBoxRect(); 4005 result = object->absoluteBoundingBoxRect();
3990 return result; 4006 return result;
3991 } 4007 }
3992 4008
3993 } // namespace blink 4009 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698