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

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

Issue 2471373005: Pretend the video has no audio track if it is playing as part of autoplay muted. (Closed)
Patch Set: Created 4 years, 1 month 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 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 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 return m_muted; 2340 return m_muted;
2341 } 2341 }
2342 2342
2343 void HTMLMediaElement::setMuted(bool muted) { 2343 void HTMLMediaElement::setMuted(bool muted) {
2344 BLINK_MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted) 2344 BLINK_MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted)
2345 << ")"; 2345 << ")";
2346 2346
2347 if (m_muted == muted) 2347 if (m_muted == muted)
2348 return; 2348 return;
2349 2349
2350 bool wasAutoplayingMuted = 2350 bool wasAutoplayingMuted = isAutoplayingMuted();
2351 !paused() && m_muted && isLockedPendingUserGesture();
2352 bool wasPendingAutoplayMuted = m_autoplayVisibilityObserver && paused() && 2351 bool wasPendingAutoplayMuted = m_autoplayVisibilityObserver && paused() &&
2353 m_muted && isLockedPendingUserGesture(); 2352 m_muted && isLockedPendingUserGesture();
2354 2353
2355 if (UserGestureIndicator::processingUserGesture()) 2354 if (UserGestureIndicator::processingUserGesture())
2356 unlockUserGesture(); 2355 unlockUserGesture();
2357 2356
2358 m_muted = muted; 2357 m_muted = muted;
2359 m_autoplayHelper->mutedChanged(); 2358 m_autoplayHelper->mutedChanged();
2360 2359
2361 updateVolume();
2362
2363 scheduleEvent(EventTypeNames::volumechange); 2360 scheduleEvent(EventTypeNames::volumechange);
2364 2361
2365 // If an element autoplayed while muted, it needs to be unlocked to unmute, 2362 // If an element autoplayed while muted, it needs to be unlocked to unmute,
2366 // otherwise, it will be paused. 2363 // otherwise, it will be paused.
2367 if (wasAutoplayingMuted) { 2364 if (wasAutoplayingMuted) {
2368 if (isGestureNeededForPlayback()) { 2365 if (isGestureNeededForPlayback()) {
2369 pause(); 2366 pause();
2370 m_autoplayUmaHelper->recordAutoplayUnmuteStatus( 2367 m_autoplayUmaHelper->recordAutoplayUnmuteStatus(
2371 AutoplayUnmuteActionStatus::Failure); 2368 AutoplayUnmuteActionStatus::Failure);
2372 } else { 2369 } else {
2373 m_autoplayUmaHelper->recordAutoplayUnmuteStatus( 2370 m_autoplayUmaHelper->recordAutoplayUnmuteStatus(
2374 AutoplayUnmuteActionStatus::Success); 2371 AutoplayUnmuteActionStatus::Success);
2375 } 2372 }
2376 } 2373 }
2377 2374
2375 // This is called after the volumechange event to make sure isAutoplayingMuted
2376 // returns the right value when webMediaPlayer receives the volume update.
2377 updateVolume();
2378
2378 // If an element was a candidate for autoplay muted but not visible, it will 2379 // If an element was a candidate for autoplay muted but not visible, it will
2379 // have a visibility observer ready to start its playback. 2380 // have a visibility observer ready to start its playback.
2380 if (wasPendingAutoplayMuted) { 2381 if (wasPendingAutoplayMuted) {
2381 m_autoplayVisibilityObserver->stop(); 2382 m_autoplayVisibilityObserver->stop();
2382 m_autoplayVisibilityObserver = nullptr; 2383 m_autoplayVisibilityObserver = nullptr;
2383 } 2384 }
2384 } 2385 }
2385 2386
2386 void HTMLMediaElement::updateVolume() { 2387 void HTMLMediaElement::updateVolume() {
2387 if (webMediaPlayer()) 2388 if (webMediaPlayer())
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 mediaControls()->stoppedCasting(); 3097 mediaControls()->stoppedCasting();
3097 if (remotePlaybackClient()) 3098 if (remotePlaybackClient())
3098 remotePlaybackClient()->stateChanged(WebRemotePlaybackState::Disconnected); 3099 remotePlaybackClient()->stateChanged(WebRemotePlaybackState::Disconnected);
3099 } 3100 }
3100 3101
3101 void HTMLMediaElement::cancelledRemotePlaybackRequest() { 3102 void HTMLMediaElement::cancelledRemotePlaybackRequest() {
3102 if (remotePlaybackClient()) 3103 if (remotePlaybackClient())
3103 remotePlaybackClient()->promptCancelled(); 3104 remotePlaybackClient()->promptCancelled();
3104 } 3105 }
3105 3106
3107 bool HTMLMediaElement::isAutoplayingMuted() {
3108 if (!isHTMLVideoElement() ||
3109 !RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) {
3110 return false;
3111 }
3112
3113 return !paused() && muted() && isLockedPendingUserGesture();
3114 }
3115
3106 void HTMLMediaElement::requestReload(const WebURL& newUrl) { 3116 void HTMLMediaElement::requestReload(const WebURL& newUrl) {
3107 DCHECK(webMediaPlayer()); 3117 DCHECK(webMediaPlayer());
3108 DCHECK(!m_srcObject); 3118 DCHECK(!m_srcObject);
3109 DCHECK(newUrl.isValid()); 3119 DCHECK(newUrl.isValid());
3110 DCHECK(isSafeToLoadURL(newUrl, Complain)); 3120 DCHECK(isSafeToLoadURL(newUrl, Complain));
3111 resetMediaPlayerAndMediaSource(); 3121 resetMediaPlayerAndMediaSource();
3112 startPlayerLoad(newUrl); 3122 startPlayerLoad(newUrl);
3113 } 3123 }
3114 3124
3115 // MediaPlayerPresentation methods 3125 // MediaPlayerPresentation methods
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
4084 4094
4085 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4095 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4086 const { 4096 const {
4087 IntRect result; 4097 IntRect result;
4088 if (LayoutObject* object = m_element->layoutObject()) 4098 if (LayoutObject* object = m_element->layoutObject())
4089 result = object->absoluteBoundingBoxRect(); 4099 result = object->absoluteBoundingBoxRect();
4090 return result; 4100 return result;
4091 } 4101 }
4092 4102
4093 } // namespace blink 4103 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | third_party/WebKit/public/platform/WebMediaPlayerClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698