Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / fetch / ClientHintsPreferences.cpp
blobac9f2bf009216ea4941d58244c8cd8f67153ef8b
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.
5 #include "config.h"
6 #include "core/fetch/ClientHintsPreferences.h"
8 #include "core/fetch/ResourceFetcher.h"
9 #include "platform/RuntimeEnabledFeatures.h"
10 #include "platform/network/HTTPParsers.h"
12 namespace blink {
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())
31 return;
33 CommaDelimitedHeaderSet acceptClientHintsHeader;
34 parseCommaDelimitedHeader(headerValue, acceptClientHintsHeader);
35 if (acceptClientHintsHeader.contains("dpr")) {
36 if (fetcher)
37 fetcher->context().countClientHintsDPR();
38 m_shouldSendDPR = true;
41 if (acceptClientHintsHeader.contains("width")) {
42 if (fetcher)
43 fetcher->context().countClientHintsResourceWidth();
44 m_shouldSendResourceWidth = true;
47 if (acceptClientHintsHeader.contains("viewport-width")) {
48 if (fetcher)
49 fetcher->context().countClientHintsViewportWidth();
50 m_shouldSendViewportWidth = true;