Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2555713002: Don't use FetchRequest in FrameFetchContext (Closed)
Patch Set: a Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return m_document ? m_document->getSecurityOrigin() : nullptr; 889 return m_document ? m_document->getSecurityOrigin() : nullptr;
890 } 890 }
891 891
892 void FrameFetchContext::modifyRequestForCSP(ResourceRequest& resourceRequest) { 892 void FrameFetchContext::modifyRequestForCSP(ResourceRequest& resourceRequest) {
893 // Record the latest requiredCSP value that will be used when sending this 893 // Record the latest requiredCSP value that will be used when sending this
894 // request. 894 // request.
895 frame()->loader().recordLatestRequiredCSP(); 895 frame()->loader().recordLatestRequiredCSP();
896 frame()->loader().modifyRequestForCSP(resourceRequest, m_document); 896 frame()->loader().modifyRequestForCSP(resourceRequest, m_document);
897 } 897 }
898 898
899 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) { 899 void FrameFetchContext::addClientHintsIfNecessary(
900 const ClientHintsPreferences& hintsPreferences,
901 const FetchRequest::ResourceWidth& resourceWidth,
902 ResourceRequest& request) {
900 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) 903 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document)
901 return; 904 return;
902 905
903 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() || 906 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() ||
904 fetchRequest.clientHintsPreferences().shouldSendDPR(); 907 hintsPreferences.shouldSendDPR();
905 bool shouldSendResourceWidth = 908 bool shouldSendResourceWidth =
906 m_document->clientHintsPreferences().shouldSendResourceWidth() || 909 m_document->clientHintsPreferences().shouldSendResourceWidth() ||
907 fetchRequest.clientHintsPreferences().shouldSendResourceWidth(); 910 hintsPreferences.shouldSendResourceWidth();
908 bool shouldSendViewportWidth = 911 bool shouldSendViewportWidth =
909 m_document->clientHintsPreferences().shouldSendViewportWidth() || 912 m_document->clientHintsPreferences().shouldSendViewportWidth() ||
910 fetchRequest.clientHintsPreferences().shouldSendViewportWidth(); 913 hintsPreferences.shouldSendViewportWidth();
911 914
912 if (shouldSendDPR) { 915 if (shouldSendDPR) {
913 fetchRequest.mutableResourceRequest().addHTTPHeaderField( 916 request.addHTTPHeaderField(
914 "DPR", AtomicString(String::number(m_document->devicePixelRatio()))); 917 "DPR", AtomicString(String::number(m_document->devicePixelRatio())));
915 } 918 }
916 919
917 if (shouldSendResourceWidth) { 920 if (shouldSendResourceWidth) {
918 FetchRequest::ResourceWidth resourceWidth = fetchRequest.getResourceWidth();
919 if (resourceWidth.isSet) { 921 if (resourceWidth.isSet) {
920 float physicalWidth = 922 float physicalWidth =
921 resourceWidth.width * m_document->devicePixelRatio(); 923 resourceWidth.width * m_document->devicePixelRatio();
922 fetchRequest.mutableResourceRequest().addHTTPHeaderField( 924 request.addHTTPHeaderField(
923 "Width", AtomicString(String::number(ceil(physicalWidth)))); 925 "Width", AtomicString(String::number(ceil(physicalWidth))));
924 } 926 }
925 } 927 }
926 928
927 if (shouldSendViewportWidth && frame()->view()) { 929 if (shouldSendViewportWidth && frame()->view()) {
928 fetchRequest.mutableResourceRequest().addHTTPHeaderField( 930 request.addHTTPHeaderField(
929 "Viewport-Width", 931 "Viewport-Width",
930 AtomicString(String::number(frame()->view()->viewportWidth()))); 932 AtomicString(String::number(frame()->view()->viewportWidth())));
931 } 933 }
932 } 934 }
933 935
934 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, 936 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type,
935 FetchRequest& fetchRequest) { 937 ResourceRequest& request) {
936 if (!m_document) 938 if (!m_document)
937 return; 939 return;
938 940
939 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy(); 941 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy();
940 if (csp->shouldSendCSPHeader(type)) 942 if (csp->shouldSendCSPHeader(type))
941 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"); 943 request.addHTTPHeaderField("CSP", "active");
942 } 944 }
943 945
944 void FrameFetchContext::populateRequestData(ResourceRequest& request) { 946 void FrameFetchContext::populateResourceRequest(
947 Resource::Type type,
948 const ClientHintsPreferences& hintsPreferences,
949 const FetchRequest::ResourceWidth& resourceWidth,
950 ResourceRequest& request) {
951 setFirstPartyCookieAndRequestorOrigin(request);
952 modifyRequestForCSP(request);
953 addClientHintsIfNecessary(hintsPreferences, resourceWidth, request);
954 addCSPHeaderIfNecessary(type, request);
955 }
956
957 void FrameFetchContext::setFirstPartyCookieAndRequestorOrigin(
958 ResourceRequest& request) {
945 if (!m_document) 959 if (!m_document)
946 return; 960 return;
947 961
948 if (request.firstPartyForCookies().isNull()) { 962 if (request.firstPartyForCookies().isNull()) {
949 request.setFirstPartyForCookies( 963 request.setFirstPartyForCookies(
950 m_document ? m_document->firstPartyForCookies() 964 m_document ? m_document->firstPartyForCookies()
951 : SecurityOrigin::urlWithUniqueSecurityOrigin()); 965 : SecurityOrigin::urlWithUniqueSecurityOrigin());
952 } 966 }
953 967
954 // Subresource requests inherit their requestor origin from |m_document| 968 // Subresource requests inherit their requestor origin from |m_document|
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 response); 1055 response);
1042 } 1056 }
1043 1057
1044 DEFINE_TRACE(FrameFetchContext) { 1058 DEFINE_TRACE(FrameFetchContext) {
1045 visitor->trace(m_document); 1059 visitor->trace(m_document);
1046 visitor->trace(m_documentLoader); 1060 visitor->trace(m_documentLoader);
1047 FetchContext::trace(visitor); 1061 FetchContext::trace(visitor);
1048 } 1062 }
1049 1063
1050 } // namespace blink 1064 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698