OLD | NEW |
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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 return m_document ? m_document->getSecurityOrigin() : nullptr; | 860 return m_document ? m_document->getSecurityOrigin() : nullptr; |
861 } | 861 } |
862 | 862 |
863 void FrameFetchContext::modifyRequestForCSP(ResourceRequest& resourceRequest) { | 863 void FrameFetchContext::modifyRequestForCSP(ResourceRequest& resourceRequest) { |
864 // Record the latest requiredCSP value that will be used when sending this | 864 // Record the latest requiredCSP value that will be used when sending this |
865 // request. | 865 // request. |
866 frame()->loader().recordLatestRequiredCSP(); | 866 frame()->loader().recordLatestRequiredCSP(); |
867 frame()->loader().modifyRequestForCSP(resourceRequest, m_document); | 867 frame()->loader().modifyRequestForCSP(resourceRequest, m_document); |
868 } | 868 } |
869 | 869 |
870 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) { | 870 void FrameFetchContext::addClientHintsIfNecessary( |
| 871 const ClientHintsPreferences& hintsPreferences, |
| 872 const FetchRequest::ResourceWidth& resourceWidth, |
| 873 ResourceRequest& request) { |
871 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) | 874 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) |
872 return; | 875 return; |
873 | 876 |
874 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() || | 877 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() || |
875 fetchRequest.clientHintsPreferences().shouldSendDPR(); | 878 hintsPreferences.shouldSendDPR(); |
876 bool shouldSendResourceWidth = | 879 bool shouldSendResourceWidth = |
877 m_document->clientHintsPreferences().shouldSendResourceWidth() || | 880 m_document->clientHintsPreferences().shouldSendResourceWidth() || |
878 fetchRequest.clientHintsPreferences().shouldSendResourceWidth(); | 881 hintsPreferences.shouldSendResourceWidth(); |
879 bool shouldSendViewportWidth = | 882 bool shouldSendViewportWidth = |
880 m_document->clientHintsPreferences().shouldSendViewportWidth() || | 883 m_document->clientHintsPreferences().shouldSendViewportWidth() || |
881 fetchRequest.clientHintsPreferences().shouldSendViewportWidth(); | 884 hintsPreferences.shouldSendViewportWidth(); |
882 | 885 |
883 if (shouldSendDPR) { | 886 if (shouldSendDPR) { |
884 fetchRequest.mutableResourceRequest().addHTTPHeaderField( | 887 request.addHTTPHeaderField( |
885 "DPR", AtomicString(String::number(m_document->devicePixelRatio()))); | 888 "DPR", AtomicString(String::number(m_document->devicePixelRatio()))); |
886 } | 889 } |
887 | 890 |
888 if (shouldSendResourceWidth) { | 891 if (shouldSendResourceWidth) { |
889 FetchRequest::ResourceWidth resourceWidth = fetchRequest.getResourceWidth(); | |
890 if (resourceWidth.isSet) { | 892 if (resourceWidth.isSet) { |
891 float physicalWidth = | 893 float physicalWidth = |
892 resourceWidth.width * m_document->devicePixelRatio(); | 894 resourceWidth.width * m_document->devicePixelRatio(); |
893 fetchRequest.mutableResourceRequest().addHTTPHeaderField( | 895 request.addHTTPHeaderField( |
894 "Width", AtomicString(String::number(ceil(physicalWidth)))); | 896 "Width", AtomicString(String::number(ceil(physicalWidth)))); |
895 } | 897 } |
896 } | 898 } |
897 | 899 |
898 if (shouldSendViewportWidth && frame()->view()) { | 900 if (shouldSendViewportWidth && frame()->view()) { |
899 fetchRequest.mutableResourceRequest().addHTTPHeaderField( | 901 request.addHTTPHeaderField( |
900 "Viewport-Width", | 902 "Viewport-Width", |
901 AtomicString(String::number(frame()->view()->viewportWidth()))); | 903 AtomicString(String::number(frame()->view()->viewportWidth()))); |
902 } | 904 } |
903 } | 905 } |
904 | 906 |
905 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, | 907 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, |
906 FetchRequest& fetchRequest) { | 908 ResourceRequest& request) { |
907 if (!m_document) | 909 if (!m_document) |
908 return; | 910 return; |
909 | 911 |
910 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy(); | 912 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy(); |
911 if (csp->shouldSendCSPHeader(type)) | 913 if (csp->shouldSendCSPHeader(type)) |
912 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"); | 914 request.addHTTPHeaderField("CSP", "active"); |
913 } | 915 } |
914 | 916 |
915 void FrameFetchContext::populateRequestData(ResourceRequest& request) { | 917 void FrameFetchContext::populateResourceRequest( |
| 918 Resource::Type type, |
| 919 const ClientHintsPreferences& hintsPreferences, |
| 920 const FetchRequest::ResourceWidth& resourceWidth, |
| 921 ResourceRequest& request) { |
| 922 setFirstPartyCookieAndRequestorOrigin(request); |
| 923 modifyRequestForCSP(request); |
| 924 addClientHintsIfNecessary(hintsPreferences, resourceWidth, request); |
| 925 addCSPHeaderIfNecessary(type, request); |
| 926 } |
| 927 |
| 928 void FrameFetchContext::setFirstPartyCookieAndRequestorOrigin( |
| 929 ResourceRequest& request) { |
916 if (!m_document) | 930 if (!m_document) |
917 return; | 931 return; |
918 | 932 |
919 if (request.firstPartyForCookies().isNull()) { | 933 if (request.firstPartyForCookies().isNull()) { |
920 request.setFirstPartyForCookies( | 934 request.setFirstPartyForCookies( |
921 m_document ? m_document->firstPartyForCookies() | 935 m_document ? m_document->firstPartyForCookies() |
922 : SecurityOrigin::urlWithUniqueSecurityOrigin()); | 936 : SecurityOrigin::urlWithUniqueSecurityOrigin()); |
923 } | 937 } |
924 | 938 |
925 // Subresource requests inherit their requestor origin from |m_document| | 939 // Subresource requests inherit their requestor origin from |m_document| |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 response); | 1040 response); |
1027 } | 1041 } |
1028 | 1042 |
1029 DEFINE_TRACE(FrameFetchContext) { | 1043 DEFINE_TRACE(FrameFetchContext) { |
1030 visitor->trace(m_document); | 1044 visitor->trace(m_document); |
1031 visitor->trace(m_documentLoader); | 1045 visitor->trace(m_documentLoader); |
1032 FetchContext::trace(visitor); | 1046 FetchContext::trace(visitor); |
1033 } | 1047 } |
1034 | 1048 |
1035 } // namespace blink | 1049 } // namespace blink |
OLD | NEW |