| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/fetch/ClientHintsPreferences.h" | 6 #include "core/fetch/ClientHintsPreferences.h" |
| 7 | 7 |
| 8 #include "core/fetch/ResourceFetcher.h" | 8 #include "core/fetch/ResourceFetcher.h" |
| 9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
| 10 #include "platform/network/HTTPParsers.h" | 10 #include "platform/network/HTTPParsers.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void handleAcceptClientHintsHeader(const String& headerValue, ClientHintsPrefere
nces& preferences, ResourceFetcher* fetcher) | 14 ClientHintsPreferences::ClientHintsPreferences() |
| 15 : m_shouldSendDPR(false) |
| 16 , m_shouldSendResourceWidth(false) |
| 17 , m_shouldSendViewportWidth(false) |
| 18 { |
| 19 } |
| 20 |
| 21 void ClientHintsPreferences::updateFrom(const ClientHintsPreferences& preference
s) |
| 22 { |
| 23 m_shouldSendDPR = preferences.m_shouldSendDPR; |
| 24 m_shouldSendResourceWidth = preferences.m_shouldSendResourceWidth; |
| 25 m_shouldSendViewportWidth = preferences.m_shouldSendViewportWidth; |
| 26 } |
| 27 |
| 28 void ClientHintsPreferences::updateFromAcceptClientHintsHeader(const String& hea
derValue, ResourceFetcher* fetcher) |
| 15 { | 29 { |
| 16 if (!RuntimeEnabledFeatures::clientHintsEnabled() || headerValue.isEmpty()) | 30 if (!RuntimeEnabledFeatures::clientHintsEnabled() || headerValue.isEmpty()) |
| 17 return; | 31 return; |
| 18 CommaDelimitedHeaderSet acceptCH; | 32 |
| 19 parseCommaDelimitedHeader(headerValue, acceptCH); | 33 CommaDelimitedHeaderSet acceptClientHintsHeader; |
| 20 if (acceptCH.contains("dpr")) { | 34 parseCommaDelimitedHeader(headerValue, acceptClientHintsHeader); |
| 35 if (acceptClientHintsHeader.contains("dpr")) { |
| 21 if (fetcher) | 36 if (fetcher) |
| 22 fetcher->context().countClientHintsDPR(); | 37 fetcher->context().countClientHintsDPR(); |
| 23 preferences.setShouldSendDPR(true); | 38 m_shouldSendDPR = true; |
| 24 } | 39 } |
| 25 | 40 |
| 26 if (acceptCH.contains("width")) { | 41 if (acceptClientHintsHeader.contains("width")) { |
| 27 if (fetcher) | 42 if (fetcher) |
| 28 fetcher->context().countClientHintsResourceWidth(); | 43 fetcher->context().countClientHintsResourceWidth(); |
| 29 preferences.setShouldSendResourceWidth(true); | 44 m_shouldSendResourceWidth = true; |
| 30 } | 45 } |
| 31 | 46 |
| 32 if (acceptCH.contains("viewport-width")) { | 47 if (acceptClientHintsHeader.contains("viewport-width")) { |
| 33 if (fetcher) | 48 if (fetcher) |
| 34 fetcher->context().countClientHintsViewportWidth(); | 49 fetcher->context().countClientHintsViewportWidth(); |
| 35 preferences.setShouldSendViewportWidth(true); | 50 m_shouldSendViewportWidth = true; |
| 36 } | 51 } |
| 37 } | 52 } |
| 38 | 53 |
| 39 } | 54 } |
| OLD | NEW |