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

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

Issue 1276143002: Defer media loading while on cellular networks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rework. Add tests. Fix singleton state. Created 5 years, 2 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "core/html/track/TextTrackList.h" 59 #include "core/html/track/TextTrackList.h"
60 #include "core/html/track/VideoTrack.h" 60 #include "core/html/track/VideoTrack.h"
61 #include "core/html/track/VideoTrackList.h" 61 #include "core/html/track/VideoTrackList.h"
62 #include "core/inspector/ConsoleMessage.h" 62 #include "core/inspector/ConsoleMessage.h"
63 #include "core/layout/LayoutVideo.h" 63 #include "core/layout/LayoutVideo.h"
64 #include "core/layout/LayoutView.h" 64 #include "core/layout/LayoutView.h"
65 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h" 65 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
66 #include "core/loader/FrameLoader.h" 66 #include "core/loader/FrameLoader.h"
67 #include "core/loader/FrameLoaderClient.h" 67 #include "core/loader/FrameLoaderClient.h"
68 #include "core/page/ChromeClient.h" 68 #include "core/page/ChromeClient.h"
69 #include "core/page/NetworkStateNotifier.h"
69 #include "platform/ContentType.h" 70 #include "platform/ContentType.h"
70 #include "platform/Logging.h" 71 #include "platform/Logging.h"
71 #include "platform/MIMETypeFromURL.h" 72 #include "platform/MIMETypeFromURL.h"
72 #include "platform/MIMETypeRegistry.h" 73 #include "platform/MIMETypeRegistry.h"
73 #include "platform/RuntimeEnabledFeatures.h" 74 #include "platform/RuntimeEnabledFeatures.h"
74 #include "platform/UserGestureIndicator.h" 75 #include "platform/UserGestureIndicator.h"
75 #include "platform/graphics/GraphicsLayer.h" 76 #include "platform/graphics/GraphicsLayer.h"
76 #include "platform/weborigin/SecurityOrigin.h" 77 #include "platform/weborigin/SecurityOrigin.h"
77 #include "public/platform/Platform.h" 78 #include "public/platform/Platform.h"
78 #include "public/platform/WebContentDecryptionModule.h" 79 #include "public/platform/WebContentDecryptionModule.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows 241 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
241 // it cannot render. 242 // it cannot render.
242 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) { 243 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) {
243 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ()); 244 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ());
244 return supported > WebMimeRegistry::IsNotSupported; 245 return supported > WebMimeRegistry::IsNotSupported;
245 } 246 }
246 247
247 return false; 248 return false;
248 } 249 }
249 250
251 static bool shouldForcePreloadNoneForCellularNetwork()
252 {
253 return networkStateNotifier().connectionType() == WebConnectionTypeCellular;
254 }
255
250 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) 256 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric)
251 { 257 {
252 Platform::current()->histogramEnumeration("Blink.MediaElement.Autoplay", met ric, NumberOfAutoplayMetrics); 258 Platform::current()->histogramEnumeration("Blink.MediaElement.Autoplay", met ric, NumberOfAutoplayMetrics);
253 } 259 }
254 260
255 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem) 261 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem)
256 { 262 {
257 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); 263 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs"));
258 264
259 if (!RuntimeEnabledFeatures::mediaEnabled()) 265 if (!RuntimeEnabledFeatures::mediaEnabled())
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 1935
1930 void HTMLMediaElement::setPreload(const AtomicString& preload) 1936 void HTMLMediaElement::setPreload(const AtomicString& preload)
1931 { 1937 {
1932 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data()); 1938 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data());
1933 setAttribute(preloadAttr, preload); 1939 setAttribute(preloadAttr, preload);
1934 } 1940 }
1935 1941
1936 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const 1942 WebMediaPlayer::Preload HTMLMediaElement::preloadType() const
1937 { 1943 {
1938 const AtomicString& preload = fastGetAttribute(preloadAttr); 1944 const AtomicString& preload = fastGetAttribute(preloadAttr);
1945
1946 WebMediaPlayer::Preload preloadType;
1947 const bool forcePreloadNone = shouldForcePreloadNoneForCellularNetwork();
1939 if (equalIgnoringCase(preload, "none")) { 1948 if (equalIgnoringCase(preload, "none")) {
1940 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone); 1949 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
1941 return WebMediaPlayer::PreloadNone; 1950 preloadType = WebMediaPlayer::PreloadNone;
1942 } 1951 } else if (equalIgnoringCase(preload, "metadata")) {
1943 if (equalIgnoringCase(preload, "metadata")) {
1944 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadat a); 1952 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadat a);
1945 return WebMediaPlayer::PreloadMetaData; 1953 preloadType = WebMediaPlayer::PreloadMetaData;
1946 } 1954 } else if (equalIgnoringCase(preload, "auto")) {
1947 if (equalIgnoringCase(preload, "auto")) {
1948 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto); 1955 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto);
1949 return WebMediaPlayer::PreloadAuto; 1956 preloadType = WebMediaPlayer::PreloadAuto;
1957 } else {
1958 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadDefault );
1959
1960 // "The attribute's missing value default is user-agent defined, though the
1961 // Metadata state is suggested as a compromise between reducing server l oad
1962 // and providing an optimal user experience."
1963
1964 // The spec does not define an invalid value default:
1965 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28950
1966
1967 // TODO(philipj): Try to make "metadata" the default preload state:
1968 // https://crbug.com/310450
1969 preloadType = forcePreloadNone ? WebMediaPlayer::PreloadNone : WebMediaP layer::PreloadAuto;
watk 2015/09/30 01:21:52 It might be clearer to just set to Auto here, and
DaleCurtis 2015/09/30 01:33:44 Done.
1950 } 1970 }
1951 1971
1952 // "The attribute's missing value default is user-agent defined, though the 1972 if (forcePreloadNone)
1953 // Metadata state is suggested as a compromise between reducing server load 1973 preloadType = WebMediaPlayer::PreloadNone;
1954 // and providing an optimal user experience."
1955 1974
1956 // The spec does not define an invalid value default: 1975 return preloadType;
1957 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28950
1958
1959 // TODO(philipj): Try to make "metadata" the default preload state:
1960 // https://crbug.com/310450
1961 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadDefault);
1962 return WebMediaPlayer::PreloadAuto;
1963 } 1976 }
1964 1977
1965 WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const 1978 WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const
1966 { 1979 {
1967 return autoplay() ? WebMediaPlayer::PreloadAuto : preloadType(); 1980 return autoplay() ? WebMediaPlayer::PreloadAuto : preloadType();
1968 } 1981 }
1969 1982
1970 void HTMLMediaElement::play() 1983 void HTMLMediaElement::play()
1971 { 1984 {
1972 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); 1985 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this);
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 visitor->trace(m_client); 3827 visitor->trace(m_client);
3815 } 3828 }
3816 3829
3817 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) 3830 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl)
3818 { 3831 {
3819 visitor->trace(m_client); 3832 visitor->trace(m_client);
3820 } 3833 }
3821 #endif 3834 #endif
3822 3835
3823 } 3836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698