Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp

Issue 2807533003: [WIP2] off-main-thread loading
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 709
708 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { 710 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) {
709 GetFrontend()->requestServedFromCache( 711 GetFrontend()->requestServedFromCache(
710 IdentifiersFactory::RequestId(identifier)); 712 IdentifiersFactory::RequestId(identifier));
711 } 713 }
712 714
713 void InspectorNetworkAgent::DidReceiveResourceResponse( 715 void InspectorNetworkAgent::DidReceiveResourceResponse(
714 LocalFrame* frame,
715 unsigned long identifier, 716 unsigned long identifier,
716 DocumentLoader* loader, 717 DocumentLoader* loader,
717 const ResourceResponse& response, 718 const ResourceResponse& response,
718 Resource* cached_resource) { 719 Resource* cached_resource) {
719 String request_id = IdentifiersFactory::RequestId(identifier); 720 String request_id = IdentifiersFactory::RequestId(identifier);
720 bool is_not_modified = response.HttpStatusCode() == 304; 721 bool is_not_modified = response.HttpStatusCode() == 304;
721 722
722 bool resource_is_empty = true; 723 bool resource_is_empty = true;
723 std::unique_ptr<protocol::Network::Response> resource_response = 724 std::unique_ptr<protocol::Network::Response> resource_response =
724 BuildObjectForResourceResponse(response, cached_resource, 725 BuildObjectForResourceResponse(response, cached_resource,
(...skipping 15 matching lines...) Expand all
740 if (type == InspectorPageAgent::kDocumentResource && loader && 741 if (type == InspectorPageAgent::kDocumentResource && loader &&
741 loader->GetSubstituteData().IsValid()) 742 loader->GetSubstituteData().IsValid())
742 return; 743 return;
743 744
744 // Resources are added to NetworkResourcesData as a WeakMember here and 745 // Resources are added to NetworkResourcesData as a WeakMember here and
745 // removed in willDestroyResource() called in the prefinalizer of Resource. 746 // removed in willDestroyResource() called in the prefinalizer of Resource.
746 // Because NetworkResourceData retains weak references only, it 747 // Because NetworkResourceData retains weak references only, it
747 // doesn't affect Resource lifetime. 748 // doesn't affect Resource lifetime.
748 if (cached_resource) 749 if (cached_resource)
749 resources_data_->AddResource(request_id, cached_resource); 750 resources_data_->AddResource(request_id, cached_resource);
750 String frame_id = IdentifiersFactory::FrameId(frame); 751 String frame_id = loader && loader->GetFrame()
752 ? IdentifiersFactory::FrameId(loader->GetFrame())
753 : "";
751 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; 754 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : "";
752 resources_data_->ResponseReceived(request_id, frame_id, response); 755 resources_data_->ResponseReceived(request_id, frame_id, response);
753 resources_data_->SetResourceType(request_id, type); 756 resources_data_->SetResourceType(request_id, type);
754 757
755 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && 758 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown &&
756 response.GetSecurityStyle() != 759 response.GetSecurityStyle() !=
757 ResourceResponse::kSecurityStyleUnauthenticated) { 760 ResourceResponse::kSecurityStyleUnauthenticated) {
758 const ResourceResponse::SecurityDetails* response_security_details = 761 const ResourceResponse::SecurityDetails* response_security_details =
759 response.GetSecurityDetails(); 762 response.GetSecurityDetails();
760 resources_data_->SetCertificate(request_id, 763 resources_data_->SetCertificate(request_id,
761 response_security_details->certificate); 764 response_security_details->certificate);
762 } 765 }
763 766
764 if (resource_response && !resource_is_empty) 767 if (resource_response && !resource_is_empty)
765 GetFrontend()->responseReceived(request_id, frame_id, loader_id, 768 GetFrontend()->responseReceived(request_id, frame_id, loader_id,
766 MonotonicallyIncreasingTime(), 769 MonotonicallyIncreasingTime(),
767 InspectorPageAgent::ResourceTypeJson(type), 770 InspectorPageAgent::ResourceTypeJson(type),
768 std::move(resource_response)); 771 std::move(resource_response));
769 // If we revalidated the resource and got Not modified, send content length 772 // If we revalidated the resource and got Not modified, send content length
770 // following didReceiveResponse as there will be no calls to didReceiveData 773 // following didReceiveResponse as there will be no calls to didReceiveData
771 // from the network stack. 774 // from the network stack.
772 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) 775 if (is_not_modified && cached_resource && cached_resource->EncodedSize())
773 DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); 776 DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize());
774 } 777 }
775 778
776 static bool IsErrorStatusCode(int status_code) { 779 static bool IsErrorStatusCode(int status_code) {
777 return status_code >= 400; 780 return status_code >= 400;
778 } 781 }
779 782
780 void InspectorNetworkAgent::DidReceiveData(LocalFrame*, 783 void InspectorNetworkAgent::DidReceiveData(unsigned long identifier,
781 unsigned long identifier, 784 DocumentLoader* loader,
782 const char* data, 785 const char* data,
783 int data_length) { 786 int data_length) {
784 String request_id = IdentifiersFactory::RequestId(identifier); 787 String request_id = IdentifiersFactory::RequestId(identifier);
785 788
786 if (data) { 789 if (data) {
787 NetworkResourcesData::ResourceData const* resource_data = 790 NetworkResourcesData::ResourceData const* resource_data =
788 resources_data_->Data(request_id); 791 resources_data_->Data(request_id);
789 if (resource_data && 792 if (resource_data &&
790 (!resource_data->CachedResource() || 793 (!resource_data->CachedResource() ||
791 resource_data->CachedResource()->GetDataBufferingPolicy() == 794 resource_data->CachedResource()->GetDataBufferingPolicy() ==
792 kDoNotBufferData || 795 kDoNotBufferData ||
793 IsErrorStatusCode(resource_data->HttpStatusCode()))) 796 IsErrorStatusCode(resource_data->HttpStatusCode())))
794 resources_data_->MaybeAddResourceData(request_id, data, data_length); 797 resources_data_->MaybeAddResourceData(request_id, data, data_length);
795 } 798 }
796 799
797 GetFrontend()->dataReceived( 800 GetFrontend()->dataReceived(
798 request_id, MonotonicallyIncreasingTime(), data_length, 801 request_id, MonotonicallyIncreasingTime(), data_length,
799 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); 802 resources_data_->GetAndClearPendingEncodedDataLength(request_id));
800 } 803 }
801 804
802 void InspectorNetworkAgent::DidReceiveEncodedDataLength( 805 void InspectorNetworkAgent::DidReceiveEncodedDataLength(
803 LocalFrame*,
804 unsigned long identifier, 806 unsigned long identifier,
805 int encoded_data_length) { 807 int encoded_data_length) {
806 String request_id = IdentifiersFactory::RequestId(identifier); 808 String request_id = IdentifiersFactory::RequestId(identifier);
807 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); 809 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length);
808 } 810 }
809 811
810 void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, 812 void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier,
811 unsigned long identifier, 813 DocumentLoader*,
812 double monotonic_finish_time, 814 double monotonic_finish_time,
813 int64_t encoded_data_length, 815 int64_t encoded_data_length,
814 int64_t decoded_body_length) { 816 int64_t decoded_body_length) {
815 String request_id = IdentifiersFactory::RequestId(identifier); 817 String request_id = IdentifiersFactory::RequestId(identifier);
816 NetworkResourcesData::ResourceData const* resource_data = 818 NetworkResourcesData::ResourceData const* resource_data =
817 resources_data_->Data(request_id); 819 resources_data_->Data(request_id);
818 820
819 int pending_encoded_data_length = 821 int pending_encoded_data_length =
820 resources_data_->GetAndClearPendingEncodedDataLength(request_id); 822 resources_data_->GetAndClearPendingEncodedDataLength(request_id);
821 if (pending_encoded_data_length > 0) { 823 if (pending_encoded_data_length > 0) {
(...skipping 16 matching lines...) Expand all
838 encoded_data_length); 840 encoded_data_length);
839 } 841 }
840 842
841 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( 843 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse(
842 LocalFrame* frame, 844 LocalFrame* frame,
843 unsigned long identifier, 845 unsigned long identifier,
844 DocumentLoader* loader, 846 DocumentLoader* loader,
845 const ResourceResponse& response, 847 const ResourceResponse& response,
846 Resource* resource) { 848 Resource* resource) {
847 // Update the response and finish loading 849 // Update the response and finish loading
848 DidReceiveResourceResponse(frame, identifier, loader, response, resource); 850 DidReceiveResourceResponse(identifier, loader, response, resource);
849 DidFinishLoading(frame, identifier, 0, 851 DidFinishLoading(identifier, loader, 0,
850 WebURLLoaderClient::kUnknownEncodedDataLength, 0); 852 WebURLLoaderClient::kUnknownEncodedDataLength, 0);
851 } 853 }
852 854
853 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, 855 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier,
854 const ResourceError& error) { 856 const ResourceError& error) {
855 String request_id = IdentifiersFactory::RequestId(identifier); 857 String request_id = IdentifiersFactory::RequestId(identifier);
856 bool canceled = error.IsCancellation(); 858 bool canceled = error.IsCancellation();
857 GetFrontend()->loadingFailed( 859 GetFrontend()->loadingFailed(
858 request_id, MonotonicallyIncreasingTime(), 860 request_id, MonotonicallyIncreasingTime(),
859 InspectorPageAgent::ResourceTypeJson( 861 InspectorPageAgent::ResourceTypeJson(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 pending_xhr_replay_data_ = XHRReplayData::Create( 929 pending_xhr_replay_data_ = XHRReplayData::Create(
928 xhr->GetExecutionContext(), method, UrlWithoutFragment(url), async, 930 xhr->GetExecutionContext(), method, UrlWithoutFragment(url), async,
929 form_data.Get(), include_credentials); 931 form_data.Get(), include_credentials);
930 for (const auto& header : headers) 932 for (const auto& header : headers)
931 pending_xhr_replay_data_->AddHeader(header.key, header.value); 933 pending_xhr_replay_data_->AddHeader(header.key, header.value);
932 } 934 }
933 935
934 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) { 936 void InspectorNetworkAgent::DelayedRemoveReplayXHR(XMLHttpRequest* xhr) {
935 if (!replay_xhrs_.Contains(xhr)) 937 if (!replay_xhrs_.Contains(xhr))
936 return; 938 return;
939 // TODO(horo): |m_removeFinishedReplayXHRTimer| is null on workers.
940 DCHECK(remove_finished_replay_xhr_timer_);
937 replay_xhrs_to_be_deleted_.insert(xhr); 941 replay_xhrs_to_be_deleted_.insert(xhr);
938 replay_xhrs_.erase(xhr); 942 replay_xhrs_.erase(xhr);
939 remove_finished_replay_xhr_timer_.StartOneShot(0, BLINK_FROM_HERE); 943 remove_finished_replay_xhr_timer_->StartOneShot(0, BLINK_FROM_HERE);
940 } 944 }
941 945
942 void InspectorNetworkAgent::DidFailXHRLoading(ExecutionContext* context, 946 void InspectorNetworkAgent::DidFailXHRLoading(ExecutionContext* context,
943 XMLHttpRequest* xhr, 947 XMLHttpRequest* xhr,
944 ThreadableLoaderClient* client, 948 ThreadableLoaderClient* client,
945 const AtomicString& method, 949 const AtomicString& method,
946 const String& url) { 950 const String& url) {
947 DidFinishXHRInternal(context, xhr, client, method, url, false); 951 DidFinishXHRInternal(context, xhr, client, method, url, false);
948 } 952 }
949 953
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 else 1398 else
1395 GetNetworkStateNotifier().ClearOverride(); 1399 GetNetworkStateNotifier().ClearOverride();
1396 return Response::OK(); 1400 return Response::OK();
1397 } 1401 }
1398 1402
1399 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { 1403 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) {
1400 // TODO(ananta) 1404 // TODO(ananta)
1401 // We should extract network cache state into a global entity which can be 1405 // We should extract network cache state into a global entity which can be
1402 // queried from FrameLoader and other places. 1406 // queried from FrameLoader and other places.
1403 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); 1407 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled);
1404 if (cache_disabled) 1408 if (cache_disabled && IsMainThread())
1405 GetMemoryCache()->EvictResources(); 1409 GetMemoryCache()->EvictResources();
1406 return Response::OK(); 1410 return Response::OK();
1407 } 1411 }
1408 1412
1409 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { 1413 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) {
1410 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); 1414 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass);
1411 return Response::OK(); 1415 return Response::OK();
1412 } 1416 }
1413 1417
1414 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, 1418 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total,
(...skipping 19 matching lines...) Expand all
1434 } 1438 }
1435 } 1439 }
1436 return Response::OK(); 1440 return Response::OK();
1437 } 1441 }
1438 1442
1439 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, 1443 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame,
1440 DocumentLoader* loader) { 1444 DocumentLoader* loader) {
1441 if (loader->GetFrame() != inspected_frames_->Root()) 1445 if (loader->GetFrame() != inspected_frames_->Root())
1442 return; 1446 return;
1443 1447
1444 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1448 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false) &&
1449 IsMainThread()) {
1445 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); 1450 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads);
1451 }
1446 1452
1447 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); 1453 resources_data_->Clear(IdentifiersFactory::LoaderId(loader));
1448 } 1454 }
1449 1455
1450 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, 1456 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame,
1451 double) { 1457 double) {
1452 String frame_id = IdentifiersFactory::FrameId(frame); 1458 String frame_id = IdentifiersFactory::FrameId(frame);
1453 frames_with_scheduled_navigation_.insert(frame_id); 1459 frames_with_scheduled_navigation_.insert(frame_id);
1454 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) { 1460 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) {
1455 frame_navigation_initiator_map_.Set( 1461 frame_navigation_initiator_map_.Set(
(...skipping 30 matching lines...) Expand all
1486 void InspectorNetworkAgent::SetHostId(const String& host_id) { 1492 void InspectorNetworkAgent::SetHostId(const String& host_id) {
1487 host_id_ = host_id; 1493 host_id_ = host_id;
1488 } 1494 }
1489 1495
1490 bool InspectorNetworkAgent::FetchResourceContent(Document* document, 1496 bool InspectorNetworkAgent::FetchResourceContent(Document* document,
1491 const KURL& url, 1497 const KURL& url,
1492 String* content, 1498 String* content,
1493 bool* base64_encoded) { 1499 bool* base64_encoded) {
1494 // First try to fetch content from the cached resource. 1500 // First try to fetch content from the cached resource.
1495 Resource* cached_resource = document->Fetcher()->CachedResource(url); 1501 Resource* cached_resource = document->Fetcher()->CachedResource(url);
1496 if (!cached_resource) 1502 if (!cached_resource && IsMainThread()) {
1497 cached_resource = GetMemoryCache()->ResourceForURL( 1503 cached_resource = GetMemoryCache()->ResourceForURL(
1498 url, document->Fetcher()->GetCacheIdentifier()); 1504 url, document->Fetcher()->GetCacheIdentifier());
1505 }
1499 if (cached_resource && InspectorPageAgent::CachedResourceContent( 1506 if (cached_resource && InspectorPageAgent::CachedResourceContent(
1500 cached_resource, content, base64_encoded)) 1507 cached_resource, content, base64_encoded))
1501 return true; 1508 return true;
1502 1509
1503 // Then fall back to resource data. 1510 // Then fall back to resource data.
1504 for (auto& resource : resources_data_->Resources()) { 1511 for (auto& resource : resources_data_->Resources()) {
1505 if (resource->RequestedURL() == url) { 1512 if (resource->RequestedURL() == url) {
1506 *content = resource->Content(); 1513 *content = resource->Content();
1507 *base64_encoded = resource->Base64Encoded(); 1514 *base64_encoded = resource->Base64Encoded();
1508 return true; 1515 return true;
(...skipping 12 matching lines...) Expand all
1521 replay_xhrs_to_be_deleted_.clear(); 1528 replay_xhrs_to_be_deleted_.clear();
1522 } 1529 }
1523 1530
1524 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) 1531 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames)
1525 : inspected_frames_(inspected_frames), 1532 : inspected_frames_(inspected_frames),
1526 resources_data_( 1533 resources_data_(
1527 NetworkResourcesData::Create(g_maximum_total_buffer_size, 1534 NetworkResourcesData::Create(g_maximum_total_buffer_size,
1528 g_maximum_resource_buffer_size)), 1535 g_maximum_resource_buffer_size)),
1529 pending_request_(nullptr), 1536 pending_request_(nullptr),
1530 remove_finished_replay_xhr_timer_( 1537 remove_finished_replay_xhr_timer_(
1531 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, 1538 inspected_frames
1532 inspected_frames->Root()), 1539 ? new TaskRunnerTimer<InspectorNetworkAgent>(
1533 this, 1540 TaskRunnerHelper::Get(TaskType::kUnspecedLoading,
1534 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} 1541 inspected_frames->Root()),
1542 this,
1543 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired)
1544 : nullptr) {}
1535 1545
1536 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { 1546 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) {
1537 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1547 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false))
1538 *result = true; 1548 *result = true;
1539 } 1549 }
1540 1550
1541 } // namespace blink 1551 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698