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