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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 { | 662 { |
663 if (frame()->document()) | 663 if (frame()->document()) |
664 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); | 664 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); |
665 } | 665 } |
666 | 666 |
667 SecurityOrigin* FrameFetchContext::getSecurityOrigin() const | 667 SecurityOrigin* FrameFetchContext::getSecurityOrigin() const |
668 { | 668 { |
669 return m_document ? m_document->getSecurityOrigin() : nullptr; | 669 return m_document ? m_document->getSecurityOrigin() : nullptr; |
670 } | 670 } |
671 | 671 |
672 void FrameFetchContext::upgradeInsecureRequest(FetchRequest& fetchRequest) | 672 void FrameFetchContext::upgradeInsecureRequest(ResourceRequest& resourceRequest) |
673 { | 673 { |
674 KURL url = fetchRequest.resourceRequest().url(); | 674 KURL url = resourceRequest.url(); |
675 | 675 |
676 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational reque
sts, as described in | 676 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational reque
sts, as described in |
677 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect | 677 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect |
678 if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNo
ne) | 678 if (resourceRequest.frameType() != WebURLRequest::FrameTypeNone) |
679 fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecu
re-Requests", "1"); | 679 resourceRequest.addHTTPHeaderField("Upgrade-Insecure-Requests", "1"); |
680 | 680 |
681 // If we don't yet have an |m_document| (because we're loading an iframe, fo
r instance), check the FrameLoader's policy. | 681 // If we don't yet have an |m_document| (because we're loading an iframe, fo
r instance), check the FrameLoader's policy. |
682 WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecu
reRequestPolicy() : frame()->loader().getInsecureRequestPolicy(); | 682 WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecu
reRequestPolicy() : frame()->loader().getInsecureRequestPolicy(); |
683 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_document
? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNavigat
ionsToUpgrade(); | 683 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_document
? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNavigat
ionsToUpgrade(); |
684 | 684 |
685 if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) { | 685 if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) { |
686 // We always upgrade requests that meet any of the following criteria: | 686 // We always upgrade requests that meet any of the following criteria: |
687 // | 687 // |
688 // 1. Are for subresources (including nested frames). | 688 // 1. Are for subresources (including nested frames). |
689 // 2. Are form submissions. | 689 // 2. Are form submissions. |
690 // 3. Whose hosts are contained in the document's InsecureNavigationSet. | 690 // 3. Whose hosts are contained in the document's InsecureNavigationSet. |
691 const ResourceRequest& request = fetchRequest.resourceRequest(); | 691 if (resourceRequest.frameType() == WebURLRequest::FrameTypeNone |
692 if (request.frameType() == WebURLRequest::FrameTypeNone | 692 || resourceRequest.frameType() == WebURLRequest::FrameTypeNested |
693 || request.frameType() == WebURLRequest::FrameTypeNested | 693 || resourceRequest.requestContext() == WebURLRequest::RequestContext
Form |
694 || request.requestContext() == WebURLRequest::RequestContextForm | 694 || (!url.host().isNull() && relevantNavigationSet->contains(url.host
().impl()->hash()))) { |
695 || (!url.host().isNull() && relevantNavigationSet->contains(url.host
().impl()->hash()))) | |
696 { | |
697 UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpg
radedRequest); | 695 UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpg
radedRequest); |
698 url.setProtocol("https"); | 696 url.setProtocol("https"); |
699 if (url.port() == 80) | 697 if (url.port() == 80) |
700 url.setPort(443); | 698 url.setPort(443); |
701 fetchRequest.mutableResourceRequest().setURL(url); | 699 resourceRequest.setURL(url); |
702 } | 700 } |
703 } | 701 } |
704 } | 702 } |
705 | 703 |
706 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) | 704 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) |
707 { | 705 { |
708 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) | 706 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) |
709 return; | 707 return; |
710 | 708 |
711 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() ||
fetchRequest.clientHintsPreferences().shouldSendDPR(); | 709 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() ||
fetchRequest.clientHintsPreferences().shouldSendDPR(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 } | 781 } |
784 | 782 |
785 DEFINE_TRACE(FrameFetchContext) | 783 DEFINE_TRACE(FrameFetchContext) |
786 { | 784 { |
787 visitor->trace(m_document); | 785 visitor->trace(m_document); |
788 visitor->trace(m_documentLoader); | 786 visitor->trace(m_documentLoader); |
789 FetchContext::trace(visitor); | 787 FetchContext::trace(visitor); |
790 } | 788 } |
791 | 789 |
792 } // namespace blink | 790 } // namespace blink |
OLD | NEW |