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