OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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(execution_context_); | |
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); |
653 GetFrontend()->requestWillBeSent( | 663 String documentURL = |
654 request_id, frame_id, loader_id, | 664 loader ? UrlWithoutFragment(loader->Url()).GetString() |
655 UrlWithoutFragment(loader->Url()).GetString(), std::move(request_info), | 665 : UrlWithoutFragment(execution_context->Url()).GetString(); |
656 MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), | 666 if (!frame_id.IsEmpty()) { |
657 BuildObjectForResourceResponse(redirect_response), resource_type); | 667 GetFrontend()->requestWillBeSent( |
668 request_id, loader_id, documentURL, std::move(request_info), | |
669 MonotonicallyIncreasingTime(), CurrentTime(), | |
670 std::move(initiator_object), | |
671 BuildObjectForResourceResponse(redirect_response), resource_type, | |
672 frame_id); | |
673 } else { | |
674 GetFrontend()->requestWillBeSent( | |
675 request_id, loader_id, documentURL, std::move(request_info), | |
676 MonotonicallyIncreasingTime(), CurrentTime(), | |
677 std::move(initiator_object), | |
678 BuildObjectForResourceResponse(redirect_response), resource_type); | |
679 } | |
dgozman
2017/06/28 22:50:32
I think it's possible to pass Maybe<String>() here
horo
2017/06/29 02:14:28
Done.
| |
658 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) | 680 if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) |
659 GetFrontend()->flush(); | 681 GetFrontend()->flush(); |
660 } | 682 } |
661 | 683 |
662 void InspectorNetworkAgent::WillSendRequest( | 684 void InspectorNetworkAgent::WillSendRequest( |
663 LocalFrame* frame, | 685 ExecutionContext* execution_context, |
664 unsigned long identifier, | 686 unsigned long identifier, |
665 DocumentLoader* loader, | 687 DocumentLoader* loader, |
666 ResourceRequest& request, | 688 ResourceRequest& request, |
667 const ResourceResponse& redirect_response, | 689 const ResourceResponse& redirect_response, |
668 const FetchInitiatorInfo& initiator_info) { | 690 const FetchInitiatorInfo& initiator_info) { |
669 // Ignore the request initiated internally. | 691 // Ignore the request initiated internally. |
670 if (initiator_info.name == FetchInitiatorTypeNames::internal) | 692 if (initiator_info.name == FetchInitiatorTypeNames::internal) |
671 return; | 693 return; |
672 | 694 |
673 if (initiator_info.name == FetchInitiatorTypeNames::document && | 695 if (initiator_info.name == FetchInitiatorTypeNames::document && |
(...skipping 19 matching lines...) Expand all Loading... | |
693 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { | 715 request.GetRequestContext() != WebURLRequest::kRequestContextInternal) { |
694 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); | 716 request.SetCachePolicy(WebCachePolicy::kBypassCacheLoadOnlyFromCache); |
695 } else { | 717 } else { |
696 request.SetCachePolicy(WebCachePolicy::kBypassingCache); | 718 request.SetCachePolicy(WebCachePolicy::kBypassingCache); |
697 } | 719 } |
698 request.SetShouldResetAppCache(true); | 720 request.SetShouldResetAppCache(true); |
699 } | 721 } |
700 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) | 722 if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) |
701 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); | 723 request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); |
702 | 724 |
703 WillSendRequestInternal(frame, identifier, loader, request, redirect_response, | 725 WillSendRequestInternal(execution_context, identifier, loader, request, |
704 initiator_info); | 726 redirect_response, initiator_info); |
705 | 727 |
706 if (!host_id_.IsEmpty()) | 728 if (!host_id_.IsEmpty()) |
707 request.AddHTTPHeaderField( | 729 request.AddHTTPHeaderField( |
708 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, | 730 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, |
709 AtomicString(host_id_)); | 731 AtomicString(host_id_)); |
710 } | 732 } |
711 | 733 |
712 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { | 734 void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { |
713 GetFrontend()->requestServedFromCache( | 735 GetFrontend()->requestServedFromCache( |
714 IdentifiersFactory::RequestId(identifier)); | 736 IdentifiersFactory::RequestId(identifier)); |
715 } | 737 } |
716 | 738 |
717 void InspectorNetworkAgent::DidReceiveResourceResponse( | 739 void InspectorNetworkAgent::DidReceiveResourceResponse( |
718 LocalFrame* frame, | |
719 unsigned long identifier, | 740 unsigned long identifier, |
720 DocumentLoader* loader, | 741 DocumentLoader* loader, |
721 const ResourceResponse& response, | 742 const ResourceResponse& response, |
722 Resource* cached_resource) { | 743 Resource* cached_resource) { |
723 String request_id = IdentifiersFactory::RequestId(identifier); | 744 String request_id = IdentifiersFactory::RequestId(identifier); |
724 bool is_not_modified = response.HttpStatusCode() == 304; | 745 bool is_not_modified = response.HttpStatusCode() == 304; |
725 | 746 |
726 bool resource_is_empty = true; | 747 bool resource_is_empty = true; |
727 std::unique_ptr<protocol::Network::Response> resource_response = | 748 std::unique_ptr<protocol::Network::Response> resource_response = |
728 BuildObjectForResourceResponse(response, cached_resource, | 749 BuildObjectForResourceResponse(response, cached_resource, |
(...skipping 15 matching lines...) Expand all Loading... | |
744 if (type == InspectorPageAgent::kDocumentResource && loader && | 765 if (type == InspectorPageAgent::kDocumentResource && loader && |
745 loader->GetSubstituteData().IsValid()) | 766 loader->GetSubstituteData().IsValid()) |
746 return; | 767 return; |
747 | 768 |
748 // Resources are added to NetworkResourcesData as a WeakMember here and | 769 // Resources are added to NetworkResourcesData as a WeakMember here and |
749 // removed in willDestroyResource() called in the prefinalizer of Resource. | 770 // removed in willDestroyResource() called in the prefinalizer of Resource. |
750 // Because NetworkResourceData retains weak references only, it | 771 // Because NetworkResourceData retains weak references only, it |
751 // doesn't affect Resource lifetime. | 772 // doesn't affect Resource lifetime. |
752 if (cached_resource) | 773 if (cached_resource) |
753 resources_data_->AddResource(request_id, cached_resource); | 774 resources_data_->AddResource(request_id, cached_resource); |
754 String frame_id = IdentifiersFactory::FrameId(frame); | 775 String frame_id = loader && loader->GetFrame() |
776 ? IdentifiersFactory::FrameId(loader->GetFrame()) | |
777 : ""; | |
755 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; | 778 String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; |
756 resources_data_->ResponseReceived(request_id, frame_id, response); | 779 resources_data_->ResponseReceived(request_id, frame_id, response); |
757 resources_data_->SetResourceType(request_id, type); | 780 resources_data_->SetResourceType(request_id, type); |
758 | 781 |
759 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && | 782 if (response.GetSecurityStyle() != ResourceResponse::kSecurityStyleUnknown && |
760 response.GetSecurityStyle() != | 783 response.GetSecurityStyle() != |
761 ResourceResponse::kSecurityStyleUnauthenticated) { | 784 ResourceResponse::kSecurityStyleUnauthenticated) { |
762 const ResourceResponse::SecurityDetails* response_security_details = | 785 const ResourceResponse::SecurityDetails* response_security_details = |
763 response.GetSecurityDetails(); | 786 response.GetSecurityDetails(); |
764 resources_data_->SetCertificate(request_id, | 787 resources_data_->SetCertificate(request_id, |
765 response_security_details->certificate); | 788 response_security_details->certificate); |
766 } | 789 } |
767 | 790 |
768 if (resource_response && !resource_is_empty) | 791 if (resource_response && !resource_is_empty) { |
769 GetFrontend()->responseReceived(request_id, frame_id, loader_id, | 792 if (!frame_id.IsEmpty()) { |
770 MonotonicallyIncreasingTime(), | 793 GetFrontend()->responseReceived( |
771 InspectorPageAgent::ResourceTypeJson(type), | 794 request_id, loader_id, MonotonicallyIncreasingTime(), |
772 std::move(resource_response)); | 795 InspectorPageAgent::ResourceTypeJson(type), |
796 std::move(resource_response), frame_id); | |
797 } else { | |
798 GetFrontend()->responseReceived( | |
799 request_id, loader_id, MonotonicallyIncreasingTime(), | |
800 InspectorPageAgent::ResourceTypeJson(type), | |
801 std::move(resource_response)); | |
802 } | |
803 } | |
773 // If we revalidated the resource and got Not modified, send content length | 804 // If we revalidated the resource and got Not modified, send content length |
774 // following didReceiveResponse as there will be no calls to didReceiveData | 805 // following didReceiveResponse as there will be no calls to didReceiveData |
775 // from the network stack. | 806 // from the network stack. |
776 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) | 807 if (is_not_modified && cached_resource && cached_resource->EncodedSize()) |
777 DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); | 808 DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize()); |
778 } | 809 } |
779 | 810 |
780 static bool IsErrorStatusCode(int status_code) { | 811 static bool IsErrorStatusCode(int status_code) { |
781 return status_code >= 400; | 812 return status_code >= 400; |
782 } | 813 } |
783 | 814 |
784 void InspectorNetworkAgent::DidReceiveData(LocalFrame*, | 815 void InspectorNetworkAgent::DidReceiveData(unsigned long identifier, |
785 unsigned long identifier, | 816 DocumentLoader* loader, |
786 const char* data, | 817 const char* data, |
787 int data_length) { | 818 int data_length) { |
788 String request_id = IdentifiersFactory::RequestId(identifier); | 819 String request_id = IdentifiersFactory::RequestId(identifier); |
789 | 820 |
790 if (data) { | 821 if (data) { |
791 NetworkResourcesData::ResourceData const* resource_data = | 822 NetworkResourcesData::ResourceData const* resource_data = |
792 resources_data_->Data(request_id); | 823 resources_data_->Data(request_id); |
793 if (resource_data && | 824 if (resource_data && |
794 (!resource_data->CachedResource() || | 825 (!resource_data->CachedResource() || |
795 resource_data->CachedResource()->GetDataBufferingPolicy() == | 826 resource_data->CachedResource()->GetDataBufferingPolicy() == |
796 kDoNotBufferData || | 827 kDoNotBufferData || |
797 IsErrorStatusCode(resource_data->HttpStatusCode()))) | 828 IsErrorStatusCode(resource_data->HttpStatusCode()))) |
798 resources_data_->MaybeAddResourceData(request_id, data, data_length); | 829 resources_data_->MaybeAddResourceData(request_id, data, data_length); |
799 } | 830 } |
800 | 831 |
801 GetFrontend()->dataReceived( | 832 GetFrontend()->dataReceived( |
802 request_id, MonotonicallyIncreasingTime(), data_length, | 833 request_id, MonotonicallyIncreasingTime(), data_length, |
803 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); | 834 resources_data_->GetAndClearPendingEncodedDataLength(request_id)); |
804 } | 835 } |
805 | 836 |
806 void InspectorNetworkAgent::DidReceiveEncodedDataLength( | 837 void InspectorNetworkAgent::DidReceiveEncodedDataLength( |
807 LocalFrame*, | |
808 unsigned long identifier, | 838 unsigned long identifier, |
809 int encoded_data_length) { | 839 int encoded_data_length) { |
810 String request_id = IdentifiersFactory::RequestId(identifier); | 840 String request_id = IdentifiersFactory::RequestId(identifier); |
811 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); | 841 resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); |
812 } | 842 } |
813 | 843 |
814 void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, | 844 void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier, |
815 unsigned long identifier, | 845 DocumentLoader*, |
816 double monotonic_finish_time, | 846 double monotonic_finish_time, |
817 int64_t encoded_data_length, | 847 int64_t encoded_data_length, |
818 int64_t decoded_body_length) { | 848 int64_t decoded_body_length) { |
819 String request_id = IdentifiersFactory::RequestId(identifier); | 849 String request_id = IdentifiersFactory::RequestId(identifier); |
820 NetworkResourcesData::ResourceData const* resource_data = | 850 NetworkResourcesData::ResourceData const* resource_data = |
821 resources_data_->Data(request_id); | 851 resources_data_->Data(request_id); |
822 | 852 |
823 int pending_encoded_data_length = | 853 int pending_encoded_data_length = |
824 resources_data_->GetAndClearPendingEncodedDataLength(request_id); | 854 resources_data_->GetAndClearPendingEncodedDataLength(request_id); |
825 if (pending_encoded_data_length > 0) { | 855 if (pending_encoded_data_length > 0) { |
(...skipping 16 matching lines...) Expand all Loading... | |
842 encoded_data_length); | 872 encoded_data_length); |
843 } | 873 } |
844 | 874 |
845 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( | 875 void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( |
846 LocalFrame* frame, | 876 LocalFrame* frame, |
847 unsigned long identifier, | 877 unsigned long identifier, |
848 DocumentLoader* loader, | 878 DocumentLoader* loader, |
849 const ResourceResponse& response, | 879 const ResourceResponse& response, |
850 Resource* resource) { | 880 Resource* resource) { |
851 // Update the response and finish loading | 881 // Update the response and finish loading |
852 DidReceiveResourceResponse(frame, identifier, loader, response, resource); | 882 DidReceiveResourceResponse(identifier, loader, response, resource); |
853 DidFinishLoading(frame, identifier, 0, | 883 DidFinishLoading(identifier, loader, 0, |
854 WebURLLoaderClient::kUnknownEncodedDataLength, 0); | 884 WebURLLoaderClient::kUnknownEncodedDataLength, 0); |
855 } | 885 } |
856 | 886 |
857 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, | 887 void InspectorNetworkAgent::DidFailLoading(unsigned long identifier, |
858 const ResourceError& error) { | 888 const ResourceError& error) { |
859 String request_id = IdentifiersFactory::RequestId(identifier); | 889 String request_id = IdentifiersFactory::RequestId(identifier); |
860 bool canceled = error.IsCancellation(); | 890 bool canceled = error.IsCancellation(); |
861 GetFrontend()->loadingFailed( | 891 GetFrontend()->loadingFailed( |
862 request_id, MonotonicallyIncreasingTime(), | 892 request_id, MonotonicallyIncreasingTime(), |
863 InspectorPageAgent::ResourceTypeJson( | 893 InspectorPageAgent::ResourceTypeJson( |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 return Response::OK(); | 1286 return Response::OK(); |
1257 } | 1287 } |
1258 | 1288 |
1259 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) { | 1289 bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) { |
1260 NetworkResourcesData::ResourceData const* resource_data = | 1290 NetworkResourcesData::ResourceData const* resource_data = |
1261 resources_data_->Data(request_id); | 1291 resources_data_->Data(request_id); |
1262 BlobDataHandle* blob = | 1292 BlobDataHandle* blob = |
1263 resource_data ? resource_data->DownloadedFileBlob() : nullptr; | 1293 resource_data ? resource_data->DownloadedFileBlob() : nullptr; |
1264 if (!blob) | 1294 if (!blob) |
1265 return false; | 1295 return false; |
1296 if (execution_context_) | |
1297 return true; | |
1266 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, | 1298 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, |
1267 resource_data->FrameId()); | 1299 resource_data->FrameId()); |
1268 return frame && frame->GetDocument(); | 1300 return frame && frame->GetDocument(); |
1269 } | 1301 } |
1270 | 1302 |
1271 void InspectorNetworkAgent::GetResponseBodyBlob( | 1303 void InspectorNetworkAgent::GetResponseBodyBlob( |
1272 const String& request_id, | 1304 const String& request_id, |
1273 std::unique_ptr<GetResponseBodyCallback> callback) { | 1305 std::unique_ptr<GetResponseBodyCallback> callback) { |
1274 NetworkResourcesData::ResourceData const* resource_data = | 1306 NetworkResourcesData::ResourceData const* resource_data = |
1275 resources_data_->Data(request_id); | 1307 resources_data_->Data(request_id); |
1276 BlobDataHandle* blob = resource_data->DownloadedFileBlob(); | 1308 BlobDataHandle* blob = resource_data->DownloadedFileBlob(); |
1309 InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient( | |
1310 blob, resource_data->MimeType(), resource_data->TextEncodingName(), | |
1311 std::move(callback)); | |
1312 if (execution_context_) { | |
1313 client->Start(execution_context_); | |
1314 return; | |
1315 } | |
1316 DCHECK(inspected_frames_); | |
1277 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, | 1317 LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, |
1278 resource_data->FrameId()); | 1318 resource_data->FrameId()); |
1279 Document* document = frame->GetDocument(); | 1319 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); | 1320 client->Start(document); |
1284 } | 1321 } |
1285 | 1322 |
1286 void InspectorNetworkAgent::getResponseBody( | 1323 void InspectorNetworkAgent::getResponseBody( |
1287 const String& request_id, | 1324 const String& request_id, |
1288 std::unique_ptr<GetResponseBodyCallback> pass_callback) { | 1325 std::unique_ptr<GetResponseBodyCallback> pass_callback) { |
1289 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback); | 1326 std::unique_ptr<GetResponseBodyCallback> callback = std::move(pass_callback); |
1290 NetworkResourcesData::ResourceData const* resource_data = | 1327 NetworkResourcesData::ResourceData const* resource_data = |
1291 resources_data_->Data(request_id); | 1328 resources_data_->Data(request_id); |
1292 if (!resource_data) { | 1329 if (!resource_data) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1388 *result = true; | 1425 *result = true; |
1389 return Response::OK(); | 1426 return Response::OK(); |
1390 } | 1427 } |
1391 | 1428 |
1392 Response InspectorNetworkAgent::emulateNetworkConditions( | 1429 Response InspectorNetworkAgent::emulateNetworkConditions( |
1393 bool offline, | 1430 bool offline, |
1394 double latency, | 1431 double latency, |
1395 double download_throughput, | 1432 double download_throughput, |
1396 double upload_throughput, | 1433 double upload_throughput, |
1397 Maybe<String> connection_type) { | 1434 Maybe<String> connection_type) { |
1435 if (!IsMainThread()) | |
1436 return Response::Error("Not supported"); | |
1437 | |
1398 WebConnectionType type = kWebConnectionTypeUnknown; | 1438 WebConnectionType type = kWebConnectionTypeUnknown; |
1399 if (connection_type.isJust()) { | 1439 if (connection_type.isJust()) { |
1400 type = ToWebConnectionType(connection_type.fromJust()); | 1440 type = ToWebConnectionType(connection_type.fromJust()); |
1401 if (type == kWebConnectionTypeUnknown) | 1441 if (type == kWebConnectionTypeUnknown) |
1402 return Response::Error("Unknown connection type"); | 1442 return Response::Error("Unknown connection type"); |
1403 } | 1443 } |
1404 // TODO(dgozman): networkStateNotifier is per-process. It would be nice to | 1444 // TODO(dgozman): networkStateNotifier is per-process. It would be nice to |
1405 // have per-frame override instead. | 1445 // have per-frame override instead. |
1406 if (offline || latency || download_throughput || upload_throughput) | 1446 if (offline || latency || download_throughput || upload_throughput) |
1407 GetNetworkStateNotifier().SetNetworkConnectionInfoOverride( | 1447 GetNetworkStateNotifier().SetNetworkConnectionInfoOverride( |
1408 !offline, type, download_throughput / (1024 * 1024 / 8)); | 1448 !offline, type, download_throughput / (1024 * 1024 / 8)); |
1409 else | 1449 else |
1410 GetNetworkStateNotifier().ClearOverride(); | 1450 GetNetworkStateNotifier().ClearOverride(); |
1411 return Response::OK(); | 1451 return Response::OK(); |
1412 } | 1452 } |
1413 | 1453 |
1414 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { | 1454 Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { |
1415 // TODO(ananta) | 1455 // TODO(ananta) |
1416 // We should extract network cache state into a global entity which can be | 1456 // We should extract network cache state into a global entity which can be |
1417 // queried from FrameLoader and other places. | 1457 // queried from FrameLoader and other places. |
1418 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); | 1458 state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); |
1419 if (cache_disabled) | 1459 if (cache_disabled && IsMainThread()) |
1420 GetMemoryCache()->EvictResources(); | 1460 GetMemoryCache()->EvictResources(); |
1421 return Response::OK(); | 1461 return Response::OK(); |
1422 } | 1462 } |
1423 | 1463 |
1424 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { | 1464 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { |
1425 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); | 1465 state_->setBoolean(NetworkAgentState::kBypassServiceWorker, bypass); |
1426 return Response::OK(); | 1466 return Response::OK(); |
1427 } | 1467 } |
1428 | 1468 |
1429 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, | 1469 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int max_total, |
(...skipping 16 matching lines...) Expand all Loading... | |
1446 for (auto& cert : resource->Certificate()) | 1486 for (auto& cert : resource->Certificate()) |
1447 certificate->get()->addItem(Base64Encode(cert.Latin1())); | 1487 certificate->get()->addItem(Base64Encode(cert.Latin1())); |
1448 return Response::OK(); | 1488 return Response::OK(); |
1449 } | 1489 } |
1450 } | 1490 } |
1451 return Response::OK(); | 1491 return Response::OK(); |
1452 } | 1492 } |
1453 | 1493 |
1454 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, | 1494 void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, |
1455 DocumentLoader* loader) { | 1495 DocumentLoader* loader) { |
1496 DCHECK(inspected_frames_); | |
1497 DCHECK(IsMainThread()); | |
1456 if (loader->GetFrame() != inspected_frames_->Root()) | 1498 if (loader->GetFrame() != inspected_frames_->Root()) |
1457 return; | 1499 return; |
1458 | 1500 |
1459 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) | 1501 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) |
1460 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); | 1502 GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); |
1461 | 1503 |
1462 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); | 1504 resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); |
1463 } | 1505 } |
1464 | 1506 |
1465 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, | 1507 void InspectorNetworkAgent::FrameScheduledNavigation(LocalFrame* frame, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1499 } | 1541 } |
1500 | 1542 |
1501 void InspectorNetworkAgent::SetHostId(const String& host_id) { | 1543 void InspectorNetworkAgent::SetHostId(const String& host_id) { |
1502 host_id_ = host_id; | 1544 host_id_ = host_id; |
1503 } | 1545 } |
1504 | 1546 |
1505 bool InspectorNetworkAgent::FetchResourceContent(Document* document, | 1547 bool InspectorNetworkAgent::FetchResourceContent(Document* document, |
1506 const KURL& url, | 1548 const KURL& url, |
1507 String* content, | 1549 String* content, |
1508 bool* base64_encoded) { | 1550 bool* base64_encoded) { |
1551 DCHECK(document); | |
1552 DCHECK(IsMainThread()); | |
1509 // First try to fetch content from the cached resource. | 1553 // First try to fetch content from the cached resource. |
1510 Resource* cached_resource = document->Fetcher()->CachedResource(url); | 1554 Resource* cached_resource = document->Fetcher()->CachedResource(url); |
1511 if (!cached_resource) | 1555 if (!cached_resource) { |
1512 cached_resource = GetMemoryCache()->ResourceForURL( | 1556 cached_resource = GetMemoryCache()->ResourceForURL( |
1513 url, document->Fetcher()->GetCacheIdentifier()); | 1557 url, document->Fetcher()->GetCacheIdentifier()); |
1558 } | |
1514 if (cached_resource && InspectorPageAgent::CachedResourceContent( | 1559 if (cached_resource && InspectorPageAgent::CachedResourceContent( |
1515 cached_resource, content, base64_encoded)) | 1560 cached_resource, content, base64_encoded)) |
1516 return true; | 1561 return true; |
1517 | 1562 |
1518 // Then fall back to resource data. | 1563 // Then fall back to resource data. |
1519 for (auto& resource : resources_data_->Resources()) { | 1564 for (auto& resource : resources_data_->Resources()) { |
1520 if (resource->RequestedURL() == url) { | 1565 if (resource->RequestedURL() == url) { |
1521 *content = resource->Content(); | 1566 *content = resource->Content(); |
1522 *base64_encoded = resource->Base64Encoded(); | 1567 *base64_encoded = resource->Base64Encoded(); |
1523 return true; | 1568 return true; |
1524 } | 1569 } |
1525 } | 1570 } |
1526 return false; | 1571 return false; |
1527 } | 1572 } |
1528 | 1573 |
1529 bool InspectorNetworkAgent::CacheDisabled() { | 1574 bool InspectorNetworkAgent::CacheDisabled() { |
1530 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled, | 1575 return state_->booleanProperty(NetworkAgentState::kNetworkAgentEnabled, |
1531 false) && | 1576 false) && |
1532 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false); | 1577 state_->booleanProperty(NetworkAgentState::kCacheDisabled, false); |
1533 } | 1578 } |
1534 | 1579 |
1535 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) { | 1580 void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) { |
1536 replay_xhrs_to_be_deleted_.clear(); | 1581 replay_xhrs_to_be_deleted_.clear(); |
1537 } | 1582 } |
1538 | 1583 |
1539 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) | 1584 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) |
dgozman
2017/06/28 22:50:32
nit: I'd just add second parameter to constructor,
horo
2017/06/29 02:14:28
Done.
| |
1540 : inspected_frames_(inspected_frames), | 1585 : inspected_frames_(inspected_frames), |
1586 execution_context_(nullptr), | |
1541 resources_data_( | 1587 resources_data_( |
1542 NetworkResourcesData::Create(g_maximum_total_buffer_size, | 1588 NetworkResourcesData::Create(g_maximum_total_buffer_size, |
1543 g_maximum_resource_buffer_size)), | 1589 g_maximum_resource_buffer_size)), |
1544 pending_request_(nullptr), | 1590 pending_request_(nullptr), |
1545 remove_finished_replay_xhr_timer_( | 1591 remove_finished_replay_xhr_timer_( |
1546 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, | 1592 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, |
1547 inspected_frames->Root()), | 1593 inspected_frames->Root()), |
1548 this, | 1594 this, |
1549 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} | 1595 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) { |
1596 DCHECK(IsMainThread()); | |
1597 } | |
1598 | |
1599 InspectorNetworkAgent::InspectorNetworkAgent( | |
1600 ExecutionContext* execution_context) | |
1601 : inspected_frames_(nullptr), | |
1602 execution_context_(execution_context), | |
1603 resources_data_( | |
1604 NetworkResourcesData::Create(g_maximum_total_buffer_size, | |
1605 g_maximum_resource_buffer_size)), | |
1606 pending_request_(nullptr), | |
1607 remove_finished_replay_xhr_timer_( | |
1608 TaskRunnerHelper::Get(TaskType::kUnspecedLoading, execution_context), | |
1609 this, | |
1610 &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) { | |
1611 DCHECK(!IsMainThread()); | |
1612 } | |
1550 | 1613 |
1551 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { | 1614 void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { |
1552 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) | 1615 if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) |
1553 *result = true; | 1616 *result = true; |
1554 } | 1617 } |
1555 | 1618 |
1556 } // namespace blink | 1619 } // namespace blink |
OLD | NEW |