| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fetch/ClientHintsPreferences.h" | 5 #include "core/fetch/ClientHintsPreferences.h" |
| 6 | 6 |
| 7 #include "core/fetch/ResourceFetcher.h" | |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 7 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include "platform/network/HTTPParsers.h" | 8 #include "platform/network/HTTPParsers.h" |
| 10 | 9 |
| 11 namespace blink { | 10 namespace blink { |
| 12 | 11 |
| 13 ClientHintsPreferences::ClientHintsPreferences() | 12 ClientHintsPreferences::ClientHintsPreferences() |
| 14 : m_shouldSendDPR(false), | 13 : m_shouldSendDPR(false), |
| 15 m_shouldSendResourceWidth(false), | 14 m_shouldSendResourceWidth(false), |
| 16 m_shouldSendViewportWidth(false) {} | 15 m_shouldSendViewportWidth(false) {} |
| 17 | 16 |
| 18 void ClientHintsPreferences::updateFrom( | 17 void ClientHintsPreferences::updateFrom( |
| 19 const ClientHintsPreferences& preferences) { | 18 const ClientHintsPreferences& preferences) { |
| 20 m_shouldSendDPR = preferences.m_shouldSendDPR; | 19 m_shouldSendDPR = preferences.m_shouldSendDPR; |
| 21 m_shouldSendResourceWidth = preferences.m_shouldSendResourceWidth; | 20 m_shouldSendResourceWidth = preferences.m_shouldSendResourceWidth; |
| 22 m_shouldSendViewportWidth = preferences.m_shouldSendViewportWidth; | 21 m_shouldSendViewportWidth = preferences.m_shouldSendViewportWidth; |
| 23 } | 22 } |
| 24 | 23 |
| 25 void ClientHintsPreferences::updateFromAcceptClientHintsHeader( | 24 void ClientHintsPreferences::updateFromAcceptClientHintsHeader( |
| 26 const String& headerValue, | 25 const String& headerValue, |
| 27 ResourceFetcher* fetcher) { | 26 Context* context) { |
| 28 if (!RuntimeEnabledFeatures::clientHintsEnabled() || headerValue.isEmpty()) | 27 if (!RuntimeEnabledFeatures::clientHintsEnabled() || headerValue.isEmpty()) |
| 29 return; | 28 return; |
| 30 | 29 |
| 31 CommaDelimitedHeaderSet acceptClientHintsHeader; | 30 CommaDelimitedHeaderSet acceptClientHintsHeader; |
| 32 parseCommaDelimitedHeader(headerValue, acceptClientHintsHeader); | 31 parseCommaDelimitedHeader(headerValue, acceptClientHintsHeader); |
| 33 if (acceptClientHintsHeader.contains("dpr")) { | 32 if (acceptClientHintsHeader.contains("dpr")) { |
| 34 if (fetcher) | 33 if (context) |
| 35 fetcher->context().countClientHintsDPR(); | 34 context->countClientHintsDPR(); |
| 36 m_shouldSendDPR = true; | 35 m_shouldSendDPR = true; |
| 37 } | 36 } |
| 38 | 37 |
| 39 if (acceptClientHintsHeader.contains("width")) { | 38 if (acceptClientHintsHeader.contains("width")) { |
| 40 if (fetcher) | 39 if (context) |
| 41 fetcher->context().countClientHintsResourceWidth(); | 40 context->countClientHintsResourceWidth(); |
| 42 m_shouldSendResourceWidth = true; | 41 m_shouldSendResourceWidth = true; |
| 43 } | 42 } |
| 44 | 43 |
| 45 if (acceptClientHintsHeader.contains("viewport-width")) { | 44 if (acceptClientHintsHeader.contains("viewport-width")) { |
| 46 if (fetcher) | 45 if (context) |
| 47 fetcher->context().countClientHintsViewportWidth(); | 46 context->countClientHintsViewportWidth(); |
| 48 m_shouldSendViewportWidth = true; | 47 m_shouldSendViewportWidth = true; |
| 49 } | 48 } |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace blink | 51 } // namespace blink |
| OLD | NEW |