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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 auto entry = blocked_urls->at(i); | 567 auto entry = blocked_urls->at(i); |
568 if (Matches(url, entry.first)) { | 568 if (Matches(url, entry.first)) { |
569 *result = true; | 569 *result = true; |
570 return; | 570 return; |
571 } | 571 } |
572 } | 572 } |
573 return; | 573 return; |
574 } | 574 } |
575 | 575 |
576 void InspectorNetworkAgent::DidBlockRequest( | 576 void InspectorNetworkAgent::DidBlockRequest( |
577 LocalFrame* frame, | |
578 const ResourceRequest& request, | 577 const ResourceRequest& request, |
579 DocumentLoader* loader, | 578 DocumentLoader* loader, |
580 const FetchInitiatorInfo& initiator_info, | 579 const FetchInitiatorInfo& initiator_info, |
581 ResourceRequestBlockedReason reason) { | 580 ResourceRequestBlockedReason reason) { |
582 unsigned long identifier = CreateUniqueIdentifier(); | 581 unsigned long identifier = CreateUniqueIdentifier(); |
583 WillSendRequestInternal(frame, identifier, loader, request, | 582 WillSendRequestInternal(identifier, loader, request, ResourceResponse(), |
584 ResourceResponse(), initiator_info); | 583 initiator_info); |
585 | 584 |
586 String request_id = IdentifiersFactory::RequestId(identifier); | 585 String request_id = IdentifiersFactory::RequestId(identifier); |
587 String protocol_reason = BuildBlockedReason(reason); | 586 String protocol_reason = BuildBlockedReason(reason); |
588 GetFrontend()->loadingFailed( | 587 GetFrontend()->loadingFailed( |
589 request_id, MonotonicallyIncreasingTime(), | 588 request_id, MonotonicallyIncreasingTime(), |
590 InspectorPageAgent::ResourceTypeJson( | 589 InspectorPageAgent::ResourceTypeJson( |
591 resources_data_->GetResourceType(request_id)), | 590 resources_data_->GetResourceType(request_id)), |
592 String(), false, protocol_reason); | 591 String(), false, protocol_reason); |
593 } | 592 } |
594 | 593 |
595 void InspectorNetworkAgent::DidChangeResourcePriority( | 594 void InspectorNetworkAgent::DidChangeResourcePriority( |
596 unsigned long identifier, | 595 unsigned long identifier, |
597 ResourceLoadPriority load_priority) { | 596 ResourceLoadPriority load_priority) { |
598 String request_id = IdentifiersFactory::RequestId(identifier); | 597 String request_id = IdentifiersFactory::RequestId(identifier); |
599 GetFrontend()->resourceChangedPriority(request_id, | 598 GetFrontend()->resourceChangedPriority(request_id, |
600 ResourcePriorityJSON(load_priority), | 599 ResourcePriorityJSON(load_priority), |
601 MonotonicallyIncreasingTime()); | 600 MonotonicallyIncreasingTime()); |
602 } | 601 } |
603 | 602 |
604 void InspectorNetworkAgent::WillSendRequestInternal( | 603 void InspectorNetworkAgent::WillSendRequestInternal( |
605 LocalFrame* frame, | |
606 unsigned long identifier, | 604 unsigned long identifier, |
607 DocumentLoader* loader, | 605 DocumentLoader* loader, |
608 const ResourceRequest& request, | 606 const ResourceRequest& request, |
609 const ResourceResponse& redirect_response, | 607 const ResourceResponse& redirect_response, |
610 const FetchInitiatorInfo& initiator_info) { | 608 const FetchInitiatorInfo& initiator_info) { |
611 String request_id = IdentifiersFactory::RequestId(identifier); | 609 String request_id = IdentifiersFactory::RequestId(identifier); |
612 String loader_id = IdentifiersFactory::LoaderId(loader); | 610 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; |
613 resources_data_->ResourceCreated(request_id, loader_id, request.Url()); | 611 resources_data_->ResourceCreated(request_id, loader_id, request.Url()); |
614 | 612 |
615 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource; | 613 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource; |
616 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) { | 614 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) { |
617 type = InspectorPageAgent::kXHRResource; | 615 type = InspectorPageAgent::kXHRResource; |
618 resources_data_->SetResourceType(request_id, type); | 616 resources_data_->SetResourceType(request_id, type); |
619 } else if (initiator_info.name == FetchInitiatorTypeNames::document) { | 617 } else if (initiator_info.name == FetchInitiatorTypeNames::document) { |
620 type = InspectorPageAgent::kDocumentResource; | 618 type = InspectorPageAgent::kDocumentResource; |
621 resources_data_->SetResourceType(request_id, type); | 619 resources_data_->SetResourceType(request_id, type); |
622 } | 620 } |
623 | 621 |
624 String frame_id = | 622 String frame_id = loader && loader->GetFrame() |
625 loader->GetFrame() ? IdentifiersFactory::FrameId(loader->GetFrame()) : ""; | 623 ? IdentifiersFactory::FrameId(loader->GetFrame()) |
| 624 : ""; |
626 std::unique_ptr<protocol::Network::Initiator> initiator_object = | 625 std::unique_ptr<protocol::Network::Initiator> initiator_object = |
627 BuildInitiatorObject( | 626 BuildInitiatorObject( |
628 loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, | 627 loader && loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, |
629 initiator_info); | 628 initiator_info); |
630 if (initiator_info.name == FetchInitiatorTypeNames::document) { | 629 if (initiator_info.name == FetchInitiatorTypeNames::document) { |
631 FrameNavigationInitiatorMap::iterator it = | 630 FrameNavigationInitiatorMap::iterator it = |
632 frame_navigation_initiator_map_.find(frame_id); | 631 frame_navigation_initiator_map_.find(frame_id); |
633 if (it != frame_navigation_initiator_map_.end()) | 632 if (it != frame_navigation_initiator_map_.end()) |
634 initiator_object = it->value->clone(); | 633 initiator_object = it->value->clone(); |
635 } | 634 } |
636 | 635 |
637 std::unique_ptr<protocol::Network::Request> request_info( | 636 std::unique_ptr<protocol::Network::Request> request_info( |
638 BuildObjectForResourceRequest(request)); | 637 BuildObjectForResourceRequest(request)); |
639 | 638 |
640 request_info->setMixedContentType(MixedContentTypeForContextType( | 639 if (loader) { |
641 MixedContentChecker::ContextTypeForInspector(frame, request))); | 640 request_info->setMixedContentType(MixedContentTypeForContextType( |
| 641 MixedContentChecker::ContextTypeForInspector(loader->GetFrame(), |
| 642 request))); |
| 643 } |
642 | 644 |
643 request_info->setReferrerPolicy( | 645 request_info->setReferrerPolicy( |
644 GetReferrerPolicy(request.GetReferrerPolicy())); | 646 GetReferrerPolicy(request.GetReferrerPolicy())); |
645 if (initiator_info.is_link_preload) | 647 if (initiator_info.is_link_preload) |
646 request_info->setIsLinkPreload(true); | 648 request_info->setIsLinkPreload(true); |
647 | 649 |
648 String resource_type = InspectorPageAgent::ResourceTypeJson(type); | 650 String resource_type = InspectorPageAgent::ResourceTypeJson(type); |
649 GetFrontend()->requestWillBeSent( | 651 GetFrontend()->requestWillBeSent( |
650 request_id, frame_id, loader_id, | 652 request_id, frame_id, loader_id, |
651 UrlWithoutFragment(loader->Url()).GetString(), std::move(request_info), | 653 loader ? UrlWithoutFragment(loader->Url()).GetString() : "", |
652 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), | 654 std::move(request_info), MonotonicallyIncreasingTime(), CurrentTime(), |
| 655 std::move(initiator_object), |
653 BuildObjectForResourceResponse(redirect_response), resource_type); | 656 BuildObjectForResourceResponse(redirect_response), resource_type); |
654 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) | 657 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) |
655 GetFrontend()->flush(); | 658 GetFrontend()->flush(); |
656 } | 659 } |
657 | 660 |
658 void InspectorNetworkAgent::WillSendRequest( | 661 void InspectorNetworkAgent::WillSendRequest( |
659 LocalFrame* frame, | |
660 unsigned long identifier, | 662 unsigned long identifier, |
661 DocumentLoader* loader, | 663 DocumentLoader* loader, |
662 ResourceRequest& request, | 664 ResourceRequest& request, |
663 const ResourceResponse& redirect_response, | 665 const ResourceResponse& redirect_response, |
664 const FetchInitiatorInfo& initiator_info) { | 666 const FetchInitiatorInfo& initiator_info) { |
665 // Ignore the request initiated internally. | 667 // Ignore the request initiated internally. |
666 if (initiator_info.name == FetchInitiatorTypeNames::internal) | 668 if (initiator_info.name == FetchInitiatorTypeNames::internal) |
667 return; | 669 return; |
668 | 670 |
669 if (initiator_info.name == FetchInitiatorTypeNames::document && | 671 if (initiator_info.name == FetchInitiatorTypeNames::document && |
(...skipping 19 matching lines...) Expand all Loading... |
689 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { | 691 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { |
690 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); | 692 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); |
691 } else { | 693 } else { |
692 request.SetCachePolicy(WebCachePolicy::kBypassingCache); | 694 request.SetCachePolicy(WebCachePolicy::kBypassingCache); |
693 } | 695 } |
694 request.SetShouldResetAppCache(true); | 696 request.SetShouldResetAppCache(true); |
695 } | 697 } |
696 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) | 698 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) |
697 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); | 699 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); |
698 | 700 |
699 WillSendRequestInternal(frame, identifier, loader, request, redirect_response, | 701 WillSendRequestInternal(identifier, loader, request, redirect_response, |
700 initiator_info); | 702 initiator_info); |
701 | 703 |
702 if (!host_id_.IsEmpty()) | 704 if (!host_id_.IsEmpty()) |
703 request.AddHTTPHeaderField( | 705 request.AddHTTPHeaderField( |
704 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, | 706 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, |
705 AtomicString(host_id_)); | 707 AtomicString(host_id_)); |
706 | 708 |
707 request.SetHTTPHeaderField( | 709 request.SetHTTPHeaderField( |
708 HTTPNames::X_DevTools_Request_Id, | 710 HTTPNames::X_DevTools_Request_Id, |
709 AtomicString(IdentifiersFactory::RequestId(identifier))); | 711 AtomicString(IdentifiersFactory::RequestId(identifier))); |
710 } | 712 } |
711 | 713 |
712 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { | 714 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { |
713 GetFrontend()->requestServedFromCache( | 715 GetFrontend()->requestServedFromCache( |
714 IdentifiersFactory::RequestId(identifier)); | 716 IdentifiersFactory::RequestId(identifier)); |
715 } | 717 } |
716 | 718 |
717 void InspectorNetworkAgent::DidReceiveResourceResponse( | 719 void InspectorNetworkAgent::DidReceiveResourceResponse( |
718 LocalFrame* frame, | |
719 unsigned long identifier, | 720 unsigned long identifier, |
720 DocumentLoader* loader, | 721 DocumentLoader* loader, |
721 const ResourceResponse& response, | 722 const ResourceResponse& response, |
722 Resource* cached_resource) { | 723 Resource* cached_resource) { |
723 String request_id = IdentifiersFactory::RequestId(identifier); | 724 String request_id = IdentifiersFactory::RequestId(identifier); |
724 bool is_not_modified = response.HttpStatusCode() == 304; | 725 bool is_not_modified = response.HttpStatusCode() == 304; |
725 | 726 |
726 bool resource_is_empty = true; | 727 bool resource_is_empty = true; |
727 std::unique_ptr<protocol::Network::Response> resource_response = | 728 std::unique_ptr<protocol::Network::Response> resource_response = |
728 BuildObjectForResourceResponse(response, cached_resource, | 729 BuildObjectForResourceResponse(response, cached_resource, |
(...skipping 15 matching lines...) Expand all Loading... |
744 if (type == InspectorPageAgent::kDocumentResource && loader && | 745 if (type == InspectorPageAgent::kDocumentResource && loader && |
745 loader->GetSubstituteData().IsValid()) | 746 loader->GetSubstituteData().IsValid()) |
746 return; | 747 return; |
747 | 748 |
748 // Resources are added to NetworkResourcesData as a WeakMember here and | 749 // Resources are added to NetworkResourcesData as a WeakMember here and |
749 // removed in willDestroyResource() called in the prefinalizer of Resource. | 750 // removed in willDestroyResource() called in the prefinalizer of Resource. |
750 // Because NetworkResourceData retains weak references only, it | 751 // Because NetworkResourceData retains weak references only, it |
751 // doesn't affect Resource lifetime. | 752 // doesn't affect Resource lifetime. |
752 if (cached_resource) | 753 if (cached_resource) |
753 resources_data_->AddResource(request_id, cached_resource); | 754 resources_data_->AddResource(request_id, cached_resource); |
754 String frame_id = IdentifiersFactory::FrameId(frame); | 755 String frame_id = loader && loader->GetFrame() |
| 756 ? IdentifiersFactory::FrameId(loader->GetFrame()) |
| 757 : ""; |
755 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; | 758 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; |
756 resources_data_->ResponseReceived(request_id, frame_id, response); | 759 resources_data_->ResponseReceived(request_id, frame_id, response); |
757 resources_data_->SetResourceType(request_id, type); | 760 resources_data_->SetResourceType(request_id, type); |
758 | 761 |
759 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && | 762 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && |
760 response.GetSecurityStyle() != | 763 response.GetSecurityStyle() != |
761 ResourceResponse::kSecurityStyleUnauthenticated) { | 764 ResourceResponse::kSecurityStyleUnauthenticated) { |
762 const ResourceResponse::SecurityDetails* response_security_details = | 765 const ResourceResponse::SecurityDetails* response_security_details = |
763 response.GetSecurityDetails(); | 766 response.GetSecurityDetails(); |
764 resources_data_->SetCertificate(request_id, | 767 resources_data_->SetCertificate(request_id, |
765 response_security_details->certificate); | 768 response_security_details->certificate); |
766 } | 769 } |
767 | 770 |
768 if (resource_response && !resource_is_empty) | 771 if (resource_response && !resource_is_empty) |
769 GetFrontend()->responseReceived(request_id, frame_id, loader_id, | 772 GetFrontend()->responseReceived(request_id, frame_id, loader_id, |
770 MonotonicallyIncreasingTime(), | 773 MonotonicallyIncreasingTime(), |
771 InspectorPageAgent::ResourceTypeJson(type), | 774 InspectorPageAgent::ResourceTypeJson(type), |
772 std::move(resource_response)); | 775 std::move(resource_response)); |
773 // If we revalidated the resource and got Not modified, send content length | 776 // If we revalidated the resource and got Not modified, send content length |
774 // following didReceiveResponse as there will be no calls to didReceiveData | 777 // following didReceiveResponse as there will be no calls to didReceiveData |
775 // from the network stack. | 778 // from the network stack. |
776 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) | 779 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) |
777 DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); | 780 DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize()); |
778 } | 781 } |
779 | 782 |
780 static bool IsErrorStatusCode(int status_code) { | 783 static bool IsErrorStatusCode(int status_code) { |
781 return status_code >= 400; | 784 return status_code >= 400; |
782 } | 785 } |
783 | 786 |
784 void InspectorNetworkAgent::DidReceiveData(LocalFrame*, | 787 void InspectorNetworkAgent::DidReceiveData(unsigned long identifier, |
785 unsigned long identifier, | 788 DocumentLoader* loader, |
786 const char* data, | 789 const char* data, |
787 int data_length) { | 790 int data_length) { |
788 String request_id = IdentifiersFactory::RequestId(identifier); | 791 String request_id = IdentifiersFactory::RequestId(identifier); |
789 | 792 |
790 if (data) { | 793 if (data) { |
791 NetworkResourcesData::ResourceData const* resource_data = | 794 NetworkResourcesData::ResourceData const* resource_data = |
792 resources_data_->Data(request_id); | 795 resources_data_->Data(request_id); |
793 if (resource_data && | 796 if (resource_data && |
794 (!resource_data->CachedResource() || | 797 (!resource_data->CachedResource() || |
795 resource_data->CachedResource()->GetDataBufferingPolicy() == | 798 resource_data->CachedResource()->GetDataBufferingPolicy() == |
796 kDoNotBufferData || | 799 kDoNotBufferData || |
797 IsErrorStatusCode(resource_data->HttpStatusCode()))) | 800 IsErrorStatusCode(resource_data->HttpStatusCode()))) |
798 resources_data_->MaybeAddResourceData(request_id, data, data_length); | 801 resources_data_->MaybeAddResourceData(request_id, data, data_length); |
799 } | 802 } |
800 | 803 |
801 GetFrontend()->dataReceived( | 804 GetFrontend()->dataReceived( |
802 request_id, MonotonicallyIncreasingTime(), data_length, | 805 request_id, MonotonicallyIncreasingTime(), data_length, |
803 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); | 806 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); |
804 } | 807 } |
805 | 808 |
806 void InspectorNetworkAgent::DidReceiveEncodedDataLength( | 809 void InspectorNetworkAgent::DidReceiveEncodedDataLength( |
807 LocalFrame*, | |
808 unsigned long identifier, | 810 unsigned long identifier, |
809 int encoded_data_length) { | 811 int encoded_data_length) { |
810 String request_id = IdentifiersFactory::RequestId(identifier); | 812 String request_id = IdentifiersFactory::RequestId(identifier); |
811 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); | 813 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); |
812 } | 814 } |
813 | 815 |
814 void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, | 816 void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier, |
815 unsigned long identifier, | 817 DocumentLoader*, |
816 double monotonic_finish_time, | 818 double monotonic_finish_time, |
817 int64_t encoded_data_length, | 819 int64_t encoded_data_length, |
818 int64_t decoded_body_length) { | 820 int64_t decoded_body_length) { |
819 String request_id = IdentifiersFactory::RequestId(identifier); | 821 String request_id = IdentifiersFactory::RequestId(identifier); |
820 NetworkResourcesData::ResourceData const* resource_data = | 822 NetworkResourcesData::ResourceData const* resource_data = |
821 resources_data_->Data(request_id); | 823 resources_data_->Data(request_id); |
822 | 824 |
823 int pending_encoded_data_length = | 825 int pending_encoded_data_length = |
824 resources_data_->GetAndClearPendingEncodedDataLength(request_id); | 826 resources_data_->GetAndClearPendingEncodedDataLength(request_id); |
825 if (pending_encoded_data_length > 0) { | 827 if (pending_encoded_data_length > 0) { |
(...skipping 16 matching lines...) Expand all Loading... |
842 encoded_data_length); | 844 encoded_data_length); |
843 } | 845 } |
844 | 846 |
845 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( | 847 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( |
846 LocalFrame* frame, | 848 LocalFrame* frame, |
847 unsigned long identifier, | 849 unsigned long identifier, |
848 DocumentLoader* loader, | 850 DocumentLoader* loader, |
849 const ResourceResponse& response, | 851 const ResourceResponse& response, |
850 Resource* resource) { | 852 Resource* resource) { |
851 // Update the response and finish loading | 853 // Update the response and finish loading |
852 DidReceiveResourceResponse(frame, identifier, loader, response, resource); | 854 DidReceiveResourceResponse(identifier, loader, response, resource); |
853 DidFinishLoading(frame, identifier, 0, | 855 DidFinishLoading(identifier, loader, 0, |
854 WebURLLoaderClient::kUnknownEncodedDataLength, 0); | 856 WebURLLoaderClient::kUnknownEncodedDataLength, 0); |
855 } | 857 } |
856 | 858 |
857 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, | 859 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, |
858 const ResourceError& error) { | 860 const ResourceError& error) { |
859 String request_id = IdentifiersFactory::RequestId(identifier); | 861 String request_id = IdentifiersFactory::RequestId(identifier); |
860 bool canceled = error.IsCancellation(); | 862 bool canceled = error.IsCancellation(); |
861 GetFrontend()->loadingFailed( | 863 GetFrontend()->loadingFailed( |
862 request_id, MonotonicallyIncreasingTime(), | 864 request_id, MonotonicallyIncreasingTime(), |
863 InspectorPageAgent::ResourceTypeJson( | 865 InspectorPageAgent::ResourceTypeJson( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 pending_xhr_replay_data_ = XHRReplayData::Create( | 933 pending_xhr_replay_data_ = XHRReplayData::Create( |
932 xhr->GetExecutionContext(), method, UrlWithoutFragment(url), async, | 934 xhr->GetExecutionContext(), method, UrlWithoutFragment(url), async, |
933 form_data.Get(), include_credentials); | 935 form_data.Get(), include_credentials); |
934 for (const auto& header : headers) | 936 for (const auto& header : headers) |
935 pending_xhr_replay_data_->AddHeader(header.key, header.value); | 937 pending_xhr_replay_data_->AddHeader(header.key, header.value); |
936 } | 938 } |
937 | 939 |
938 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) { | 940 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) { |
939 if (!replay_xhrs_.Contains(xhr)) | 941 if (!replay_xhrs_.Contains(xhr)) |
940 return; | 942 return; |
| 943 // TODO(horo): |m_removeFinishedReplayXHRTimer| is null on workers. |
| 944 DCHECK(remove_finished_replay_xhr_timer_); |
941 replay_xhrs_to_be_deleted_.insert(xhr); | 945 replay_xhrs_to_be_deleted_.insert(xhr); |
942 replay_xhrs_.erase(xhr); | 946 replay_xhrs_.erase(xhr); |
943 remove_finished_replay_xhr_timer_.StartOneShot(0, BLINK_FROM_HERE); | 947 remove_finished_replay_xhr_timer_->StartOneShot(0, BLINK_FROM_HERE); |
944 } | 948 } |
945 | 949 |
946 void InspectorNetworkAgent::DidFailXHRLoading(ExecutionContext* context, | 950 void InspectorNetworkAgent::DidFailXHRLoading(ExecutionContext* context, |
947 XMLHttpRequest* xhr, | 951 XMLHttpRequest* xhr, |
948 ThreadableLoaderClient* client, | 952 ThreadableLoaderClient* client, |
949 const AtomicString& method, | 953 const AtomicString& method, |
950 const String& url) { | 954 const String& url) { |
951 DidFinishXHRInternal(context, xhr, client, method, url, false); | 955 DidFinishXHRInternal(context, xhr, client, method, url, false); |
952 } | 956 } |
953 | 957 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 else | 1408 else |
1405 GetNetworkStateNotifier().ClearOverride(); | 1409 GetNetworkStateNotifier().ClearOverride(); |
1406 return Response::OK(); | 1410 return Response::OK(); |
1407 } | 1411 } |
1408 | 1412 |
1409 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { | 1413 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { |
1410 // TODO(ananta) | 1414 // TODO(ananta) |
1411 // We should extract network cache state into a global entity which can be | 1415 // We should extract network cache state into a global entity which can be |
1412 // queried from FrameLoader and other places. | 1416 // queried from FrameLoader and other places. |
1413 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); | 1417 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); |
1414 if (cache_disabled) | 1418 if (cache_disabled && IsMainThread()) |
1415 GetMemoryCache()->EvictResources(); | 1419 GetMemoryCache()->EvictResources(); |
1416 return Response::OK(); | 1420 return Response::OK(); |
1417 } | 1421 } |
1418 | 1422 |
1419 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { | 1423 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { |
1420 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); | 1424 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); |
1421 return Response::OK(); | 1425 return Response::OK(); |
1422 } | 1426 } |
1423 | 1427 |
1424 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, | 1428 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, |
(...skipping 19 matching lines...) Expand all Loading... |
1444 } | 1448 } |
1445 } | 1449 } |
1446 return Response::OK(); | 1450 return Response::OK(); |
1447 } | 1451 } |
1448 | 1452 |
1449 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, | 1453 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, |
1450 DocumentLoader* loader) { | 1454 DocumentLoader* loader) { |
1451 if (loader->GetFrame() != inspected_frames_->Root()) | 1455 if (loader->GetFrame() != inspected_frames_->Root()) |
1452 return; | 1456 return; |
1453 | 1457 |
1454 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) | 1458 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false) && |
| 1459 IsMainThread()) { |
1455 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); | 1460 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); |
| 1461 } |
1456 | 1462 |
1457 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); | 1463 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); |
1458 } | 1464 } |
1459 | 1465 |
1460 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, | 1466 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, |
1461 double) { | 1467 double) { |
1462 String frame_id = IdentifiersFactory::FrameId(frame); | 1468 String frame_id = IdentifiersFactory::FrameId(frame); |
1463 frames_with_scheduled_navigation_.insert(frame_id); | 1469 frames_with_scheduled_navigation_.insert(frame_id); |
1464 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) { | 1470 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) { |
1465 frame_navigation_initiator_map_.Set( | 1471 frame_navigation_initiator_map_.Set( |
(...skipping 30 matching lines...) Expand all Loading... |
1496 void InspectorNetworkAgent::SetHostId(const String& host_id) { | 1502 void InspectorNetworkAgent::SetHostId(const String& host_id) { |
1497 host_id_ = host_id; | 1503 host_id_ = host_id; |
1498 } | 1504 } |
1499 | 1505 |
1500 bool InspectorNetworkAgent::FetchResourceContent(Document* document, | 1506 bool InspectorNetworkAgent::FetchResourceContent(Document* document, |
1501 const KURL& url, | 1507 const KURL& url, |
1502 String* content, | 1508 String* content, |
1503 bool* base64_encoded) { | 1509 bool* base64_encoded) { |
1504 // First try to fetch content from the cached resource. | 1510 // First try to fetch content from the cached resource. |
1505 Resource* cached_resource = document->Fetcher()->CachedResource(url); | 1511 Resource* cached_resource = document->Fetcher()->CachedResource(url); |
1506 if (!cached_resource) | 1512 if (!cached_resource && IsMainThread()) { |
1507 cached_resource = GetMemoryCache()->ResourceForURL( | 1513 cached_resource = GetMemoryCache()->ResourceForURL( |
1508 url, document->Fetcher()->GetCacheIdentifier()); | 1514 url, document->Fetcher()->GetCacheIdentifier()); |
| 1515 } |
1509 if (cached_resource && InspectorPageAgent::CachedResourceContent( | 1516 if (cached_resource && InspectorPageAgent::CachedResourceContent( |
1510 cached_resource, content, base64_encoded)) | 1517 cached_resource, content, base64_encoded)) |
1511 return true; | 1518 return true; |
1512 | 1519 |
1513 // Then fall back to resource data. | 1520 // Then fall back to resource data. |
1514 for (auto& resource : resources_data_->Resources()) { | 1521 for (auto& resource : resources_data_->Resources()) { |
1515 if (resource->RequestedURL() == url) { | 1522 if (resource->RequestedURL() == url) { |
1516 *content = resource->Content(); | 1523 *content = resource->Content(); |
1517 *base64_encoded = resource->Base64Encoded(); | 1524 *base64_encoded = resource->Base64Encoded(); |
1518 return true; | 1525 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
1531 replay_xhrs_to_be_deleted_.clear(); | 1538 replay_xhrs_to_be_deleted_.clear(); |
1532 } | 1539 } |
1533 | 1540 |
1534 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) | 1541 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) |
1535 : inspected_frames_(inspected_frames), | 1542 : inspected_frames_(inspected_frames), |
1536 resources_data_( | 1543 resources_data_( |
1537 NetworkResourcesData::Create(g_maximum_total_buffer_size, | 1544 NetworkResourcesData::Create(g_maximum_total_buffer_size, |
1538 g_maximum_resource_buffer_size)), | 1545 g_maximum_resource_buffer_size)), |
1539 pending_request_(nullptr), | 1546 pending_request_(nullptr), |
1540 remove_finished_replay_xhr_timer_( | 1547 remove_finished_replay_xhr_timer_( |
1541 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, | 1548 inspected_frames |
1542 inspected_frames->Root()), | 1549 ? new TaskRunnerTimer<InspectorNetworkAgent>( |
1543 this, | 1550 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, |
1544 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} | 1551 inspected_frames->Root()), |
| 1552 this, |
| 1553 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) |
| 1554 : nullptr) {} |
1545 | 1555 |
1546 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { | 1556 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { |
1547 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) | 1557 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) |
1548 *result = true; | 1558 *result = true; |
1549 } | 1559 } |
1550 | 1560 |
1551 } // namespace blink | 1561 } // namespace blink |
OLD | NEW |