OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return false; | 569 return false; |
570 } | 570 } |
571 | 571 |
572 void InspectorNetworkAgent::didBlockRequest( | 572 void InspectorNetworkAgent::didBlockRequest( |
573 LocalFrame* frame, | 573 LocalFrame* frame, |
574 const ResourceRequest& request, | 574 const ResourceRequest& request, |
575 DocumentLoader* loader, | 575 DocumentLoader* loader, |
576 const FetchInitiatorInfo& initiatorInfo, | 576 const FetchInitiatorInfo& initiatorInfo, |
577 ResourceRequestBlockedReason reason) { | 577 ResourceRequestBlockedReason reason) { |
578 unsigned long identifier = createUniqueIdentifier(); | 578 unsigned long identifier = createUniqueIdentifier(); |
579 willSendRequestInternal(identifier, loader, request, ResourceResponse(), | 579 willSendRequestInternal(frame, identifier, loader, request, |
580 initiatorInfo); | 580 ResourceResponse(), initiatorInfo); |
581 | 581 |
582 String requestId = IdentifiersFactory::requestId(identifier); | 582 String requestId = IdentifiersFactory::requestId(identifier); |
583 String protocolReason = buildBlockedReason(reason); | 583 String protocolReason = buildBlockedReason(reason); |
584 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), | 584 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), |
585 InspectorPageAgent::resourceTypeJson( | 585 InspectorPageAgent::resourceTypeJson( |
586 m_resourcesData->resourceType(requestId)), | 586 m_resourcesData->resourceType(requestId)), |
587 String(), false, protocolReason); | 587 String(), false, protocolReason); |
588 } | 588 } |
589 | 589 |
590 void InspectorNetworkAgent::didChangeResourcePriority( | 590 void InspectorNetworkAgent::didChangeResourcePriority( |
591 unsigned long identifier, | 591 unsigned long identifier, |
592 ResourceLoadPriority loadPriority) { | 592 ResourceLoadPriority loadPriority) { |
593 String requestId = IdentifiersFactory::requestId(identifier); | 593 String requestId = IdentifiersFactory::requestId(identifier); |
594 frontend()->resourceChangedPriority(requestId, | 594 frontend()->resourceChangedPriority(requestId, |
595 resourcePriorityJSON(loadPriority), | 595 resourcePriorityJSON(loadPriority), |
596 monotonicallyIncreasingTime()); | 596 monotonicallyIncreasingTime()); |
597 } | 597 } |
598 | 598 |
599 void InspectorNetworkAgent::willSendRequestInternal( | 599 void InspectorNetworkAgent::willSendRequestInternal( |
| 600 LocalFrame* frame, |
600 unsigned long identifier, | 601 unsigned long identifier, |
601 DocumentLoader* loader, | 602 DocumentLoader* loader, |
602 const ResourceRequest& request, | 603 const ResourceRequest& request, |
603 const ResourceResponse& redirectResponse, | 604 const ResourceResponse& redirectResponse, |
604 const FetchInitiatorInfo& initiatorInfo) { | 605 const FetchInitiatorInfo& initiatorInfo) { |
605 String requestId = IdentifiersFactory::requestId(identifier); | 606 String requestId = IdentifiersFactory::requestId(identifier); |
606 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : ""; | 607 String loaderId = IdentifiersFactory::loaderId(loader); |
607 m_resourcesData->resourceCreated(requestId, loaderId, request.url()); | 608 m_resourcesData->resourceCreated(requestId, loaderId, request.url()); |
608 | 609 |
609 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; | 610 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; |
610 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { | 611 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { |
611 type = InspectorPageAgent::XHRResource; | 612 type = InspectorPageAgent::XHRResource; |
612 m_resourcesData->setResourceType(requestId, type); | 613 m_resourcesData->setResourceType(requestId, type); |
613 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | 614 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { |
614 type = InspectorPageAgent::DocumentResource; | 615 type = InspectorPageAgent::DocumentResource; |
615 m_resourcesData->setResourceType(requestId, type); | 616 m_resourcesData->setResourceType(requestId, type); |
616 } | 617 } |
617 | 618 |
618 String frameId = loader && loader->frame() | 619 String frameId = |
619 ? IdentifiersFactory::frameId(loader->frame()) | 620 loader->frame() ? IdentifiersFactory::frameId(loader->frame()) : ""; |
620 : ""; | 621 std::unique_ptr<protocol::Network::Initiator> initiatorObject = |
621 std::unique_ptr<protocol::Network::Initiator> initiatorObject; | 622 buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0, |
622 if (loader) { | 623 initiatorInfo); |
623 initiatorObject = buildInitiatorObject( | |
624 loader->frame() ? loader->frame()->document() : 0, initiatorInfo); | |
625 } else { | |
626 initiatorObject = | |
627 protocol::Network::Initiator::create() | |
628 .setType(protocol::Network::Initiator::TypeEnum::Preload) | |
629 .build(); | |
630 } | |
631 | |
632 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | 624 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { |
633 FrameNavigationInitiatorMap::iterator it = | 625 FrameNavigationInitiatorMap::iterator it = |
634 m_frameNavigationInitiatorMap.find(frameId); | 626 m_frameNavigationInitiatorMap.find(frameId); |
635 if (it != m_frameNavigationInitiatorMap.end()) | 627 if (it != m_frameNavigationInitiatorMap.end()) |
636 initiatorObject = it->value->clone(); | 628 initiatorObject = it->value->clone(); |
637 } | 629 } |
638 | 630 |
639 std::unique_ptr<protocol::Network::Request> requestInfo( | 631 std::unique_ptr<protocol::Network::Request> requestInfo( |
640 buildObjectForResourceRequest(request)); | 632 buildObjectForResourceRequest(request)); |
641 | 633 |
642 if (loader) { | 634 requestInfo->setMixedContentType(mixedContentTypeForContextType( |
643 requestInfo->setMixedContentType(mixedContentTypeForContextType( | 635 MixedContentChecker::contextTypeForInspector(frame, request))); |
644 MixedContentChecker::contextTypeForInspector(loader->frame(), | |
645 request))); | |
646 } | |
647 | 636 |
648 requestInfo->setReferrerPolicy(referrerPolicy(request.getReferrerPolicy())); | 637 requestInfo->setReferrerPolicy(referrerPolicy(request.getReferrerPolicy())); |
649 | 638 |
650 String resourceType = InspectorPageAgent::resourceTypeJson(type); | 639 String resourceType = InspectorPageAgent::resourceTypeJson(type); |
651 frontend()->requestWillBeSent( | 640 frontend()->requestWillBeSent( |
652 requestId, frameId, loaderId, | 641 requestId, frameId, loaderId, |
653 loader ? urlWithoutFragment(loader->url()).getString() : "", | 642 urlWithoutFragment(loader->url()).getString(), std::move(requestInfo), |
654 std::move(requestInfo), monotonicallyIncreasingTime(), currentTime(), | 643 monotonicallyIncreasingTime(), currentTime(), std::move(initiatorObject), |
655 std::move(initiatorObject), | |
656 buildObjectForResourceResponse(redirectResponse), resourceType); | 644 buildObjectForResourceResponse(redirectResponse), resourceType); |
657 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) | 645 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) |
658 frontend()->flush(); | 646 frontend()->flush(); |
659 } | 647 } |
660 | 648 |
661 void InspectorNetworkAgent::willSendRequest( | 649 void InspectorNetworkAgent::willSendRequest( |
| 650 LocalFrame* frame, |
662 unsigned long identifier, | 651 unsigned long identifier, |
663 DocumentLoader* loader, | 652 DocumentLoader* loader, |
664 ResourceRequest& request, | 653 ResourceRequest& request, |
665 const ResourceResponse& redirectResponse, | 654 const ResourceResponse& redirectResponse, |
666 const FetchInitiatorInfo& initiatorInfo) { | 655 const FetchInitiatorInfo& initiatorInfo) { |
667 // Ignore the request initiated internally. | 656 // Ignore the request initiated internally. |
668 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) | 657 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) |
669 return; | 658 return; |
670 | 659 |
671 if (initiatorInfo.name == FetchInitiatorTypeNames::document && | 660 if (initiatorInfo.name == FetchInitiatorTypeNames::document && |
(...skipping 19 matching lines...) Expand all Loading... |
691 request.requestContext() != WebURLRequest::RequestContextInternal) { | 680 request.requestContext() != WebURLRequest::RequestContextInternal) { |
692 request.setCachePolicy(WebCachePolicy::BypassCacheLoadOnlyFromCache); | 681 request.setCachePolicy(WebCachePolicy::BypassCacheLoadOnlyFromCache); |
693 } else { | 682 } else { |
694 request.setCachePolicy(WebCachePolicy::BypassingCache); | 683 request.setCachePolicy(WebCachePolicy::BypassingCache); |
695 } | 684 } |
696 request.setShouldResetAppCache(true); | 685 request.setShouldResetAppCache(true); |
697 } | 686 } |
698 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false)) | 687 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false)) |
699 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 688 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
700 | 689 |
701 willSendRequestInternal(identifier, loader, request, redirectResponse, | 690 willSendRequestInternal(frame, identifier, loader, request, redirectResponse, |
702 initiatorInfo); | 691 initiatorInfo); |
703 | 692 |
704 if (!m_hostId.isEmpty()) | 693 if (!m_hostId.isEmpty()) |
705 request.addHTTPHeaderField( | 694 request.addHTTPHeaderField( |
706 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, | 695 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, |
707 AtomicString(m_hostId)); | 696 AtomicString(m_hostId)); |
708 } | 697 } |
709 | 698 |
710 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) { | 699 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) { |
711 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier)); | 700 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier)); |
712 } | 701 } |
713 | 702 |
714 void InspectorNetworkAgent::didReceiveResourceResponse( | 703 void InspectorNetworkAgent::didReceiveResourceResponse( |
715 ExecutionContext* context, | 704 LocalFrame* frame, |
716 unsigned long identifier, | 705 unsigned long identifier, |
717 DocumentLoader* loader, | 706 DocumentLoader* loader, |
718 const ResourceResponse& response, | 707 const ResourceResponse& response, |
719 Resource* cachedResource) { | 708 Resource* cachedResource) { |
720 String requestId = IdentifiersFactory::requestId(identifier); | 709 String requestId = IdentifiersFactory::requestId(identifier); |
721 bool isNotModified = response.httpStatusCode() == 304; | 710 bool isNotModified = response.httpStatusCode() == 304; |
722 | 711 |
723 bool resourceIsEmpty = true; | 712 bool resourceIsEmpty = true; |
724 std::unique_ptr<protocol::Network::Response> resourceResponse = | 713 std::unique_ptr<protocol::Network::Response> resourceResponse = |
725 buildObjectForResourceResponse(response, cachedResource, | 714 buildObjectForResourceResponse(response, cachedResource, |
(...skipping 15 matching lines...) Expand all Loading... |
741 if (type == InspectorPageAgent::DocumentResource && loader && | 730 if (type == InspectorPageAgent::DocumentResource && loader && |
742 loader->substituteData().isValid()) | 731 loader->substituteData().isValid()) |
743 return; | 732 return; |
744 | 733 |
745 // Resources are added to NetworkResourcesData as a WeakMember here and | 734 // Resources are added to NetworkResourcesData as a WeakMember here and |
746 // removed in willDestroyResource() called in the prefinalizer of Resource. | 735 // removed in willDestroyResource() called in the prefinalizer of Resource. |
747 // Because NetworkResourceData retains weak references only, it | 736 // Because NetworkResourceData retains weak references only, it |
748 // doesn't affect Resource lifetime. | 737 // doesn't affect Resource lifetime. |
749 if (cachedResource) | 738 if (cachedResource) |
750 m_resourcesData->addResource(requestId, cachedResource); | 739 m_resourcesData->addResource(requestId, cachedResource); |
751 String frameId = | 740 String frameId = IdentifiersFactory::frameId(frame); |
752 context->isDocument() | |
753 ? IdentifiersFactory::frameId(toDocument(context)->frame()) | |
754 : ""; | |
755 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : ""; | 741 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : ""; |
756 m_resourcesData->responseReceived(requestId, frameId, response); | 742 m_resourcesData->responseReceived(requestId, frameId, response); |
757 m_resourcesData->setResourceType(requestId, type); | 743 m_resourcesData->setResourceType(requestId, type); |
758 | 744 |
759 if (response.getSecurityStyle() != ResourceResponse::SecurityStyleUnknown && | 745 if (response.getSecurityStyle() != ResourceResponse::SecurityStyleUnknown && |
760 response.getSecurityStyle() != | 746 response.getSecurityStyle() != |
761 ResourceResponse::SecurityStyleUnauthenticated) { | 747 ResourceResponse::SecurityStyleUnauthenticated) { |
762 const ResourceResponse::SecurityDetails* responseSecurityDetails = | 748 const ResourceResponse::SecurityDetails* responseSecurityDetails = |
763 response.getSecurityDetails(); | 749 response.getSecurityDetails(); |
764 m_resourcesData->setCertificate(requestId, | 750 m_resourcesData->setCertificate(requestId, |
765 responseSecurityDetails->certificate); | 751 responseSecurityDetails->certificate); |
766 } | 752 } |
767 | 753 |
768 if (resourceResponse && !resourceIsEmpty) | 754 if (resourceResponse && !resourceIsEmpty) |
769 frontend()->responseReceived(requestId, frameId, loaderId, | 755 frontend()->responseReceived(requestId, frameId, loaderId, |
770 monotonicallyIncreasingTime(), | 756 monotonicallyIncreasingTime(), |
771 InspectorPageAgent::resourceTypeJson(type), | 757 InspectorPageAgent::resourceTypeJson(type), |
772 std::move(resourceResponse)); | 758 std::move(resourceResponse)); |
773 // If we revalidated the resource and got Not modified, send content length | 759 // If we revalidated the resource and got Not modified, send content length |
774 // following didReceiveResponse as there will be no calls to didReceiveData | 760 // following didReceiveResponse as there will be no calls to didReceiveData |
775 // from the network stack. | 761 // from the network stack. |
776 if (isNotModified && cachedResource && cachedResource->encodedSize()) | 762 if (isNotModified && cachedResource && cachedResource->encodedSize()) |
777 didReceiveData(identifier, 0, cachedResource->encodedSize()); | 763 didReceiveData(frame, identifier, 0, cachedResource->encodedSize()); |
778 } | 764 } |
779 | 765 |
780 static bool isErrorStatusCode(int statusCode) { | 766 static bool isErrorStatusCode(int statusCode) { |
781 return statusCode >= 400; | 767 return statusCode >= 400; |
782 } | 768 } |
783 | 769 |
784 void InspectorNetworkAgent::didReceiveData(unsigned long identifier, | 770 void InspectorNetworkAgent::didReceiveData(LocalFrame*, |
| 771 unsigned long identifier, |
785 const char* data, | 772 const char* data, |
786 int dataLength) { | 773 int dataLength) { |
787 String requestId = IdentifiersFactory::requestId(identifier); | 774 String requestId = IdentifiersFactory::requestId(identifier); |
788 | 775 |
789 if (data) { | 776 if (data) { |
790 NetworkResourcesData::ResourceData const* resourceData = | 777 NetworkResourcesData::ResourceData const* resourceData = |
791 m_resourcesData->data(requestId); | 778 m_resourcesData->data(requestId); |
792 if (resourceData && | 779 if (resourceData && |
793 (!resourceData->cachedResource() || | 780 (!resourceData->cachedResource() || |
794 resourceData->cachedResource()->getDataBufferingPolicy() == | 781 resourceData->cachedResource()->getDataBufferingPolicy() == |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 encodedDataLength); | 826 encodedDataLength); |
840 } | 827 } |
841 | 828 |
842 void InspectorNetworkAgent::didReceiveCORSRedirectResponse( | 829 void InspectorNetworkAgent::didReceiveCORSRedirectResponse( |
843 LocalFrame* frame, | 830 LocalFrame* frame, |
844 unsigned long identifier, | 831 unsigned long identifier, |
845 DocumentLoader* loader, | 832 DocumentLoader* loader, |
846 const ResourceResponse& response, | 833 const ResourceResponse& response, |
847 Resource* resource) { | 834 Resource* resource) { |
848 // Update the response and finish loading | 835 // Update the response and finish loading |
849 didReceiveResourceResponse(frame->document(), identifier, loader, response, | 836 didReceiveResourceResponse(frame, identifier, loader, response, resource); |
850 resource); | |
851 didFinishLoading(identifier, 0, | 837 didFinishLoading(identifier, 0, |
852 WebURLLoaderClient::kUnknownEncodedDataLength); | 838 WebURLLoaderClient::kUnknownEncodedDataLength); |
853 } | 839 } |
854 | 840 |
855 void InspectorNetworkAgent::didFailLoading(unsigned long identifier, | 841 void InspectorNetworkAgent::didFailLoading(unsigned long identifier, |
856 const ResourceError& error) { | 842 const ResourceError& error) { |
857 String requestId = IdentifiersFactory::requestId(identifier); | 843 String requestId = IdentifiersFactory::requestId(identifier); |
858 bool canceled = error.isCancellation(); | 844 bool canceled = error.isCancellation(); |
859 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), | 845 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), |
860 InspectorPageAgent::resourceTypeJson( | 846 InspectorPageAgent::resourceTypeJson( |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 m_isRecalculatingStyle(false), | 1532 m_isRecalculatingStyle(false), |
1547 m_removeFinishedReplayXHRTimer( | 1533 m_removeFinishedReplayXHRTimer( |
1548 this, | 1534 this, |
1549 &InspectorNetworkAgent::removeFinishedReplayXHRFired) {} | 1535 &InspectorNetworkAgent::removeFinishedReplayXHRFired) {} |
1550 | 1536 |
1551 bool InspectorNetworkAgent::shouldForceCORSPreflight() { | 1537 bool InspectorNetworkAgent::shouldForceCORSPreflight() { |
1552 return m_state->booleanProperty(NetworkAgentState::cacheDisabled, false); | 1538 return m_state->booleanProperty(NetworkAgentState::cacheDisabled, false); |
1553 } | 1539 } |
1554 | 1540 |
1555 } // namespace blink | 1541 } // namespace blink |
OLD | NEW |