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

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

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

Powered by Google App Engine
This is Rietveld 408576698