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
3 // found in the LICENSE file.
6 #include "core/fetch/ClientHintsPreferences.h"
8 #include "core/fetch/ResourceFetcher.h"
9 #include "platform/RuntimeEnabledFeatures.h"
10 #include "platform/network/HTTPParsers.h"
14 ClientHintsPreferences::ClientHintsPreferences()
15 : m_shouldSendDPR(false)
16 , m_shouldSendResourceWidth(false)
17 , m_shouldSendViewportWidth(false)
21 void ClientHintsPreferences::updateFrom(const ClientHintsPreferences
& preferences
)
23 m_shouldSendDPR
= preferences
.m_shouldSendDPR
;
24 m_shouldSendResourceWidth
= preferences
.m_shouldSendResourceWidth
;
25 m_shouldSendViewportWidth
= preferences
.m_shouldSendViewportWidth
;
28 void ClientHintsPreferences::updateFromAcceptClientHintsHeader(const String
& headerValue
, ResourceFetcher
* fetcher
)
30 if (!RuntimeEnabledFeatures::clientHintsEnabled() || headerValue
.isEmpty())
33 CommaDelimitedHeaderSet acceptClientHintsHeader
;
34 parseCommaDelimitedHeader(headerValue
, acceptClientHintsHeader
);
35 if (acceptClientHintsHeader
.contains("dpr")) {
37 fetcher
->context().countClientHintsDPR();
38 m_shouldSendDPR
= true;
41 if (acceptClientHintsHeader
.contains("width")) {
43 fetcher
->context().countClientHintsResourceWidth();
44 m_shouldSendResourceWidth
= true;
47 if (acceptClientHintsHeader
.contains("viewport-width")) {
49 fetcher
->context().countClientHintsViewportWidth();
50 m_shouldSendViewportWidth
= true;