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

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

Issue 2900613002: Support DevTools for off-main-thread-fetch (Closed)
Patch Set: 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "core/inspector/ConsoleMessage.h" 44 #include "core/inspector/ConsoleMessage.h"
45 #include "core/inspector/IdentifiersFactory.h" 45 #include "core/inspector/IdentifiersFactory.h"
46 #include "core/inspector/InspectedFrames.h" 46 #include "core/inspector/InspectedFrames.h"
47 #include "core/inspector/NetworkResourcesData.h" 47 #include "core/inspector/NetworkResourcesData.h"
48 #include "core/loader/DocumentLoader.h" 48 #include "core/loader/DocumentLoader.h"
49 #include "core/loader/FrameLoader.h" 49 #include "core/loader/FrameLoader.h"
50 #include "core/loader/MixedContentChecker.h" 50 #include "core/loader/MixedContentChecker.h"
51 #include "core/loader/ThreadableLoaderClient.h" 51 #include "core/loader/ThreadableLoaderClient.h"
52 #include "core/page/Page.h" 52 #include "core/page/Page.h"
53 #include "core/probe/CoreProbes.h" 53 #include "core/probe/CoreProbes.h"
54 #include "core/workers/WorkerGlobalScope.h"
54 #include "core/xmlhttprequest/XMLHttpRequest.h" 55 #include "core/xmlhttprequest/XMLHttpRequest.h"
55 #include "platform/RuntimeEnabledFeatures.h" 56 #include "platform/RuntimeEnabledFeatures.h"
56 #include "platform/blob/BlobData.h" 57 #include "platform/blob/BlobData.h"
57 #include "platform/loader/fetch/FetchInitiatorInfo.h" 58 #include "platform/loader/fetch/FetchInitiatorInfo.h"
58 #include "platform/loader/fetch/FetchInitiatorTypeNames.h" 59 #include "platform/loader/fetch/FetchInitiatorTypeNames.h"
59 #include "platform/loader/fetch/MemoryCache.h" 60 #include "platform/loader/fetch/MemoryCache.h"
60 #include "platform/loader/fetch/Resource.h" 61 #include "platform/loader/fetch/Resource.h"
61 #include "platform/loader/fetch/ResourceError.h" 62 #include "platform/loader/fetch/ResourceError.h"
62 #include "platform/loader/fetch/ResourceFetcher.h" 63 #include "platform/loader/fetch/ResourceFetcher.h"
63 #include "platform/loader/fetch/ResourceLoadTiming.h" 64 #include "platform/loader/fetch/ResourceLoadTiming.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 response_object->setSecurityDetails(std::move(security_details)); 542 response_object->setSecurityDetails(std::move(security_details));
542 } 543 }
543 544
544 return response_object; 545 return response_object;
545 } 546 }
546 547
547 InspectorNetworkAgent::~InspectorNetworkAgent() {} 548 InspectorNetworkAgent::~InspectorNetworkAgent() {}
548 549
549 DEFINE_TRACE(InspectorNetworkAgent) { 550 DEFINE_TRACE(InspectorNetworkAgent) {
550 visitor->Trace(inspected_frames_); 551 visitor->Trace(inspected_frames_);
552 visitor->Trace(worker_global_scope_);
551 visitor->Trace(resources_data_); 553 visitor->Trace(resources_data_);
552 visitor->Trace(replay_xhrs_); 554 visitor->Trace(replay_xhrs_);
553 visitor->Trace(replay_xhrs_to_be_deleted_); 555 visitor->Trace(replay_xhrs_to_be_deleted_);
554 visitor->Trace(pending_xhr_replay_data_); 556 visitor->Trace(pending_xhr_replay_data_);
555 InspectorBaseAgent::Trace(visitor); 557 InspectorBaseAgent::Trace(visitor);
556 } 558 }
557 559
558 void InspectorNetworkAgent::ShouldBlockRequest(const ResourceRequest& request, 560 void InspectorNetworkAgent::ShouldBlockRequest(const ResourceRequest& request,
559 bool* result) { 561 bool* result) {
560 protocol::DictionaryValue* blocked_urls = 562 protocol::DictionaryValue* blocked_urls =
561 state_->getObject(NetworkAgentState::kBlockedURLs); 563 state_->getObject(NetworkAgentState::kBlockedURLs);
562 if (!blocked_urls) 564 if (!blocked_urls)
563 return; 565 return;
564 566
565 String url = request.Url().GetString(); 567 String url = request.Url().GetString();
566 for (size_t i = 0; i < blocked_urls->size(); ++i) { 568 for (size_t i = 0; i < blocked_urls->size(); ++i) {
567 auto entry = blocked_urls->at(i); 569 auto entry = blocked_urls->at(i);
568 if (Matches(url, entry.first)) { 570 if (Matches(url, entry.first)) {
569 *result = true; 571 *result = true;
570 return; 572 return;
571 } 573 }
572 } 574 }
573 return; 575 return;
574 } 576 }
575 577
576 void InspectorNetworkAgent::DidBlockRequest( 578 void InspectorNetworkAgent::DidBlockRequest(
577 LocalFrame* frame,
578 const ResourceRequest& request, 579 const ResourceRequest& request,
579 DocumentLoader* loader, 580 DocumentLoader* loader,
580 const FetchInitiatorInfo& initiator_info, 581 const FetchInitiatorInfo& initiator_info,
581 ResourceRequestBlockedReason reason) { 582 ResourceRequestBlockedReason reason) {
582 unsigned long identifier = CreateUniqueIdentifier(); 583 unsigned long identifier = CreateUniqueIdentifier();
583 WillSendRequestInternal(frame, identifier, loader, request, 584 WillSendRequestInternal(identifier, loader, request, ResourceResponse(),
584 ResourceResponse(), initiator_info); 585 initiator_info);
585 586
586 String request_id = IdentifiersFactory::RequestId(identifier); 587 String request_id = IdentifiersFactory::RequestId(identifier);
587 String protocol_reason = BuildBlockedReason(reason); 588 String protocol_reason = BuildBlockedReason(reason);
588 GetFrontend()->loadingFailed( 589 GetFrontend()->loadingFailed(
589 request_id, MonotonicallyIncreasingTime(), 590 request_id, MonotonicallyIncreasingTime(),
590 InspectorPageAgent::ResourceTypeJson( 591 InspectorPageAgent::ResourceTypeJson(
591 resources_data_->GetResourceType(request_id)), 592 resources_data_->GetResourceType(request_id)),
592 String(), false, protocol_reason); 593 String(), false, protocol_reason);
593 } 594 }
594 595
595 void InspectorNetworkAgent::DidChangeResourcePriority( 596 void InspectorNetworkAgent::DidChangeResourcePriority(
596 unsigned long identifier, 597 unsigned long identifier,
597 ResourceLoadPriority load_priority) { 598 ResourceLoadPriority load_priority) {
598 String request_id = IdentifiersFactory::RequestId(identifier); 599 String request_id = IdentifiersFactory::RequestId(identifier);
599 GetFrontend()->resourceChangedPriority(request_id, 600 GetFrontend()->resourceChangedPriority(request_id,
600 ResourcePriorityJSON(load_priority), 601 ResourcePriorityJSON(load_priority),
601 MonotonicallyIncreasingTime()); 602 MonotonicallyIncreasingTime());
602 } 603 }
603 604
604 void InspectorNetworkAgent::WillSendRequestInternal( 605 void InspectorNetworkAgent::WillSendRequestInternal(
605 LocalFrame* frame,
606 unsigned long identifier, 606 unsigned long identifier,
607 DocumentLoader* loader, 607 DocumentLoader* loader,
608 const ResourceRequest& request, 608 const ResourceRequest& request,
609 const ResourceResponse& redirect_response, 609 const ResourceResponse& redirect_response,
610 const FetchInitiatorInfo& initiator_info) { 610 const FetchInitiatorInfo& initiator_info) {
611 String request_id = IdentifiersFactory::RequestId(identifier); 611 String request_id = IdentifiersFactory::RequestId(identifier);
612 String loader_id = IdentifiersFactory::LoaderId(loader); 612 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : "";
613 resources_data_->ResourceCreated(request_id, loader_id, request.Url()); 613 resources_data_->ResourceCreated(request_id, loader_id, request.Url());
614 614
615 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource; 615 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource;
616 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) { 616 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) {
617 type = InspectorPageAgent::kXHRResource; 617 type = InspectorPageAgent::kXHRResource;
618 resources_data_->SetResourceType(request_id, type); 618 resources_data_->SetResourceType(request_id, type);
619 } else if (initiator_info.name == FetchInitiatorTypeNames::document) { 619 } else if (initiator_info.name == FetchInitiatorTypeNames::document) {
620 type = InspectorPageAgent::kDocumentResource; 620 type = InspectorPageAgent::kDocumentResource;
621 resources_data_->SetResourceType(request_id, type); 621 resources_data_->SetResourceType(request_id, type);
622 } 622 }
623 623
624 String frame_id = 624 String frame_id = loader && loader->GetFrame()
625 loader->GetFrame() ? IdentifiersFactory::FrameId(loader->GetFrame()) : ""; 625 ? IdentifiersFactory::FrameId(loader->GetFrame())
626 : "";
626 std::unique_ptr<protocol::Network::Initiator> initiator_object = 627 std::unique_ptr<protocol::Network::Initiator> initiator_object =
627 BuildInitiatorObject( 628 BuildInitiatorObject(
628 loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, 629 loader && loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0,
629 initiator_info); 630 initiator_info);
630 if (initiator_info.name == FetchInitiatorTypeNames::document) { 631 if (initiator_info.name == FetchInitiatorTypeNames::document) {
631 FrameNavigationInitiatorMap::iterator it = 632 FrameNavigationInitiatorMap::iterator it =
632 frame_navigation_initiator_map_.find(frame_id); 633 frame_navigation_initiator_map_.find(frame_id);
633 if (it != frame_navigation_initiator_map_.end()) 634 if (it != frame_navigation_initiator_map_.end())
634 initiator_object = it->value->clone(); 635 initiator_object = it->value->clone();
635 } 636 }
636 637
637 std::unique_ptr<protocol::Network::Request> request_info( 638 std::unique_ptr<protocol::Network::Request> request_info(
638 BuildObjectForResourceRequest(request)); 639 BuildObjectForResourceRequest(request));
639 640
640 request_info->setMixedContentType(MixedContentTypeForContextType( 641 // |loader| is null while inspecting worker if off-main-thread-fetch is
641 MixedContentChecker::ContextTypeForInspector(frame, request))); 642 // enabled. TODO(horo): Refactor MixedContentChecker and set mixed content
643 // type even if |loader| is null.
644 if (loader) {
645 request_info->setMixedContentType(MixedContentTypeForContextType(
646 MixedContentChecker::ContextTypeForInspector(loader->GetFrame(),
647 request)));
648 }
642 649
643 request_info->setReferrerPolicy( 650 request_info->setReferrerPolicy(
644 GetReferrerPolicy(request.GetReferrerPolicy())); 651 GetReferrerPolicy(request.GetReferrerPolicy()));
645 if (initiator_info.is_link_preload) 652 if (initiator_info.is_link_preload)
646 request_info->setIsLinkPreload(true); 653 request_info->setIsLinkPreload(true);
647 654
648 String resource_type = InspectorPageAgent::ResourceTypeJson(type); 655 String resource_type = InspectorPageAgent::ResourceTypeJson(type);
649 GetFrontend()->requestWillBeSent( 656 GetFrontend()->requestWillBeSent(
650 request_id, frame_id, loader_id, 657 request_id, frame_id, loader_id,
651 UrlWithoutFragment(loader->Url()).GetString(), std::move(request_info), 658 loader ? UrlWithoutFragment(loader->Url()).GetString() : "",
652 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), 659 std::move(request_info), MonotonicallyIncreasingTime(), CurrentTime(),
660 std::move(initiator_object),
653 BuildObjectForResourceResponse(redirect_response), resource_type); 661 BuildObjectForResourceResponse(redirect_response), resource_type);
654 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) 662 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async())
655 GetFrontend()->flush(); 663 GetFrontend()->flush();
656 } 664 }
657 665
658 void InspectorNetworkAgent::WillSendRequest( 666 void InspectorNetworkAgent::WillSendRequest(
659 LocalFrame* frame,
660 unsigned long identifier, 667 unsigned long identifier,
661 DocumentLoader* loader, 668 DocumentLoader* loader,
662 ResourceRequest& request, 669 ResourceRequest& request,
663 const ResourceResponse& redirect_response, 670 const ResourceResponse& redirect_response,
664 const FetchInitiatorInfo& initiator_info) { 671 const FetchInitiatorInfo& initiator_info) {
665 // Ignore the request initiated internally. 672 // Ignore the request initiated internally.
666 if (initiator_info.name == FetchInitiatorTypeNames::internal) 673 if (initiator_info.name == FetchInitiatorTypeNames::internal)
667 return; 674 return;
668 675
669 if (initiator_info.name == FetchInitiatorTypeNames::document && 676 if (initiator_info.name == FetchInitiatorTypeNames::document &&
(...skipping 19 matching lines...) Expand all
689 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { 696 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) {
690 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); 697 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache);
691 } else { 698 } else {
692 request.SetCachePolicy(WebCachePolicy::kBypassingCache); 699 request.SetCachePolicy(WebCachePolicy::kBypassingCache);
693 } 700 }
694 request.SetShouldResetAppCache(true); 701 request.SetShouldResetAppCache(true);
695 } 702 }
696 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) 703 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false))
697 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); 704 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone);
698 705
699 WillSendRequestInternal(frame, identifier, loader, request, redirect_response, 706 WillSendRequestInternal(identifier, loader, request, redirect_response,
700 initiator_info); 707 initiator_info);
701 708
702 if (!host_id_.IsEmpty()) 709 if (!host_id_.IsEmpty())
703 request.AddHTTPHeaderField( 710 request.AddHTTPHeaderField(
704 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, 711 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id,
705 AtomicString(host_id_)); 712 AtomicString(host_id_));
706 } 713 }
707 714
708 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { 715 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) {
709 GetFrontend()->requestServedFromCache( 716 GetFrontend()->requestServedFromCache(
710 IdentifiersFactory::RequestId(identifier)); 717 IdentifiersFactory::RequestId(identifier));
711 } 718 }
712 719
713 void InspectorNetworkAgent::DidReceiveResourceResponse( 720 void InspectorNetworkAgent::DidReceiveResourceResponse(
714 LocalFrame* frame,
715 unsigned long identifier, 721 unsigned long identifier,
716 DocumentLoader* loader, 722 DocumentLoader* loader,
717 const ResourceResponse& response, 723 const ResourceResponse& response,
718 Resource* cached_resource) { 724 Resource* cached_resource) {
719 String request_id = IdentifiersFactory::RequestId(identifier); 725 String request_id = IdentifiersFactory::RequestId(identifier);
720 bool is_not_modified = response.HttpStatusCode() == 304; 726 bool is_not_modified = response.HttpStatusCode() == 304;
721 727
722 bool resource_is_empty = true; 728 bool resource_is_empty = true;
723 std::unique_ptr<protocol::Network::Response> resource_response = 729 std::unique_ptr<protocol::Network::Response> resource_response =
724 BuildObjectForResourceResponse(response, cached_resource, 730 BuildObjectForResourceResponse(response, cached_resource,
(...skipping 15 matching lines...) Expand all
740 if (type == InspectorPageAgent::kDocumentResource && loader && 746 if (type == InspectorPageAgent::kDocumentResource && loader &&
741 loader->GetSubstituteData().IsValid()) 747 loader->GetSubstituteData().IsValid())
742 return; 748 return;
743 749
744 // Resources are added to NetworkResourcesData as a WeakMember here and 750 // Resources are added to NetworkResourcesData as a WeakMember here and
745 // removed in willDestroyResource() called in the prefinalizer of Resource. 751 // removed in willDestroyResource() called in the prefinalizer of Resource.
746 // Because NetworkResourceData retains weak references only, it 752 // Because NetworkResourceData retains weak references only, it
747 // doesn't affect Resource lifetime. 753 // doesn't affect Resource lifetime.
748 if (cached_resource) 754 if (cached_resource)
749 resources_data_->AddResource(request_id, cached_resource); 755 resources_data_->AddResource(request_id, cached_resource);
750 String frame_id = IdentifiersFactory::FrameId(frame); 756 String frame_id = loader && loader->GetFrame()
757 ? IdentifiersFactory::FrameId(loader->GetFrame())
758 : "";
751 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; 759 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : "";
752 resources_data_->ResponseReceived(request_id, frame_id, response); 760 resources_data_->ResponseReceived(request_id, frame_id, response);
753 resources_data_->SetResourceType(request_id, type); 761 resources_data_->SetResourceType(request_id, type);
754 762
755 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && 763 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown &&
756 response.GetSecurityStyle() != 764 response.GetSecurityStyle() !=
757 ResourceResponse::kSecurityStyleUnauthenticated) { 765 ResourceResponse::kSecurityStyleUnauthenticated) {
758 const ResourceResponse::SecurityDetails* response_security_details = 766 const ResourceResponse::SecurityDetails* response_security_details =
759 response.GetSecurityDetails(); 767 response.GetSecurityDetails();
760 resources_data_->SetCertificate(request_id, 768 resources_data_->SetCertificate(request_id,
761 response_security_details->certificate); 769 response_security_details->certificate);
762 } 770 }
763 771
764 if (resource_response && !resource_is_empty) 772 if (resource_response && !resource_is_empty)
765 GetFrontend()->responseReceived(request_id, frame_id, loader_id, 773 GetFrontend()->responseReceived(request_id, frame_id, loader_id,
766 MonotonicallyIncreasingTime(), 774 MonotonicallyIncreasingTime(),
767 InspectorPageAgent::ResourceTypeJson(type), 775 InspectorPageAgent::ResourceTypeJson(type),
768 std::move(resource_response)); 776 std::move(resource_response));
769 // 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
770 // following didReceiveResponse as there will be no calls to didReceiveData 778 // following didReceiveResponse as there will be no calls to didReceiveData
771 // from the network stack. 779 // from the network stack.
772 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) 780 if (is_not_modified && cached_resource && cached_resource->EncodedSize())
773 DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); 781 DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize());
774 } 782 }
775 783
776 static bool IsErrorStatusCode(int status_code) { 784 static bool IsErrorStatusCode(int status_code) {
777 return status_code >= 400; 785 return status_code >= 400;
778 } 786 }
779 787
780 void InspectorNetworkAgent::DidReceiveData(LocalFrame*, 788 void InspectorNetworkAgent::DidReceiveData(unsigned long identifier,
781 unsigned long identifier, 789 DocumentLoader* loader,
782 const char* data, 790 const char* data,
783 int data_length) { 791 int data_length) {
784 String request_id = IdentifiersFactory::RequestId(identifier); 792 String request_id = IdentifiersFactory::RequestId(identifier);
785 793
786 if (data) { 794 if (data) {
787 NetworkResourcesData::ResourceData const* resource_data = 795 NetworkResourcesData::ResourceData const* resource_data =
788 resources_data_->Data(request_id); 796 resources_data_->Data(request_id);
789 if (resource_data && 797 if (resource_data &&
790 (!resource_data->CachedResource() || 798 (!resource_data->CachedResource() ||
791 resource_data->CachedResource()->GetDataBufferingPolicy() == 799 resource_data->CachedResource()->GetDataBufferingPolicy() ==
792 kDoNotBufferData || 800 kDoNotBufferData ||
793 IsErrorStatusCode(resource_data->HttpStatusCode()))) 801 IsErrorStatusCode(resource_data->HttpStatusCode())))
794 resources_data_->MaybeAddResourceData(request_id, data, data_length); 802 resources_data_->MaybeAddResourceData(request_id, data, data_length);
795 } 803 }
796 804
797 GetFrontend()->dataReceived( 805 GetFrontend()->dataReceived(
798 request_id, MonotonicallyIncreasingTime(), data_length, 806 request_id, MonotonicallyIncreasingTime(), data_length,
799 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); 807 resources_data_->GetAndClearPendingEncodedDataLength(request_id));
800 } 808 }
801 809
802 void InspectorNetworkAgent::DidReceiveEncodedDataLength( 810 void InspectorNetworkAgent::DidReceiveEncodedDataLength(
803 LocalFrame*,
804 unsigned long identifier, 811 unsigned long identifier,
805 int encoded_data_length) { 812 int encoded_data_length) {
806 String request_id = IdentifiersFactory::RequestId(identifier); 813 String request_id = IdentifiersFactory::RequestId(identifier);
807 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); 814 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length);
808 } 815 }
809 816
810 void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, 817 void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier,
811 unsigned long identifier, 818 DocumentLoader*,
812 double monotonic_finish_time, 819 double monotonic_finish_time,
813 int64_t encoded_data_length, 820 int64_t encoded_data_length,
814 int64_t decoded_body_length) { 821 int64_t decoded_body_length) {
815 String request_id = IdentifiersFactory::RequestId(identifier); 822 String request_id = IdentifiersFactory::RequestId(identifier);
816 NetworkResourcesData::ResourceData const* resource_data = 823 NetworkResourcesData::ResourceData const* resource_data =
817 resources_data_->Data(request_id); 824 resources_data_->Data(request_id);
818 825
819 int pending_encoded_data_length = 826 int pending_encoded_data_length =
820 resources_data_->GetAndClearPendingEncodedDataLength(request_id); 827 resources_data_->GetAndClearPendingEncodedDataLength(request_id);
821 if (pending_encoded_data_length > 0) { 828 if (pending_encoded_data_length > 0) {
(...skipping 16 matching lines...) Expand all
838 encoded_data_length); 845 encoded_data_length);
839 } 846 }
840 847
841 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( 848 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse(
842 LocalFrame* frame, 849 LocalFrame* frame,
843 unsigned long identifier, 850 unsigned long identifier,
844 DocumentLoader* loader, 851 DocumentLoader* loader,
845 const ResourceResponse& response, 852 const ResourceResponse& response,
846 Resource* resource) { 853 Resource* resource) {
847 // Update the response and finish loading 854 // Update the response and finish loading
848 DidReceiveResourceResponse(frame, identifier, loader, response, resource); 855 DidReceiveResourceResponse(identifier, loader, response, resource);
849 DidFinishLoading(frame, identifier, 0, 856 DidFinishLoading(identifier, loader, 0,
850 WebURLLoaderClient::kUnknownEncodedDataLength, 0); 857 WebURLLoaderClient::kUnknownEncodedDataLength, 0);
851 } 858 }
852 859
853 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, 860 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier,
854 const ResourceError& error) { 861 const ResourceError& error) {
855 String request_id = IdentifiersFactory::RequestId(identifier); 862 String request_id = IdentifiersFactory::RequestId(identifier);
856 bool canceled = error.IsCancellation(); 863 bool canceled = error.IsCancellation();
857 GetFrontend()->loadingFailed( 864 GetFrontend()->loadingFailed(
858 request_id, MonotonicallyIncreasingTime(), 865 request_id, MonotonicallyIncreasingTime(),
859 InspectorPageAgent::ResourceTypeJson( 866 InspectorPageAgent::ResourceTypeJson(
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 return Response::OK(); 1248 return Response::OK();
1242 } 1249 }
1243 1250
1244 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) { 1251 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) {
1245 NetworkResourcesData::ResourceData const* resource_data = 1252 NetworkResourcesData::ResourceData const* resource_data =
1246 resources_data_->Data(request_id); 1253 resources_data_->Data(request_id);
1247 BlobDataHandle* blob = 1254 BlobDataHandle* blob =
1248 resource_data ? resource_data->DownloadedFileBlob() : nullptr; 1255 resource_data ? resource_data->DownloadedFileBlob() : nullptr;
1249 if (!blob) 1256 if (!blob)
1250 return false; 1257 return false;
1258 if (worker_global_scope_)
1259 return true;
1251 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, 1260 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_,
1252 resource_data->FrameId()); 1261 resource_data->FrameId());
1253 return frame && frame->GetDocument(); 1262 return frame && frame->GetDocument();
1254 } 1263 }
1255 1264
1256 void InspectorNetworkAgent::GetResponseBodyBlob( 1265 void InspectorNetworkAgent::GetResponseBodyBlob(
1257 const String& request_id, 1266 const String& request_id,
1258 std::unique_ptr<GetResponseBodyCallback> callback) { 1267 std::unique_ptr<GetResponseBodyCallback> callback) {
1259 NetworkResourcesData::ResourceData const* resource_data = 1268 NetworkResourcesData::ResourceData const* resource_data =
1260 resources_data_->Data(request_id); 1269 resources_data_->Data(request_id);
1261 BlobDataHandle* blob = resource_data->DownloadedFileBlob(); 1270 BlobDataHandle* blob = resource_data->DownloadedFileBlob();
1271 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient(
1272 blob, resource_data->MimeType(), resource_data->TextEncodingName(),
1273 std::move(callback));
1274 if (worker_global_scope_) {
1275 client->Start(worker_global_scope_);
1276 return;
1277 }
1278 DCHECK(inspected_frames_);
1262 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, 1279 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_,
1263 resource_data->FrameId()); 1280 resource_data->FrameId());
1264 Document* document = frame->GetDocument(); 1281 Document* document = frame->GetDocument();
1265 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient(
1266 blob, resource_data->MimeType(), resource_data->TextEncodingName(),
1267 std::move(callback));
1268 client->Start(document); 1282 client->Start(document);
1269 } 1283 }
1270 1284
1271 void InspectorNetworkAgent::getResponseBody( 1285 void InspectorNetworkAgent::getResponseBody(
1272 const String& request_id, 1286 const String& request_id,
1273 std::unique_ptr<GetResponseBodyCallback> pass_callback) { 1287 std::unique_ptr<GetResponseBodyCallback> pass_callback) {
1274 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback); 1288 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback);
1275 NetworkResourcesData::ResourceData const* resource_data = 1289 NetworkResourcesData::ResourceData const* resource_data =
1276 resources_data_->Data(request_id); 1290 resources_data_->Data(request_id);
1277 if (!resource_data) { 1291 if (!resource_data) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 else 1408 else
1395 GetNetworkStateNotifier().ClearOverride(); 1409 GetNetworkStateNotifier().ClearOverride();
1396 return Response::OK(); 1410 return Response::OK();
1397 } 1411 }
1398 1412
1399 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { 1413 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) {
1400 // TODO(ananta) 1414 // TODO(ananta)
1401 // 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
1402 // queried from FrameLoader and other places. 1416 // queried from FrameLoader and other places.
1403 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); 1417 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled);
1404 if (cache_disabled) 1418 if (cache_disabled && IsMainThread())
1405 GetMemoryCache()->EvictResources(); 1419 GetMemoryCache()->EvictResources();
1406 return Response::OK(); 1420 return Response::OK();
1407 } 1421 }
1408 1422
1409 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { 1423 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) {
1410 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); 1424 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass);
1411 return Response::OK(); 1425 return Response::OK();
1412 } 1426 }
1413 1427
1414 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, 1428 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total,
(...skipping 16 matching lines...) Expand all
1431 for (auto& cert : resource->Certificate()) 1445 for (auto& cert : resource->Certificate())
1432 certificate->get()->addItem(Base64Encode(cert.Latin1())); 1446 certificate->get()->addItem(Base64Encode(cert.Latin1()));
1433 return Response::OK(); 1447 return Response::OK();
1434 } 1448 }
1435 } 1449 }
1436 return Response::OK(); 1450 return Response::OK();
1437 } 1451 }
1438 1452
1439 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, 1453 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame,
1440 DocumentLoader* loader) { 1454 DocumentLoader* loader) {
1455 DCHECK(inspected_frames_);
1441 if (loader->GetFrame() != inspected_frames_->Root()) 1456 if (loader->GetFrame() != inspected_frames_->Root())
1442 return; 1457 return;
1443 1458
1444 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1459 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false) &&
1460 IsMainThread()) {
kinuko 2017/05/22 06:53:40 DCHECK(IsMainThread()) seems fine
horo 2017/05/22 07:32:17 Done.
1445 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); 1461 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads);
1462 }
1446 1463
1447 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); 1464 resources_data_->Clear(IdentifiersFactory::LoaderId(loader));
1448 } 1465 }
1449 1466
1450 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, 1467 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame,
1451 double) { 1468 double) {
1452 String frame_id = IdentifiersFactory::FrameId(frame); 1469 String frame_id = IdentifiersFactory::FrameId(frame);
1453 frames_with_scheduled_navigation_.insert(frame_id); 1470 frames_with_scheduled_navigation_.insert(frame_id);
1454 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) { 1471 if (!frames_with_scheduled_client_navigation_.Contains(frame_id)) {
1455 frame_navigation_initiator_map_.Set( 1472 frame_navigation_initiator_map_.Set(
(...skipping 30 matching lines...) Expand all
1486 void InspectorNetworkAgent::SetHostId(const String& host_id) { 1503 void InspectorNetworkAgent::SetHostId(const String& host_id) {
1487 host_id_ = host_id; 1504 host_id_ = host_id;
1488 } 1505 }
1489 1506
1490 bool InspectorNetworkAgent::FetchResourceContent(Document* document, 1507 bool InspectorNetworkAgent::FetchResourceContent(Document* document,
1491 const KURL& url, 1508 const KURL& url,
1492 String* content, 1509 String* content,
1493 bool* base64_encoded) { 1510 bool* base64_encoded) {
1494 // First try to fetch content from the cached resource. 1511 // First try to fetch content from the cached resource.
1495 Resource* cached_resource = document->Fetcher()->CachedResource(url); 1512 Resource* cached_resource = document->Fetcher()->CachedResource(url);
1496 if (!cached_resource) 1513 if (!cached_resource && IsMainThread()) {
kinuko 2017/05/22 06:53:40 This seems to be only called for document case (fo
horo 2017/05/22 07:32:17 Done.
1497 cached_resource = GetMemoryCache()->ResourceForURL( 1514 cached_resource = GetMemoryCache()->ResourceForURL(
1498 url, document->Fetcher()->GetCacheIdentifier()); 1515 url, document->Fetcher()->GetCacheIdentifier());
1516 }
1499 if (cached_resource && InspectorPageAgent::CachedResourceContent( 1517 if (cached_resource && InspectorPageAgent::CachedResourceContent(
1500 cached_resource, content, base64_encoded)) 1518 cached_resource, content, base64_encoded))
1501 return true; 1519 return true;
1502 1520
1503 // Then fall back to resource data. 1521 // Then fall back to resource data.
1504 for (auto& resource : resources_data_->Resources()) { 1522 for (auto& resource : resources_data_->Resources()) {
1505 if (resource->RequestedURL() == url) { 1523 if (resource->RequestedURL() == url) {
1506 *content = resource->Content(); 1524 *content = resource->Content();
1507 *base64_encoded = resource->Base64Encoded(); 1525 *base64_encoded = resource->Base64Encoded();
1508 return true; 1526 return true;
1509 } 1527 }
1510 } 1528 }
1511 return false; 1529 return false;
1512 } 1530 }
1513 1531
1514 bool InspectorNetworkAgent::CacheDisabled() { 1532 bool InspectorNetworkAgent::CacheDisabled() {
1515 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled, 1533 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled,
1516 false) && 1534 false) &&
1517 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false); 1535 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false);
1518 } 1536 }
1519 1537
1520 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) { 1538 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) {
1521 replay_xhrs_to_be_deleted_.clear(); 1539 replay_xhrs_to_be_deleted_.clear();
1522 } 1540 }
1523 1541
1524 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) 1542 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames)
1525 : inspected_frames_(inspected_frames), 1543 : inspected_frames_(inspected_frames),
1544 worker_global_scope_(nullptr),
1526 resources_data_( 1545 resources_data_(
1527 NetworkResourcesData::Create(g_maximum_total_buffer_size, 1546 NetworkResourcesData::Create(g_maximum_total_buffer_size,
1528 g_maximum_resource_buffer_size)), 1547 g_maximum_resource_buffer_size)),
1529 pending_request_(nullptr), 1548 pending_request_(nullptr),
1530 remove_finished_replay_xhr_timer_( 1549 remove_finished_replay_xhr_timer_(
1531 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, 1550 TaskRunnerHelper::Get(TaskType::kUnspecedLoading,
1532 inspected_frames->Root()), 1551 inspected_frames->Root()),
1533 this, 1552 this,
1534 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} 1553 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {
1554 DCHECK(IsMainThread());
1555 }
1556
1557 InspectorNetworkAgent::InspectorNetworkAgent(
1558 WorkerGlobalScope* worker_global_scope)
1559 : inspected_frames_(nullptr),
1560 worker_global_scope_(worker_global_scope),
1561 resources_data_(
1562 NetworkResourcesData::Create(g_maximum_total_buffer_size,
1563 g_maximum_resource_buffer_size)),
1564 pending_request_(nullptr),
1565 remove_finished_replay_xhr_timer_(
1566 TaskRunnerHelper::Get(TaskType::kUnspecedLoading,
1567 worker_global_scope),
1568 this,
1569 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {
1570 DCHECK(!IsMainThread());
1571 }
1535 1572
1536 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { 1573 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) {
1537 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1574 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false))
1538 *result = true; 1575 *result = true;
1539 } 1576 }
1540 1577
1541 } // namespace blink 1578 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698