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

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

Issue 2466273006: Allow metadata preload on cellular connections and disallow autoplay muted for low end devices. (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 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 String HTMLMediaElement::preload() const { 2058 String HTMLMediaElement::preload() const {
2059 return preloadTypeToString(preloadType()); 2059 return preloadTypeToString(preloadType());
2060 } 2060 }
2061 2061
2062 void HTMLMediaElement::setPreload(const AtomicString& preload) { 2062 void HTMLMediaElement::setPreload(const AtomicString& preload) {
2063 BLINK_MEDIA_LOG << "setPreload(" << (void*)this << ", " << preload << ")"; 2063 BLINK_MEDIA_LOG << "setPreload(" << (void*)this << ", " << preload << ")";
2064 setAttribute(preloadAttr, preload); 2064 setAttribute(preloadAttr, preload);
2065 } 2065 }
2066 2066
2067 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const { 2067 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const {
2068 // Force preload to none for cellular connections or when data saver is 2068 const AtomicString& preload = fastGetAttribute(preloadAttr);
2069 // explicitly set. 2069 if (equalIgnoringCase(preload, "none")) {
2070 if (networkStateNotifier().isCellularConnectionType() || 2070 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
2071 (document().settings() && 2071 return WebMediaPlayer::PreloadNone;
2072 (document().settings()->dataSaverEnabled() || 2072 }
2073 document().settings()->forcePreloadNoneForMediaElements()))) { 2073
2074 // Force preload to 'none' on Data Saver and for low end devices.
2075 if (document().settings() &&
2076 (document().settings()->dataSaverEnabled() ||
2077 document().settings()->forcePreloadNoneForMediaElements())) {
2074 UseCounter::count(document(), 2078 UseCounter::count(document(),
2075 UseCounter::HTMLMediaElementPreloadForcedNone); 2079 UseCounter::HTMLMediaElementPreloadForcedNone);
2076 return WebMediaPlayer::PreloadNone; 2080 return WebMediaPlayer::PreloadNone;
2077 } 2081 }
2078 2082
2079 const AtomicString& preload = fastGetAttribute(preloadAttr);
2080 if (equalIgnoringCase(preload, "none")) {
2081 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
2082 return WebMediaPlayer::PreloadNone;
2083 }
2084 if (equalIgnoringCase(preload, "metadata")) { 2083 if (equalIgnoringCase(preload, "metadata")) {
2085 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadata); 2084 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadata);
2086 return WebMediaPlayer::PreloadMetaData; 2085 return WebMediaPlayer::PreloadMetaData;
2087 } 2086 }
2087
2088 // Force preload to 'metadata' on cellular connections.
2089 if (networkStateNotifier().isCellularConnectionType()) {
2090 UseCounter::count(document(),
2091 UseCounter::HTMLMediaElementPreloadForcedMetadata);
2092 return WebMediaPlayer::PreloadMetaData;
2093 }
2094
2088 if (equalIgnoringCase(preload, "auto")) { 2095 if (equalIgnoringCase(preload, "auto")) {
2089 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto); 2096 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto);
2090 return WebMediaPlayer::PreloadAuto; 2097 return WebMediaPlayer::PreloadAuto;
2091 } 2098 }
2092 2099
2093 // "The attribute's missing value default is user-agent defined, though the 2100 // "The attribute's missing value default is user-agent defined, though the
2094 // Metadata state is suggested as a compromise between reducing server load 2101 // Metadata state is suggested as a compromise between reducing server load
2095 // and providing an optimal user experience." 2102 // and providing an optimal user experience."
2096 2103
2097 // The spec does not define an invalid value default: 2104 // The spec does not define an invalid value default:
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 bool HTMLMediaElement::isGestureNeededForPlayback() const { 3806 bool HTMLMediaElement::isGestureNeededForPlayback() const {
3800 if (!m_lockedPendingUserGesture) 3807 if (!m_lockedPendingUserGesture)
3801 return false; 3808 return false;
3802 3809
3803 if (loadType() == WebMediaPlayer::LoadTypeMediaStream) 3810 if (loadType() == WebMediaPlayer::LoadTypeMediaStream)
3804 return false; 3811 return false;
3805 3812
3806 // We want to allow muted video to autoplay if: 3813 // We want to allow muted video to autoplay if:
3807 // - the flag is enabled; 3814 // - the flag is enabled;
3808 // - Data Saver is not enabled; 3815 // - Data Saver is not enabled;
3816 // - Preload was not disabled (low end devices);
3809 // - Autoplay is enabled in settings; 3817 // - Autoplay is enabled in settings;
3810 if (isHTMLVideoElement() && muted() && 3818 if (isHTMLVideoElement() && muted() &&
3811 RuntimeEnabledFeatures::autoplayMutedVideosEnabled() && 3819 RuntimeEnabledFeatures::autoplayMutedVideosEnabled() &&
3812 !(document().settings() && document().settings()->dataSaverEnabled()) && 3820 !(document().settings() && document().settings()->dataSaverEnabled()) &&
3821 !(document().settings() &&
3822 document().settings()->forcePreloadNoneForMediaElements()) &&
3813 isAutoplayAllowedPerSettings()) { 3823 isAutoplayAllowedPerSettings()) {
3814 return false; 3824 return false;
3815 } 3825 }
3816 3826
3817 if (m_autoplayHelper->isGestureRequirementOverridden()) 3827 if (m_autoplayHelper->isGestureRequirementOverridden())
3818 return false; 3828 return false;
3819 3829
3820 return true; 3830 return true;
3821 } 3831 }
3822 3832
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 4102
4093 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4103 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4094 const { 4104 const {
4095 IntRect result; 4105 IntRect result;
4096 if (LayoutObject* object = m_element->layoutObject()) 4106 if (LayoutObject* object = m_element->layoutObject())
4097 result = object->absoluteBoundingBoxRect(); 4107 result = object->absoluteBoundingBoxRect();
4098 return result; 4108 return result;
4099 } 4109 }
4100 4110
4101 } // namespace blink 4111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698