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

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

Issue 2091253002: When autoplaying muted video, record when unmute happen and the result. (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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // These values are used for histograms. Do not reorder. 286 // These values are used for histograms. Do not reorder.
287 enum AutoplaySource { 287 enum AutoplaySource {
288 // Autoplay comes from HTMLMediaElement `autoplay` attribute. 288 // Autoplay comes from HTMLMediaElement `autoplay` attribute.
289 AutoplaySourceAttribute = 0, 289 AutoplaySourceAttribute = 0,
290 // Autoplay comes from `play()` method. 290 // Autoplay comes from `play()` method.
291 AutoplaySourceMethod = 1, 291 AutoplaySourceMethod = 1,
292 // This enum value must be last. 292 // This enum value must be last.
293 NumberOfAutoplaySources = 2, 293 NumberOfAutoplaySources = 2,
294 }; 294 };
295 295
296 // These values are used for histograms. Do not reorder.
297 enum AutoplayUnmuteActionStatus {
298 AutoplayUnmuteActionFailure = 0,
299 AutoplayUnmuteActionSuccess = 1,
300 AutoplayUnmuteActionMax = 2,
301 };
302
296 } // anonymous namespace 303 } // anonymous namespace
297 304
298 class HTMLMediaElement::AutoplayHelperClientImpl : 305 class HTMLMediaElement::AutoplayHelperClientImpl :
299 public AutoplayExperimentHelper::Client { 306 public AutoplayExperimentHelper::Client {
300 307
301 public: 308 public:
302 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) 309 static AutoplayHelperClientImpl* create(HTMLMediaElement* element)
303 { 310 {
304 return new AutoplayHelperClientImpl(element); 311 return new AutoplayHelperClientImpl(element);
305 } 312 }
(...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 2292
2286 bool HTMLMediaElement::muted() const 2293 bool HTMLMediaElement::muted() const
2287 { 2294 {
2288 return m_muted; 2295 return m_muted;
2289 } 2296 }
2290 2297
2291 void HTMLMediaElement::setMuted(bool muted) 2298 void HTMLMediaElement::setMuted(bool muted)
2292 { 2299 {
2293 MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted) << ")"; 2300 MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted) << ")";
2294 2301
2295 if (UserGestureIndicator::processingUserGesture())
2296 unlockUserGesture();
2297
2298 if (m_muted == muted) 2302 if (m_muted == muted)
2299 return; 2303 return;
2300 2304
2301 m_muted = muted; 2305 m_muted = muted;
2302 m_autoplayHelper->mutedChanged(); 2306 m_autoplayHelper->mutedChanged();
2303 2307
2304 updateVolume(); 2308 updateVolume();
2305 2309
2306 if (muted) 2310 if (muted)
2307 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _On")); 2311 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _On"));
2308 else 2312 else
2309 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _Off")); 2313 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _Off"));
2310 2314
2311 scheduleEvent(EventTypeNames::volumechange); 2315 scheduleEvent(EventTypeNames::volumechange);
2312 2316
2317 bool wasLocked = isGestureNeededForPlayback();
whywhat 2016/06/28 10:20:59 nit: I think you either want: bool wasLocked = m_
2318 if (UserGestureIndicator::processingUserGesture())
2319 unlockUserGesture();
2320
2321 // Record when unmuting a video that was autoplayed because it was muted.
2322 if (wasLocked && !muted && isHTMLVideoElement() && RuntimeEnabledFeatures::a utoplayMutedVideosEnabled())
whywhat 2016/06/28 10:20:59 this condition seems to be very hard to read and m
2323 recordAutoplayUnmuteStatus(isGestureNeededForPlayback() ? AutoplayUnmute Status::Failure : AutoplayUnmuteStatus::Success);
2324
2313 // Pause the element when unmuting if it's still locked. 2325 // Pause the element when unmuting if it's still locked.
2314 if (!muted && isGestureNeededForPlayback()) 2326 if (!muted && isGestureNeededForPlayback())
whywhat 2016/06/28 10:20:59 // this implicitly relies on m_muted set to false
2315 pause(); 2327 pause();
2316 } 2328 }
2317 2329
2318 void HTMLMediaElement::updateVolume() 2330 void HTMLMediaElement::updateVolume()
2319 { 2331 {
2320 if (webMediaPlayer()) 2332 if (webMediaPlayer())
2321 webMediaPlayer()->setVolume(effectiveMediaVolume()); 2333 webMediaPlayer()->setVolume(effectiveMediaVolume());
2322 2334
2323 if (mediaControls()) 2335 if (mediaControls())
2324 mediaControls()->updateVolume(); 2336 mediaControls()->updateVolume();
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
3883 3895
3884 if (isHTMLVideoElement()) { 3896 if (isHTMLVideoElement()) {
3885 videoHistogram.count(source); 3897 videoHistogram.count(source);
3886 if (muted()) 3898 if (muted())
3887 mutedVideoHistogram.count(source); 3899 mutedVideoHistogram.count(source);
3888 } else { 3900 } else {
3889 audioHistogram.count(source); 3901 audioHistogram.count(source);
3890 } 3902 }
3891 } 3903 }
3892 3904
3905 void HTMLMediaElement::recordAutoplayUnmuteStatus(AutoplayUnmuteStatus status)
3906 {
3907 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V ideo.Autoplay.Muted.UnmuteAction", AutoplayUnmuteActionMax));
3908
3909 autoplayUnmuteHistogram.count(status == AutoplayUnmuteStatus::Success ? Auto playUnmuteActionSuccess : AutoplayUnmuteActionFailure);
3910 }
3911
3893 void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible) 3912 void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible)
3894 { 3913 {
3895 if (!isVisible) 3914 if (!isVisible)
3896 return; 3915 return;
3897 3916
3898 if (shouldAutoplay()) { 3917 if (shouldAutoplay()) {
3899 m_paused = false; 3918 m_paused = false;
3900 invalidateCachedTime(); 3919 invalidateCachedTime();
3901 scheduleEvent(EventTypeNames::play); 3920 scheduleEvent(EventTypeNames::play);
3902 scheduleNotifyPlaying(); 3921 scheduleNotifyPlaying();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4015 4034
4016 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 4035 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
4017 { 4036 {
4018 IntRect result; 4037 IntRect result;
4019 if (LayoutObject* object = m_element->layoutObject()) 4038 if (LayoutObject* object = m_element->layoutObject())
4020 result = object->absoluteBoundingBoxRect(); 4039 result = object->absoluteBoundingBoxRect();
4021 return result; 4040 return result;
4022 } 4041 }
4023 4042
4024 } // namespace blink 4043 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698