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

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: add not allowed value 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 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 String HTMLMediaElement::preload() const { 2129 String HTMLMediaElement::preload() const {
2130 return preloadTypeToString(preloadType()); 2130 return preloadTypeToString(preloadType());
2131 } 2131 }
2132 2132
2133 void HTMLMediaElement::setPreload(const AtomicString& preload) { 2133 void HTMLMediaElement::setPreload(const AtomicString& preload) {
2134 BLINK_MEDIA_LOG << "setPreload(" << (void*)this << ", " << preload << ")"; 2134 BLINK_MEDIA_LOG << "setPreload(" << (void*)this << ", " << preload << ")";
2135 setAttribute(preloadAttr, preload); 2135 setAttribute(preloadAttr, preload);
2136 } 2136 }
2137 2137
2138 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const { 2138 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const {
2139 // Force preload to none for cellular connections or when data saver is 2139 const AtomicString& preload = fastGetAttribute(preloadAttr);
2140 // explicitly set. 2140 if (equalIgnoringCase(preload, "none")) {
2141 if (networkStateNotifier().isCellularConnectionType() || 2141 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
2142 (document().settings() && 2142 return WebMediaPlayer::PreloadNone;
2143 (document().settings()->dataSaverEnabled() || 2143 }
2144 document().settings()->forcePreloadNoneForMediaElements()))) { 2144
2145 // Force preload to 'none' on Data Saver and for low end devices.
2146 if (document().settings() &&
2147 (document().settings()->dataSaverEnabled() ||
2148 document().settings()->forcePreloadNoneForMediaElements())) {
2145 UseCounter::count(document(), 2149 UseCounter::count(document(),
2146 UseCounter::HTMLMediaElementPreloadForcedNone); 2150 UseCounter::HTMLMediaElementPreloadForcedNone);
2147 return WebMediaPlayer::PreloadNone; 2151 return WebMediaPlayer::PreloadNone;
2148 } 2152 }
2149 2153
2150 const AtomicString& preload = fastGetAttribute(preloadAttr);
2151 if (equalIgnoringCase(preload, "none")) {
2152 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
2153 return WebMediaPlayer::PreloadNone;
2154 }
2155 if (equalIgnoringCase(preload, "metadata")) { 2154 if (equalIgnoringCase(preload, "metadata")) {
2156 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadata); 2155 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadata);
2157 return WebMediaPlayer::PreloadMetaData; 2156 return WebMediaPlayer::PreloadMetaData;
2158 } 2157 }
2158
2159 // Force preload to 'metadata' on cellular connections.
2160 if (networkStateNotifier().isCellularConnectionType()) {
2161 UseCounter::count(document(),
2162 UseCounter::HTMLMediaElementPreloadForcedMetadata);
2163 return WebMediaPlayer::PreloadMetaData;
2164 }
2165
2159 if (equalIgnoringCase(preload, "auto")) { 2166 if (equalIgnoringCase(preload, "auto")) {
2160 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto); 2167 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto);
2161 return WebMediaPlayer::PreloadAuto; 2168 return WebMediaPlayer::PreloadAuto;
2162 } 2169 }
2163 2170
2164 // "The attribute's missing value default is user-agent defined, though the 2171 // "The attribute's missing value default is user-agent defined, though the
2165 // Metadata state is suggested as a compromise between reducing server load 2172 // Metadata state is suggested as a compromise between reducing server load
2166 // and providing an optimal user experience." 2173 // and providing an optimal user experience."
2167 2174
2168 // The spec does not define an invalid value default: 2175 // The spec does not define an invalid value default:
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3892 bool HTMLMediaElement::isGestureNeededForPlayback() const { 3899 bool HTMLMediaElement::isGestureNeededForPlayback() const {
3893 if (!m_lockedPendingUserGesture) 3900 if (!m_lockedPendingUserGesture)
3894 return false; 3901 return false;
3895 3902
3896 if (loadType() == WebMediaPlayer::LoadTypeMediaStream) 3903 if (loadType() == WebMediaPlayer::LoadTypeMediaStream)
3897 return false; 3904 return false;
3898 3905
3899 // We want to allow muted video to autoplay if: 3906 // We want to allow muted video to autoplay if:
3900 // - the flag is enabled; 3907 // - the flag is enabled;
3901 // - Data Saver is not enabled; 3908 // - Data Saver is not enabled;
3909 // - Preload was not disabled (low end devices);
3902 // - Autoplay is enabled in settings; 3910 // - Autoplay is enabled in settings;
3903 if (isHTMLVideoElement() && muted() && 3911 if (isHTMLVideoElement() && muted() &&
3904 RuntimeEnabledFeatures::autoplayMutedVideosEnabled() && 3912 RuntimeEnabledFeatures::autoplayMutedVideosEnabled() &&
3905 !(document().settings() && document().settings()->dataSaverEnabled()) && 3913 !(document().settings() && document().settings()->dataSaverEnabled()) &&
3914 !(document().settings() &&
3915 document().settings()->forcePreloadNoneForMediaElements()) &&
3906 isAutoplayAllowedPerSettings()) { 3916 isAutoplayAllowedPerSettings()) {
3907 return false; 3917 return false;
3908 } 3918 }
3909 3919
3910 if (m_autoplayHelper->isGestureRequirementOverridden()) 3920 if (m_autoplayHelper->isGestureRequirementOverridden())
3911 return false; 3921 return false;
3912 3922
3913 return true; 3923 return true;
3914 } 3924 }
3915 3925
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 4189
4180 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4190 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4181 const { 4191 const {
4182 IntRect result; 4192 IntRect result;
4183 if (LayoutObject* object = m_element->layoutObject()) 4193 if (LayoutObject* object = m_element->layoutObject())
4184 result = object->absoluteBoundingBoxRect(); 4194 result = object->absoluteBoundingBoxRect();
4185 return result; 4195 return result;
4186 } 4196 }
4187 4197
4188 } // namespace blink 4198 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698