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

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

Issue 2900613002: Support DevTools for off-main-thread-fetch (Closed)
Patch Set: rebase Created 3 years, 5 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 response_object->setSecurityDetails(std::move(security_details)); 546 response_object->setSecurityDetails(std::move(security_details));
546 } 547 }
547 548
548 return response_object; 549 return response_object;
549 } 550 }
550 551
551 InspectorNetworkAgent::~InspectorNetworkAgent() {} 552 InspectorNetworkAgent::~InspectorNetworkAgent() {}
552 553
553 DEFINE_TRACE(InspectorNetworkAgent) { 554 DEFINE_TRACE(InspectorNetworkAgent) {
554 visitor->Trace(inspected_frames_); 555 visitor->Trace(inspected_frames_);
556 visitor->Trace(worker_global_scope_);
555 visitor->Trace(resources_data_); 557 visitor->Trace(resources_data_);
556 visitor->Trace(replay_xhrs_); 558 visitor->Trace(replay_xhrs_);
557 visitor->Trace(replay_xhrs_to_be_deleted_); 559 visitor->Trace(replay_xhrs_to_be_deleted_);
558 visitor->Trace(pending_xhr_replay_data_); 560 visitor->Trace(pending_xhr_replay_data_);
559 InspectorBaseAgent::Trace(visitor); 561 InspectorBaseAgent::Trace(visitor);
560 } 562 }
561 563
562 void InspectorNetworkAgent::ShouldBlockRequest(const ResourceRequest& request, 564 void InspectorNetworkAgent::ShouldBlockRequest(const ResourceRequest& request,
563 bool* result) { 565 bool* result) {
564 protocol::DictionaryValue* blocked_urls = 566 protocol::DictionaryValue* blocked_urls =
565 state_->getObject(NetworkAgentState::kBlockedURLs); 567 state_->getObject(NetworkAgentState::kBlockedURLs);
566 if (!blocked_urls) 568 if (!blocked_urls)
567 return; 569 return;
568 570
569 String url = request.Url().GetString(); 571 String url = request.Url().GetString();
570 for (size_t i = 0; i < blocked_urls->size(); ++i) { 572 for (size_t i = 0; i < blocked_urls->size(); ++i) {
571 auto entry = blocked_urls->at(i); 573 auto entry = blocked_urls->at(i);
572 if (Matches(url, entry.first)) { 574 if (Matches(url, entry.first)) {
573 *result = true; 575 *result = true;
574 return; 576 return;
575 } 577 }
576 } 578 }
577 return; 579 return;
578 } 580 }
579 581
580 void InspectorNetworkAgent::DidBlockRequest( 582 void InspectorNetworkAgent::DidBlockRequest(
581 LocalFrame* frame, 583 ExecutionContext* execution_context,
582 const ResourceRequest& request, 584 const ResourceRequest& request,
583 DocumentLoader* loader, 585 DocumentLoader* loader,
584 const FetchInitiatorInfo& initiator_info, 586 const FetchInitiatorInfo& initiator_info,
585 ResourceRequestBlockedReason reason) { 587 ResourceRequestBlockedReason reason) {
586 unsigned long identifier = CreateUniqueIdentifier(); 588 unsigned long identifier = CreateUniqueIdentifier();
587 WillSendRequestInternal(frame, identifier, loader, request, 589 WillSendRequestInternal(execution_context, identifier, loader, request,
588 ResourceResponse(), initiator_info); 590 ResourceResponse(), initiator_info);
589 591
590 String request_id = IdentifiersFactory::RequestId(identifier); 592 String request_id = IdentifiersFactory::RequestId(identifier);
591 String protocol_reason = BuildBlockedReason(reason); 593 String protocol_reason = BuildBlockedReason(reason);
592 GetFrontend()->loadingFailed( 594 GetFrontend()->loadingFailed(
593 request_id, MonotonicallyIncreasingTime(), 595 request_id, MonotonicallyIncreasingTime(),
594 InspectorPageAgent::ResourceTypeJson( 596 InspectorPageAgent::ResourceTypeJson(
595 resources_data_->GetResourceType(request_id)), 597 resources_data_->GetResourceType(request_id)),
596 String(), false, protocol_reason); 598 String(), false, protocol_reason);
597 } 599 }
598 600
599 void InspectorNetworkAgent::DidChangeResourcePriority( 601 void InspectorNetworkAgent::DidChangeResourcePriority(
600 unsigned long identifier, 602 unsigned long identifier,
601 ResourceLoadPriority load_priority) { 603 ResourceLoadPriority load_priority) {
602 String request_id = IdentifiersFactory::RequestId(identifier); 604 String request_id = IdentifiersFactory::RequestId(identifier);
603 GetFrontend()->resourceChangedPriority(request_id, 605 GetFrontend()->resourceChangedPriority(request_id,
604 ResourcePriorityJSON(load_priority), 606 ResourcePriorityJSON(load_priority),
605 MonotonicallyIncreasingTime()); 607 MonotonicallyIncreasingTime());
606 } 608 }
607 609
608 void InspectorNetworkAgent::WillSendRequestInternal( 610 void InspectorNetworkAgent::WillSendRequestInternal(
609 LocalFrame* frame, 611 ExecutionContext* execution_context,
610 unsigned long identifier, 612 unsigned long identifier,
611 DocumentLoader* loader, 613 DocumentLoader* loader,
612 const ResourceRequest& request, 614 const ResourceRequest& request,
613 const ResourceResponse& redirect_response, 615 const ResourceResponse& redirect_response,
614 const FetchInitiatorInfo& initiator_info) { 616 const FetchInitiatorInfo& initiator_info) {
615 String request_id = IdentifiersFactory::RequestId(identifier); 617 String request_id = IdentifiersFactory::RequestId(identifier);
616 String loader_id = IdentifiersFactory::LoaderId(loader); 618 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : "";
617 resources_data_->ResourceCreated(request_id, loader_id, request.Url()); 619 resources_data_->ResourceCreated(request_id, loader_id, request.Url());
618 620
619 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource; 621 InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource;
620 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) { 622 if (initiator_info.name == FetchInitiatorTypeNames::xmlhttprequest) {
621 type = InspectorPageAgent::kXHRResource; 623 type = InspectorPageAgent::kXHRResource;
622 resources_data_->SetResourceType(request_id, type); 624 resources_data_->SetResourceType(request_id, type);
623 } else if (initiator_info.name == FetchInitiatorTypeNames::document) { 625 } else if (initiator_info.name == FetchInitiatorTypeNames::document) {
624 type = InspectorPageAgent::kDocumentResource; 626 type = InspectorPageAgent::kDocumentResource;
625 resources_data_->SetResourceType(request_id, type); 627 resources_data_->SetResourceType(request_id, type);
626 } 628 }
627 629
628 String frame_id = 630 String frame_id = loader && loader->GetFrame()
629 loader->GetFrame() ? IdentifiersFactory::FrameId(loader->GetFrame()) : ""; 631 ? IdentifiersFactory::FrameId(loader->GetFrame())
632 : "";
630 std::unique_ptr<protocol::Network::Initiator> initiator_object = 633 std::unique_ptr<protocol::Network::Initiator> initiator_object =
631 BuildInitiatorObject( 634 BuildInitiatorObject(loader && loader->GetFrame()
632 loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, 635 ? loader->GetFrame()->GetDocument()
633 initiator_info); 636 : nullptr,
637 initiator_info);
634 if (initiator_info.name == FetchInitiatorTypeNames::document) { 638 if (initiator_info.name == FetchInitiatorTypeNames::document) {
635 FrameNavigationInitiatorMap::iterator it = 639 FrameNavigationInitiatorMap::iterator it =
636 frame_navigation_initiator_map_.find(frame_id); 640 frame_navigation_initiator_map_.find(frame_id);
637 if (it != frame_navigation_initiator_map_.end()) 641 if (it != frame_navigation_initiator_map_.end())
638 initiator_object = it->value->clone(); 642 initiator_object = it->value->clone();
639 } 643 }
640 644
641 std::unique_ptr<protocol::Network::Request> request_info( 645 std::unique_ptr<protocol::Network::Request> request_info(
642 BuildObjectForResourceRequest(request)); 646 BuildObjectForResourceRequest(request));
643 647
644 request_info->setMixedContentType(MixedContentTypeForContextType( 648 // |loader| is null while inspecting worker if off-main-thread-fetch is
645 MixedContentChecker::ContextTypeForInspector(frame, request))); 649 // enabled. TODO(horo): Refactor MixedContentChecker and set mixed content
650 // type even if |loader| is null.
651 if (loader) {
652 request_info->setMixedContentType(MixedContentTypeForContextType(
653 MixedContentChecker::ContextTypeForInspector(loader->GetFrame(),
654 request)));
655 }
646 656
647 request_info->setReferrerPolicy( 657 request_info->setReferrerPolicy(
648 GetReferrerPolicy(request.GetReferrerPolicy())); 658 GetReferrerPolicy(request.GetReferrerPolicy()));
649 if (initiator_info.is_link_preload) 659 if (initiator_info.is_link_preload)
650 request_info->setIsLinkPreload(true); 660 request_info->setIsLinkPreload(true);
651 661
652 String resource_type = InspectorPageAgent::ResourceTypeJson(type); 662 String resource_type = InspectorPageAgent::ResourceTypeJson(type);
663 String documentURL =
664 loader ? UrlWithoutFragment(loader->Url()).GetString()
665 : UrlWithoutFragment(execution_context->Url()).GetString();
666 Maybe<String> maybe_frame_id;
667 if (!frame_id.IsEmpty())
668 maybe_frame_id = frame_id;
653 GetFrontend()->requestWillBeSent( 669 GetFrontend()->requestWillBeSent(
654 request_id, frame_id, loader_id, 670 request_id, loader_id, documentURL, std::move(request_info),
655 UrlWithoutFragment(loader->Url()).GetString(), std::move(request_info),
656 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), 671 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object),
657 BuildObjectForResourceResponse(redirect_response), resource_type); 672 BuildObjectForResourceResponse(redirect_response), resource_type,
673 std::move(maybe_frame_id));
658 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) 674 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async())
659 GetFrontend()->flush(); 675 GetFrontend()->flush();
660 } 676 }
661 677
662 void InspectorNetworkAgent::WillSendRequest( 678 void InspectorNetworkAgent::WillSendRequest(
663 LocalFrame* frame, 679 ExecutionContext* execution_context,
664 unsigned long identifier, 680 unsigned long identifier,
665 DocumentLoader* loader, 681 DocumentLoader* loader,
666 ResourceRequest& request, 682 ResourceRequest& request,
667 const ResourceResponse& redirect_response, 683 const ResourceResponse& redirect_response,
668 const FetchInitiatorInfo& initiator_info) { 684 const FetchInitiatorInfo& initiator_info) {
669 // Ignore the request initiated internally. 685 // Ignore the request initiated internally.
670 if (initiator_info.name == FetchInitiatorTypeNames::internal) 686 if (initiator_info.name == FetchInitiatorTypeNames::internal)
671 return; 687 return;
672 688
673 if (initiator_info.name == FetchInitiatorTypeNames::document && 689 if (initiator_info.name == FetchInitiatorTypeNames::document &&
(...skipping 19 matching lines...) Expand all
693 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { 709 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) {
694 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); 710 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache);
695 } else { 711 } else {
696 request.SetCachePolicy(WebCachePolicy::kBypassingCache); 712 request.SetCachePolicy(WebCachePolicy::kBypassingCache);
697 } 713 }
698 request.SetShouldResetAppCache(true); 714 request.SetShouldResetAppCache(true);
699 } 715 }
700 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) 716 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false))
701 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); 717 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone);
702 718
703 WillSendRequestInternal(frame, identifier, loader, request, redirect_response, 719 WillSendRequestInternal(execution_context, identifier, loader, request,
704 initiator_info); 720 redirect_response, initiator_info);
705 721
706 if (!host_id_.IsEmpty()) 722 if (!host_id_.IsEmpty())
707 request.AddHTTPHeaderField( 723 request.AddHTTPHeaderField(
708 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, 724 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id,
709 AtomicString(host_id_)); 725 AtomicString(host_id_));
710 } 726 }
711 727
712 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { 728 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) {
713 GetFrontend()->requestServedFromCache( 729 GetFrontend()->requestServedFromCache(
714 IdentifiersFactory::RequestId(identifier)); 730 IdentifiersFactory::RequestId(identifier));
715 } 731 }
716 732
717 void InspectorNetworkAgent::DidReceiveResourceResponse( 733 void InspectorNetworkAgent::DidReceiveResourceResponse(
718 LocalFrame* frame,
719 unsigned long identifier, 734 unsigned long identifier,
720 DocumentLoader* loader, 735 DocumentLoader* loader,
721 const ResourceResponse& response, 736 const ResourceResponse& response,
722 Resource* cached_resource) { 737 Resource* cached_resource) {
723 String request_id = IdentifiersFactory::RequestId(identifier); 738 String request_id = IdentifiersFactory::RequestId(identifier);
724 bool is_not_modified = response.HttpStatusCode() == 304; 739 bool is_not_modified = response.HttpStatusCode() == 304;
725 740
726 bool resource_is_empty = true; 741 bool resource_is_empty = true;
727 std::unique_ptr<protocol::Network::Response> resource_response = 742 std::unique_ptr<protocol::Network::Response> resource_response =
728 BuildObjectForResourceResponse(response, cached_resource, 743 BuildObjectForResourceResponse(response, cached_resource,
(...skipping 15 matching lines...) Expand all
744 if (type == InspectorPageAgent::kDocumentResource && loader && 759 if (type == InspectorPageAgent::kDocumentResource && loader &&
745 loader->GetSubstituteData().IsValid()) 760 loader->GetSubstituteData().IsValid())
746 return; 761 return;
747 762
748 // Resources are added to NetworkResourcesData as a WeakMember here and 763 // Resources are added to NetworkResourcesData as a WeakMember here and
749 // removed in willDestroyResource() called in the prefinalizer of Resource. 764 // removed in willDestroyResource() called in the prefinalizer of Resource.
750 // Because NetworkResourceData retains weak references only, it 765 // Because NetworkResourceData retains weak references only, it
751 // doesn't affect Resource lifetime. 766 // doesn't affect Resource lifetime.
752 if (cached_resource) 767 if (cached_resource)
753 resources_data_->AddResource(request_id, cached_resource); 768 resources_data_->AddResource(request_id, cached_resource);
754 String frame_id = IdentifiersFactory::FrameId(frame); 769 String frame_id = loader && loader->GetFrame()
770 ? IdentifiersFactory::FrameId(loader->GetFrame())
771 : "";
755 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; 772 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : "";
756 resources_data_->ResponseReceived(request_id, frame_id, response); 773 resources_data_->ResponseReceived(request_id, frame_id, response);
757 resources_data_->SetResourceType(request_id, type); 774 resources_data_->SetResourceType(request_id, type);
758 775
759 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && 776 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown &&
760 response.GetSecurityStyle() != 777 response.GetSecurityStyle() !=
761 ResourceResponse::kSecurityStyleUnauthenticated) { 778 ResourceResponse::kSecurityStyleUnauthenticated) {
762 const ResourceResponse::SecurityDetails* response_security_details = 779 const ResourceResponse::SecurityDetails* response_security_details =
763 response.GetSecurityDetails(); 780 response.GetSecurityDetails();
764 resources_data_->SetCertificate(request_id, 781 resources_data_->SetCertificate(request_id,
765 response_security_details->certificate); 782 response_security_details->certificate);
766 } 783 }
767 784
768 if (resource_response && !resource_is_empty) 785 if (resource_response && !resource_is_empty) {
769 GetFrontend()->responseReceived(request_id, frame_id, loader_id, 786 Maybe<String> maybe_frame_id;
770 MonotonicallyIncreasingTime(), 787 if (!frame_id.IsEmpty())
771 InspectorPageAgent::ResourceTypeJson(type), 788 maybe_frame_id = frame_id;
772 std::move(resource_response)); 789 GetFrontend()->responseReceived(
790 request_id, loader_id, MonotonicallyIncreasingTime(),
791 InspectorPageAgent::ResourceTypeJson(type),
792 std::move(resource_response), std::move(maybe_frame_id));
793 }
773 // If we revalidated the resource and got Not modified, send content length 794 // If we revalidated the resource and got Not modified, send content length
774 // following didReceiveResponse as there will be no calls to didReceiveData 795 // following didReceiveResponse as there will be no calls to didReceiveData
775 // from the network stack. 796 // from the network stack.
776 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) 797 if (is_not_modified && cached_resource && cached_resource->EncodedSize())
777 DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); 798 DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize());
778 } 799 }
779 800
780 static bool IsErrorStatusCode(int status_code) { 801 static bool IsErrorStatusCode(int status_code) {
781 return status_code >= 400; 802 return status_code >= 400;
782 } 803 }
783 804
784 void InspectorNetworkAgent::DidReceiveData(LocalFrame*, 805 void InspectorNetworkAgent::DidReceiveData(unsigned long identifier,
785 unsigned long identifier, 806 DocumentLoader* loader,
786 const char* data, 807 const char* data,
787 int data_length) { 808 int data_length) {
788 String request_id = IdentifiersFactory::RequestId(identifier); 809 String request_id = IdentifiersFactory::RequestId(identifier);
789 810
790 if (data) { 811 if (data) {
791 NetworkResourcesData::ResourceData const* resource_data = 812 NetworkResourcesData::ResourceData const* resource_data =
792 resources_data_->Data(request_id); 813 resources_data_->Data(request_id);
793 if (resource_data && 814 if (resource_data &&
794 (!resource_data->CachedResource() || 815 (!resource_data->CachedResource() ||
795 resource_data->CachedResource()->GetDataBufferingPolicy() == 816 resource_data->CachedResource()->GetDataBufferingPolicy() ==
796 kDoNotBufferData || 817 kDoNotBufferData ||
797 IsErrorStatusCode(resource_data->HttpStatusCode()))) 818 IsErrorStatusCode(resource_data->HttpStatusCode())))
798 resources_data_->MaybeAddResourceData(request_id, data, data_length); 819 resources_data_->MaybeAddResourceData(request_id, data, data_length);
799 } 820 }
800 821
801 GetFrontend()->dataReceived( 822 GetFrontend()->dataReceived(
802 request_id, MonotonicallyIncreasingTime(), data_length, 823 request_id, MonotonicallyIncreasingTime(), data_length,
803 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); 824 resources_data_->GetAndClearPendingEncodedDataLength(request_id));
804 } 825 }
805 826
806 void InspectorNetworkAgent::DidReceiveEncodedDataLength( 827 void InspectorNetworkAgent::DidReceiveEncodedDataLength(
807 LocalFrame*,
808 unsigned long identifier, 828 unsigned long identifier,
809 int encoded_data_length) { 829 int encoded_data_length) {
810 String request_id = IdentifiersFactory::RequestId(identifier); 830 String request_id = IdentifiersFactory::RequestId(identifier);
811 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); 831 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length);
812 } 832 }
813 833
814 void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, 834 void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier,
815 unsigned long identifier, 835 DocumentLoader*,
816 double monotonic_finish_time, 836 double monotonic_finish_time,
817 int64_t encoded_data_length, 837 int64_t encoded_data_length,
818 int64_t decoded_body_length) { 838 int64_t decoded_body_length) {
819 String request_id = IdentifiersFactory::RequestId(identifier); 839 String request_id = IdentifiersFactory::RequestId(identifier);
820 NetworkResourcesData::ResourceData const* resource_data = 840 NetworkResourcesData::ResourceData const* resource_data =
821 resources_data_->Data(request_id); 841 resources_data_->Data(request_id);
822 842
823 int pending_encoded_data_length = 843 int pending_encoded_data_length =
824 resources_data_->GetAndClearPendingEncodedDataLength(request_id); 844 resources_data_->GetAndClearPendingEncodedDataLength(request_id);
825 if (pending_encoded_data_length > 0) { 845 if (pending_encoded_data_length > 0) {
(...skipping 16 matching lines...) Expand all
842 encoded_data_length); 862 encoded_data_length);
843 } 863 }
844 864
845 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( 865 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse(
846 LocalFrame* frame, 866 LocalFrame* frame,
847 unsigned long identifier, 867 unsigned long identifier,
848 DocumentLoader* loader, 868 DocumentLoader* loader,
849 const ResourceResponse& response, 869 const ResourceResponse& response,
850 Resource* resource) { 870 Resource* resource) {
851 // Update the response and finish loading 871 // Update the response and finish loading
852 DidReceiveResourceResponse(frame, identifier, loader, response, resource); 872 DidReceiveResourceResponse(identifier, loader, response, resource);
853 DidFinishLoading(frame, identifier, 0, 873 DidFinishLoading(identifier, loader, 0,
854 WebURLLoaderClient::kUnknownEncodedDataLength, 0); 874 WebURLLoaderClient::kUnknownEncodedDataLength, 0);
855 } 875 }
856 876
857 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, 877 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier,
858 const ResourceError& error) { 878 const ResourceError& error) {
859 String request_id = IdentifiersFactory::RequestId(identifier); 879 String request_id = IdentifiersFactory::RequestId(identifier);
860 bool canceled = error.IsCancellation(); 880 bool canceled = error.IsCancellation();
861 GetFrontend()->loadingFailed( 881 GetFrontend()->loadingFailed(
862 request_id, MonotonicallyIncreasingTime(), 882 request_id, MonotonicallyIncreasingTime(),
863 InspectorPageAgent::ResourceTypeJson( 883 InspectorPageAgent::ResourceTypeJson(
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 return Response::OK(); 1276 return Response::OK();
1257 } 1277 }
1258 1278
1259 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) { 1279 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) {
1260 NetworkResourcesData::ResourceData const* resource_data = 1280 NetworkResourcesData::ResourceData const* resource_data =
1261 resources_data_->Data(request_id); 1281 resources_data_->Data(request_id);
1262 BlobDataHandle* blob = 1282 BlobDataHandle* blob =
1263 resource_data ? resource_data->DownloadedFileBlob() : nullptr; 1283 resource_data ? resource_data->DownloadedFileBlob() : nullptr;
1264 if (!blob) 1284 if (!blob)
1265 return false; 1285 return false;
1286 if (worker_global_scope_)
1287 return true;
1266 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, 1288 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_,
1267 resource_data->FrameId()); 1289 resource_data->FrameId());
1268 return frame && frame->GetDocument(); 1290 return frame && frame->GetDocument();
1269 } 1291 }
1270 1292
1271 void InspectorNetworkAgent::GetResponseBodyBlob( 1293 void InspectorNetworkAgent::GetResponseBodyBlob(
1272 const String& request_id, 1294 const String& request_id,
1273 std::unique_ptr<GetResponseBodyCallback> callback) { 1295 std::unique_ptr<GetResponseBodyCallback> callback) {
1274 NetworkResourcesData::ResourceData const* resource_data = 1296 NetworkResourcesData::ResourceData const* resource_data =
1275 resources_data_->Data(request_id); 1297 resources_data_->Data(request_id);
1276 BlobDataHandle* blob = resource_data->DownloadedFileBlob(); 1298 BlobDataHandle* blob = resource_data->DownloadedFileBlob();
1299 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient(
1300 blob, resource_data->MimeType(), resource_data->TextEncodingName(),
1301 std::move(callback));
1302 if (worker_global_scope_) {
1303 client->Start(worker_global_scope_);
1304 return;
1305 }
1306 DCHECK(inspected_frames_);
1277 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, 1307 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_,
1278 resource_data->FrameId()); 1308 resource_data->FrameId());
1279 Document* document = frame->GetDocument(); 1309 Document* document = frame->GetDocument();
1280 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient(
1281 blob, resource_data->MimeType(), resource_data->TextEncodingName(),
1282 std::move(callback));
1283 client->Start(document); 1310 client->Start(document);
1284 } 1311 }
1285 1312
1286 void InspectorNetworkAgent::getResponseBody( 1313 void InspectorNetworkAgent::getResponseBody(
1287 const String& request_id, 1314 const String& request_id,
1288 std::unique_ptr<GetResponseBodyCallback> pass_callback) { 1315 std::unique_ptr<GetResponseBodyCallback> pass_callback) {
1289 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback); 1316 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback);
1290 NetworkResourcesData::ResourceData const* resource_data = 1317 NetworkResourcesData::ResourceData const* resource_data =
1291 resources_data_->Data(request_id); 1318 resources_data_->Data(request_id);
1292 if (!resource_data) { 1319 if (!resource_data) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 *result = true; 1415 *result = true;
1389 return Response::OK(); 1416 return Response::OK();
1390 } 1417 }
1391 1418
1392 Response InspectorNetworkAgent::emulateNetworkConditions( 1419 Response InspectorNetworkAgent::emulateNetworkConditions(
1393 bool offline, 1420 bool offline,
1394 double latency, 1421 double latency,
1395 double download_throughput, 1422 double download_throughput,
1396 double upload_throughput, 1423 double upload_throughput,
1397 Maybe<String> connection_type) { 1424 Maybe<String> connection_type) {
1425 if (!IsMainThread())
1426 return Response::Error("Not supported");
1427
1398 WebConnectionType type = kWebConnectionTypeUnknown; 1428 WebConnectionType type = kWebConnectionTypeUnknown;
1399 if (connection_type.isJust()) { 1429 if (connection_type.isJust()) {
1400 type = ToWebConnectionType(connection_type.fromJust()); 1430 type = ToWebConnectionType(connection_type.fromJust());
1401 if (type == kWebConnectionTypeUnknown) 1431 if (type == kWebConnectionTypeUnknown)
1402 return Response::Error("Unknown connection type"); 1432 return Response::Error("Unknown connection type");
1403 } 1433 }
1404 // TODO(dgozman): networkStateNotifier is per-process. It would be nice to 1434 // TODO(dgozman): networkStateNotifier is per-process. It would be nice to
1405 // have per-frame override instead. 1435 // have per-frame override instead.
1406 if (offline || latency || download_throughput || upload_throughput) 1436 if (offline || latency || download_throughput || upload_throughput)
1407 GetNetworkStateNotifier().SetNetworkConnectionInfoOverride( 1437 GetNetworkStateNotifier().SetNetworkConnectionInfoOverride(
1408 !offline, type, download_throughput / (1024 * 1024 / 8)); 1438 !offline, type, download_throughput / (1024 * 1024 / 8));
1409 else 1439 else
1410 GetNetworkStateNotifier().ClearOverride(); 1440 GetNetworkStateNotifier().ClearOverride();
1411 return Response::OK(); 1441 return Response::OK();
1412 } 1442 }
1413 1443
1414 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { 1444 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) {
1415 // TODO(ananta) 1445 // TODO(ananta)
1416 // We should extract network cache state into a global entity which can be 1446 // We should extract network cache state into a global entity which can be
1417 // queried from FrameLoader and other places. 1447 // queried from FrameLoader and other places.
1418 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); 1448 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled);
1419 if (cache_disabled) 1449 if (cache_disabled && IsMainThread())
1420 GetMemoryCache()->EvictResources(); 1450 GetMemoryCache()->EvictResources();
1421 return Response::OK(); 1451 return Response::OK();
1422 } 1452 }
1423 1453
1424 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { 1454 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) {
1425 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); 1455 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass);
1426 return Response::OK(); 1456 return Response::OK();
1427 } 1457 }
1428 1458
1429 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, 1459 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total,
(...skipping 16 matching lines...) Expand all
1446 for (auto& cert : resource->Certificate()) 1476 for (auto& cert : resource->Certificate())
1447 certificate->get()->addItem(Base64Encode(cert.Latin1())); 1477 certificate->get()->addItem(Base64Encode(cert.Latin1()));
1448 return Response::OK(); 1478 return Response::OK();
1449 } 1479 }
1450 } 1480 }
1451 return Response::OK(); 1481 return Response::OK();
1452 } 1482 }
1453 1483
1454 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, 1484 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame,
1455 DocumentLoader* loader) { 1485 DocumentLoader* loader) {
1486 DCHECK(inspected_frames_);
1487 DCHECK(IsMainThread());
1456 if (loader->GetFrame() != inspected_frames_->Root()) 1488 if (loader->GetFrame() != inspected_frames_->Root())
1457 return; 1489 return;
1458 1490
1459 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1491 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false))
1460 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); 1492 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads);
1461 1493
1462 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); 1494 resources_data_->Clear(IdentifiersFactory::LoaderId(loader));
1463 } 1495 }
1464 1496
1465 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, 1497 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 } 1531 }
1500 1532
1501 void InspectorNetworkAgent::SetHostId(const String& host_id) { 1533 void InspectorNetworkAgent::SetHostId(const String& host_id) {
1502 host_id_ = host_id; 1534 host_id_ = host_id;
1503 } 1535 }
1504 1536
1505 bool InspectorNetworkAgent::FetchResourceContent(Document* document, 1537 bool InspectorNetworkAgent::FetchResourceContent(Document* document,
1506 const KURL& url, 1538 const KURL& url,
1507 String* content, 1539 String* content,
1508 bool* base64_encoded) { 1540 bool* base64_encoded) {
1541 DCHECK(document);
1542 DCHECK(IsMainThread());
1509 // First try to fetch content from the cached resource. 1543 // First try to fetch content from the cached resource.
1510 Resource* cached_resource = document->Fetcher()->CachedResource(url); 1544 Resource* cached_resource = document->Fetcher()->CachedResource(url);
1511 if (!cached_resource) 1545 if (!cached_resource) {
1512 cached_resource = GetMemoryCache()->ResourceForURL( 1546 cached_resource = GetMemoryCache()->ResourceForURL(
1513 url, document->Fetcher()->GetCacheIdentifier()); 1547 url, document->Fetcher()->GetCacheIdentifier());
1548 }
1514 if (cached_resource && InspectorPageAgent::CachedResourceContent( 1549 if (cached_resource && InspectorPageAgent::CachedResourceContent(
1515 cached_resource, content, base64_encoded)) 1550 cached_resource, content, base64_encoded))
1516 return true; 1551 return true;
1517 1552
1518 // Then fall back to resource data. 1553 // Then fall back to resource data.
1519 for (auto& resource : resources_data_->Resources()) { 1554 for (auto& resource : resources_data_->Resources()) {
1520 if (resource->RequestedURL() == url) { 1555 if (resource->RequestedURL() == url) {
1521 *content = resource->Content(); 1556 *content = resource->Content();
1522 *base64_encoded = resource->Base64Encoded(); 1557 *base64_encoded = resource->Base64Encoded();
1523 return true; 1558 return true;
1524 } 1559 }
1525 } 1560 }
1526 return false; 1561 return false;
1527 } 1562 }
1528 1563
1529 bool InspectorNetworkAgent::CacheDisabled() { 1564 bool InspectorNetworkAgent::CacheDisabled() {
1530 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled, 1565 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled,
1531 false) && 1566 false) &&
1532 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false); 1567 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false);
1533 } 1568 }
1534 1569
1535 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) { 1570 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) {
1536 replay_xhrs_to_be_deleted_.clear(); 1571 replay_xhrs_to_be_deleted_.clear();
1537 } 1572 }
1538 1573
1539 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) 1574 InspectorNetworkAgent::InspectorNetworkAgent(
1575 InspectedFrames* inspected_frames,
1576 WorkerGlobalScope* worker_global_scope)
1540 : inspected_frames_(inspected_frames), 1577 : inspected_frames_(inspected_frames),
1578 worker_global_scope_(worker_global_scope),
1541 resources_data_( 1579 resources_data_(
1542 NetworkResourcesData::Create(g_maximum_total_buffer_size, 1580 NetworkResourcesData::Create(g_maximum_total_buffer_size,
1543 g_maximum_resource_buffer_size)), 1581 g_maximum_resource_buffer_size)),
1544 pending_request_(nullptr), 1582 pending_request_(nullptr),
1545 remove_finished_replay_xhr_timer_( 1583 remove_finished_replay_xhr_timer_(
1546 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, 1584 inspected_frames ? TaskRunnerHelper::Get(TaskType::kUnspecedLoading,
1547 inspected_frames->Root()), 1585 inspected_frames->Root())
1586 : TaskRunnerHelper::Get(TaskType::kUnspecedLoading,
1587 worker_global_scope),
1548 this, 1588 this,
1549 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} 1589 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {
1590 DCHECK((IsMainThread() && inspected_frames_ && !worker_global_scope_) ||
1591 (!IsMainThread() && !inspected_frames_ && worker_global_scope_));
1592 }
1550 1593
1551 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { 1594 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) {
1552 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) 1595 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false))
1553 *result = true; 1596 *result = true;
1554 } 1597 }
1555 1598
1556 } // namespace blink 1599 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698