diff options
author | toyoshim <toyoshim@chromium.org> | 2015-12-17 20:11:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-18 04:12:19 +0000 |
commit | cfb26409da10af0fe7d7d576e185161724819783 (patch) | |
tree | d2f5c47dd1636f837b2335dec13186317a6aa1ed | |
parent | 29067ecc7b35d07bce918606240e1f1628ae1a06 (diff) | |
download | chromium_src-cfb26409da10af0fe7d7d576e185161724819783.zip chromium_src-cfb26409da10af0fe7d7d576e185161724819783.tar.gz chromium_src-cfb26409da10af0fe7d7d576e185161724819783.tar.bz2 |
Intervention: Web Font adaptive timeout on 2G network
This patch changes WebConnectionType to be a super set of the connection
type that Network Information API defines so that FontResource can
identify 2G cellular networks.
FontResource adjusts fallback timeout to 0sec on slow 2G networks.
This is the first step of the adaptive font timeouts proposal.
https://docs.google.com/document/d/12yQa0eMhGPO-DDhLb8FCg8ss-MTt8JkTFgEJyoM_4uQ/edit?usp=sharing
The feature is behind the experimental web platform feature flag as font-display is.
BUG=515343
Review URL: https://codereview.chromium.org/1463083003
Cr-Commit-Position: refs/heads/master@{#366012}
14 files changed, 229 insertions, 11 deletions
diff --git a/components/html_viewer/blink_settings_impl.cc b/components/html_viewer/blink_settings_impl.cc index a2b3180..e787861 100644 --- a/components/html_viewer/blink_settings_impl.cc +++ b/components/html_viewer/blink_settings_impl.cc @@ -50,9 +50,11 @@ blink::WebConnectionType NetConnectionTypeToWebConnectionType( case net::NetworkChangeNotifier::CONNECTION_NONE: return blink::WebConnectionTypeNone; case net::NetworkChangeNotifier::CONNECTION_2G: + return blink::WebConnectionTypeCellular2G; case net::NetworkChangeNotifier::CONNECTION_3G: + return blink::WebConnectionTypeCellular3G; case net::NetworkChangeNotifier::CONNECTION_4G: - return blink::WebConnectionTypeCellular; + return blink::WebConnectionTypeCellular4G; case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: return blink::WebConnectionTypeBluetooth; } diff --git a/content/renderer/net_info_helper.cc b/content/renderer/net_info_helper.cc index 4db6641..4d26d02 100644 --- a/content/renderer/net_info_helper.cc +++ b/content/renderer/net_info_helper.cc @@ -19,9 +19,11 @@ NetConnectionTypeToWebConnectionType( case net::NetworkChangeNotifier::CONNECTION_NONE: return blink::WebConnectionTypeNone; case net::NetworkChangeNotifier::CONNECTION_2G: + return blink::WebConnectionTypeCellular2G; case net::NetworkChangeNotifier::CONNECTION_3G: + return blink::WebConnectionTypeCellular3G; case net::NetworkChangeNotifier::CONNECTION_4G: - return blink::WebConnectionTypeCellular; + return blink::WebConnectionTypeCellular4G; case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: return blink::WebConnectionTypeBluetooth; } diff --git a/content/test/test_blink_web_unit_test_support.cc b/content/test/test_blink_web_unit_test_support.cc index f2c6f16..7c3e229 100644 --- a/content/test/test_blink_web_unit_test_support.cc +++ b/content/test/test_blink_web_unit_test_support.cc @@ -25,6 +25,7 @@ #include "media/base/media.h" #include "net/cookies/cookie_monster.h" #include "storage/browser/database/vfs_backend.h" +#include "third_party/WebKit/public/platform/WebConnectionType.h" #include "third_party/WebKit/public/platform/WebData.h" #include "third_party/WebKit/public/platform/WebFileSystem.h" #include "third_party/WebKit/public/platform/WebPluginListBuilder.h" @@ -34,6 +35,7 @@ #include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/web/WebDatabase.h" #include "third_party/WebKit/public/web/WebKit.h" +#include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "third_party/WebKit/public/web/WebSecurityPolicy.h" #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" @@ -122,6 +124,11 @@ TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { blink::WebRuntimeFeatures::enableNotifications(true); blink::WebRuntimeFeatures::enableTouch(true); + // Initialize NetworkStateNotifier. + blink::WebNetworkStateNotifier::setWebConnection( + blink::WebConnectionType::WebConnectionTypeUnknown, + std::numeric_limits<double>::infinity()); + // External cc::AnimationHost is enabled for unit tests. cc::LayerSettings layer_settings; layer_settings.use_compositor_animation_timelines = true; diff --git a/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention-expected.html b/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention-expected.html new file mode 100644 index 0000000..541dce9 --- /dev/null +++ b/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention-expected.html @@ -0,0 +1,86 @@ +<!DOCTYPE html> +<title>Test for font-display @font-face descriptor</title> +<script src="/js-test-resources/ahem.js"></script> +<style> +.ahem { + font-family: Ahem; +} +.arial { + font-family: Arial; +} +</style> +<p>Tests how text with a font that takes <i>delay</i> seconds to load look like after <i>T</i> seconds from load start.</p> +<table> +<tr> + <th>T[sec]</th> + <th>delay[sec]</th> + <th>auto</th> + <th>block</th> + <th>swap</th> + <th>fallback</th> + <th>optional</th> +</tr> +<tr> + <td>0</td> + <td>1</td> + <td class="arial">a</td> + <td></td> + <td class="arial">a</td> + <td></td> + <td></td> +</tr> +<tr> + <td>1</td> + <td>0</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> +</tr> +<tr> + <td>1</td> + <td>0.5</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="arial">a</td> +</tr> +<tr> + <td>1</td> + <td>3</td> + <td class="arial">a</td> + <td></td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> +</tr> +<tr> + <td>5</td> + <td>2</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="arial">a</td> +</tr> +<tr> + <td>5</td> + <td>4</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="ahem">a</td> + <td class="arial">a</td> + <td class="arial">a</td> +</tr> +<tr> + <td>5</td> + <td>8</td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> +</tr> +</table> diff --git a/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention.html b/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention.html new file mode 100644 index 0000000..dc56031 --- /dev/null +++ b/third_party/WebKit/LayoutTests/http/tests/webfont/font-display-intervention.html @@ -0,0 +1,74 @@ +<!DOCTYPE html> +<title>Test for font-display @font-face descriptor with User-Agent Intervention</title> +<style> +.hidden { display: none; } +</style> +<p>Tests how text with a font that takes <i>delay</i> seconds to load look like after <i>T</i> seconds from load start.</p> +<table id="container"> + <tr> + <th>T[sec]</th> + <th>delay[sec]</th> + <th>auto</th> + <th>block</th> + <th>swap</th> + <th>fallback</th> + <th>optional</th> + </tr> +</table> +<script> +if (window.testRunner) + testRunner.waitUntilDone(); + +// 2G cellular networks will cause an User-Agent Intervention. +// Under the situation, 'auto' should behave as 'swap'. +if (window.internals) { + internals.setNetworkStateNotifierTestOnly(true); + internals.setNetworkConnectionInfo('cellular2g', 1.0); +} + +var fontDisplayValues = ['auto', 'block', 'swap', 'fallback', 'optional']; +var configs = [{time: 0, delay: 1000}, + {time: 1000, delay: 0}, + {time: 1000, delay: 500}, + {time: 1000, delay: 3000}, + {time: 5000, delay: 2000}, + {time: 5000, delay: 4000}, + {time: 5000, delay: 8000}]; + +function makeFontFaceDeclaration(family, config, display) { + var url = '/resources/Ahem.ttf'; + if (config.delay > 0) + url = 'slow-ahem-loading.cgi?delay=' + config.delay + '&t=' + config.time; + return '@font-face { font-family: ' + family + '; src: url(' + url + '); font-display: ' + display + '; }'; +} + + +var maxTime = Math.max.apply(null, configs.map((config) => config.time)); +var table = document.getElementById('container'); + +for (var config, i = 0; config = configs[i]; i++) { + var tr = document.createElement('tr'); + tr.classList.add('hidden'); + var td1 = document.createElement('td'); + td1.textContent = config.time / 1000; + tr.appendChild(td1); + var td2 = document.createElement('td'); + td2.textContent = config.delay / 1000; + tr.appendChild(td2); + + for (var display, j = 0; display = fontDisplayValues[j]; j++) { + var family = [display, config.time, config.delay].join('-'); + var rule = makeFontFaceDeclaration(family, config, display); + document.styleSheets[0].insertRule(rule, 0); + var td = document.createElement('td'); + td.textContent = 'a'; + td.style.fontFamily = family + ', Arial'; + tr.appendChild(td); + } + table.appendChild(tr); + setTimeout((function(tr){tr.classList.remove('hidden')}).bind(null, tr), maxTime - config.time); +} + +if (window.testRunner) + setTimeout(function() { testRunner.notifyDone(); }, maxTime); +</script> diff --git a/third_party/WebKit/LayoutTests/media/video-preload-cellular-test.js b/third_party/WebKit/LayoutTests/media/video-preload-cellular-test.js index 202f4b0..4c47179 100644 --- a/third_party/WebKit/LayoutTests/media/video-preload-cellular-test.js +++ b/third_party/WebKit/LayoutTests/media/video-preload-cellular-test.js @@ -1,7 +1,7 @@ function cellular_preload_test() { async_test(function(t) { internals.setNetworkStateNotifierTestOnly(true); - internals.setNetworkConnectionInfo('cellular', 2.0); + internals.setNetworkConnectionInfo('cellular3g', 2.0); var video = document.querySelector('video'); assert_equals(video.preload, 'none') diff --git a/third_party/WebKit/LayoutTests/netinfo/connection-types.html b/third_party/WebKit/LayoutTests/netinfo/connection-types.html index 896e103..8c9f7c5 100644 --- a/third_party/WebKit/LayoutTests/netinfo/connection-types.html +++ b/third_party/WebKit/LayoutTests/netinfo/connection-types.html @@ -37,8 +37,15 @@ connection.addEventListener('change', function(e) { finishJSTest(); }); +// Blink internally handles fine grained connection types on cellular network. +function convertType(type) { + if (type == 'cellular') + return 'cellular2g'; + return type; +} + for(var i = 0; i < types.length; i++) - internals.setNetworkConnectionInfo(types[i][0], types[i][1]); + internals.setNetworkConnectionInfo(convertType(types[i][0]), types[i][1]); </script> </body> diff --git a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp index 8a0dcf4..6a91ef5 100644 --- a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp +++ b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp @@ -8,6 +8,8 @@ #include "core/css/CSSCustomFontData.h" #include "core/css/CSSFontFace.h" #include "core/css/FontLoader.h" +#include "core/page/NetworkStateNotifier.h" +#include "platform/RuntimeEnabledFeatures.h" #include "platform/fonts/FontCache.h" #include "platform/fonts/FontDescription.h" #include "platform/fonts/SimpleFontData.h" @@ -21,11 +23,19 @@ RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, PassRefPtrWillBeR , m_fontLoader(fontLoader) , m_display(display) , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) + , m_isInterventionEnabled(false) { #if ENABLE(OILPAN) ThreadState::current()->registerPreFinalizer(this); #endif m_font->addClient(this); + + if (RuntimeEnabledFeatures::cssFontDisplayEnabled()) { + // TODO(crbug.com/515343): Consider to use better signals. + m_isInterventionEnabled = networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; + if (m_isInterventionEnabled && m_display == FontDisplayAuto) + m_period = SwapPeriod; + } } RemoteFontFaceSource::~RemoteFontFaceSource() @@ -102,7 +112,7 @@ void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { - if (m_display == FontDisplayAuto || m_display == FontDisplayBlock) + if (m_display == FontDisplayBlock || (!m_isInterventionEnabled && m_display == FontDisplayAuto)) switchToSwapPeriod(); else if (m_display == FontDisplayFallback) switchToFailurePeriod(); diff --git a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.h b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.h index 3374684..3432729 100644 --- a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.h +++ b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.h @@ -80,6 +80,7 @@ private: const FontDisplay m_display; DisplayPeriod m_period; FontLoadHistograms m_histograms; + bool m_isInterventionEnabled; }; } // namespace blink diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp index 5a36203..cbef832 100644 --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp @@ -1909,7 +1909,7 @@ void HTMLMediaElement::setPreload(const AtomicString& preload) WebMediaPlayer::Preload HTMLMediaElement::preloadType() const { // Force preload to none for cellular connections. - if (networkStateNotifier().connectionType() == WebConnectionTypeCellular) { + if (networkStateNotifier().isCellularConnectionType()) { UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadForcedNone); return WebMediaPlayer::PreloadNone; } diff --git a/third_party/WebKit/Source/core/page/NetworkStateNotifier.h b/third_party/WebKit/Source/core/page/NetworkStateNotifier.h index 1514ba5..fb34c69 100644 --- a/third_party/WebKit/Source/core/page/NetworkStateNotifier.h +++ b/third_party/WebKit/Source/core/page/NetworkStateNotifier.h @@ -74,6 +74,27 @@ public: } // Can be called on any thread. + bool isCellularConnectionType() const + { + switch (connectionType()) { + case WebConnectionTypeCellular2G: + case WebConnectionTypeCellular3G: + case WebConnectionTypeCellular4G: + return true; + case WebConnectionTypeBluetooth: + case WebConnectionTypeEthernet: + case WebConnectionTypeWifi: + case WebConnectionTypeWimax: + case WebConnectionTypeOther: + case WebConnectionTypeNone: + case WebConnectionTypeUnknown: + return false; + } + ASSERT_NOT_REACHED(); + return false; + } + + // Can be called on any thread. double maxBandwidth() const { MutexLocker locker(m_mutex); diff --git a/third_party/WebKit/Source/core/testing/Internals.cpp b/third_party/WebKit/Source/core/testing/Internals.cpp index f3bcbda..2d8c933 100644 --- a/third_party/WebKit/Source/core/testing/Internals.cpp +++ b/third_party/WebKit/Source/core/testing/Internals.cpp @@ -2368,8 +2368,12 @@ void Internals::setNetworkStateNotifierTestOnly(bool testOnly) void Internals::setNetworkConnectionInfo(const String& type, double downlinkMaxMbps, ExceptionState& exceptionState) { WebConnectionType webtype; - if (type == "cellular") { - webtype = WebConnectionTypeCellular; + if (type == "cellular2g") { + webtype = WebConnectionTypeCellular2G; + } else if (type == "cellular3g") { + webtype = WebConnectionTypeCellular3G; + } else if (type == "cellular4g") { + webtype = WebConnectionTypeCellular4G; } else if (type == "bluetooth") { webtype = WebConnectionTypeBluetooth; } else if (type == "ethernet") { diff --git a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp index 75d5086..95d79fb 100644 --- a/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp +++ b/third_party/WebKit/Source/modules/netinfo/NetworkInformation.cpp @@ -19,7 +19,9 @@ using namespace blink; String connectionTypeToString(WebConnectionType type) { switch (type) { - case WebConnectionTypeCellular: + case WebConnectionTypeCellular2G: + case WebConnectionTypeCellular3G: + case WebConnectionTypeCellular4G: return "cellular"; case WebConnectionTypeBluetooth: return "bluetooth"; diff --git a/third_party/WebKit/public/platform/WebConnectionType.h b/third_party/WebKit/public/platform/WebConnectionType.h index a614958..d5a7940 100644 --- a/third_party/WebKit/public/platform/WebConnectionType.h +++ b/third_party/WebKit/public/platform/WebConnectionType.h @@ -33,9 +33,11 @@ namespace blink { -// Connection types from http://w3c.github.io/netinfo/. +// A superset of Connection types from http://w3c.github.io/netinfo/. enum WebConnectionType { - WebConnectionTypeCellular = 0, + WebConnectionTypeCellular2G = 0, + WebConnectionTypeCellular3G, + WebConnectionTypeCellular4G, WebConnectionTypeBluetooth, WebConnectionTypeEthernet, WebConnectionTypeWifi, |