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

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

Issue 2701753003: [WIP] off-main-thread loading
Patch Set: small fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 auto entry = blockedURLs->at(i); 567 auto entry = blockedURLs->at(i);
568 if (matches(url, entry.first)) { 568 if (matches(url, entry.first)) {
569 *result = true; 569 *result = true;
570 return; 570 return;
571 } 571 }
572 } 572 }
573 return; 573 return;
574 } 574 }
575 575
576 void InspectorNetworkAgent::didBlockRequest( 576 void InspectorNetworkAgent::didBlockRequest(
577 LocalFrame* frame,
578 const ResourceRequest& request, 577 const ResourceRequest& request,
579 DocumentLoader* loader, 578 DocumentLoader* loader,
580 const FetchInitiatorInfo& initiatorInfo, 579 const FetchInitiatorInfo& initiatorInfo,
581 ResourceRequestBlockedReason reason) { 580 ResourceRequestBlockedReason reason) {
582 unsigned long identifier = createUniqueIdentifier(); 581 unsigned long identifier = createUniqueIdentifier();
583 willSendRequestInternal(frame, identifier, loader, request, 582 willSendRequestInternal(identifier, loader, request, ResourceResponse(),
584 ResourceResponse(), initiatorInfo); 583 initiatorInfo);
585 584
586 String requestId = IdentifiersFactory::requestId(identifier); 585 String requestId = IdentifiersFactory::requestId(identifier);
587 String protocolReason = buildBlockedReason(reason); 586 String protocolReason = buildBlockedReason(reason);
588 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), 587 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(),
589 InspectorPageAgent::resourceTypeJson( 588 InspectorPageAgent::resourceTypeJson(
590 m_resourcesData->resourceType(requestId)), 589 m_resourcesData->resourceType(requestId)),
591 String(), false, protocolReason); 590 String(), false, protocolReason);
592 } 591 }
593 592
594 void InspectorNetworkAgent::didChangeResourcePriority( 593 void InspectorNetworkAgent::didChangeResourcePriority(
595 unsigned long identifier, 594 unsigned long identifier,
596 ResourceLoadPriority loadPriority) { 595 ResourceLoadPriority loadPriority) {
597 String requestId = IdentifiersFactory::requestId(identifier); 596 String requestId = IdentifiersFactory::requestId(identifier);
598 frontend()->resourceChangedPriority(requestId, 597 frontend()->resourceChangedPriority(requestId,
599 resourcePriorityJSON(loadPriority), 598 resourcePriorityJSON(loadPriority),
600 monotonicallyIncreasingTime()); 599 monotonicallyIncreasingTime());
601 } 600 }
602 601
603 void InspectorNetworkAgent::willSendRequestInternal( 602 void InspectorNetworkAgent::willSendRequestInternal(
604 LocalFrame* frame,
605 unsigned long identifier, 603 unsigned long identifier,
606 DocumentLoader* loader, 604 DocumentLoader* loader,
607 const ResourceRequest& request, 605 const ResourceRequest& request,
608 const ResourceResponse& redirectResponse, 606 const ResourceResponse& redirectResponse,
609 const FetchInitiatorInfo& initiatorInfo) { 607 const FetchInitiatorInfo& initiatorInfo) {
610 String requestId = IdentifiersFactory::requestId(identifier); 608 String requestId = IdentifiersFactory::requestId(identifier);
611 String loaderId = IdentifiersFactory::loaderId(loader); 609 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : "";
612 m_resourcesData->resourceCreated(requestId, loaderId, request.url()); 610 m_resourcesData->resourceCreated(requestId, loaderId, request.url());
613 611
614 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; 612 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource;
615 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { 613 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) {
616 type = InspectorPageAgent::XHRResource; 614 type = InspectorPageAgent::XHRResource;
617 m_resourcesData->setResourceType(requestId, type); 615 m_resourcesData->setResourceType(requestId, type);
618 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { 616 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
619 type = InspectorPageAgent::DocumentResource; 617 type = InspectorPageAgent::DocumentResource;
620 m_resourcesData->setResourceType(requestId, type); 618 m_resourcesData->setResourceType(requestId, type);
621 } 619 }
622 620 String frameId = loader && loader->frame()
623 String frameId = 621 ? IdentifiersFactory::frameId(loader->frame())
624 loader->frame() ? IdentifiersFactory::frameId(loader->frame()) : ""; 622 : "";
625 std::unique_ptr<protocol::Network::Initiator> initiatorObject = 623 std::unique_ptr<protocol::Network::Initiator> initiatorObject =
626 buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0, 624 buildInitiatorObject(
627 initiatorInfo); 625 loader && loader->frame() ? loader->frame()->document() : 0,
626 initiatorInfo);
628 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { 627 if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
629 FrameNavigationInitiatorMap::iterator it = 628 FrameNavigationInitiatorMap::iterator it =
630 m_frameNavigationInitiatorMap.find(frameId); 629 m_frameNavigationInitiatorMap.find(frameId);
631 if (it != m_frameNavigationInitiatorMap.end()) 630 if (it != m_frameNavigationInitiatorMap.end())
632 initiatorObject = it->value->clone(); 631 initiatorObject = it->value->clone();
633 } 632 }
634 633
635 std::unique_ptr<protocol::Network::Request> requestInfo( 634 std::unique_ptr<protocol::Network::Request> requestInfo(
636 buildObjectForResourceRequest(request)); 635 buildObjectForResourceRequest(request));
637 636
638 requestInfo->setMixedContentType(mixedContentTypeForContextType( 637 if (loader) {
639 MixedContentChecker::contextTypeForInspector(frame, request))); 638 requestInfo->setMixedContentType(mixedContentTypeForContextType(
639 MixedContentChecker::contextTypeForInspector(loader->frame(),
640 request)));
641 }
640 642
641 requestInfo->setReferrerPolicy(referrerPolicy(request.getReferrerPolicy())); 643 requestInfo->setReferrerPolicy(referrerPolicy(request.getReferrerPolicy()));
642 if (initiatorInfo.isLinkPreload) 644 if (initiatorInfo.isLinkPreload)
643 requestInfo->setIsLinkPreload(true); 645 requestInfo->setIsLinkPreload(true);
644 646
645 String resourceType = InspectorPageAgent::resourceTypeJson(type); 647 String resourceType = InspectorPageAgent::resourceTypeJson(type);
646 frontend()->requestWillBeSent( 648 frontend()->requestWillBeSent(
647 requestId, frameId, loaderId, 649 requestId, frameId, loaderId,
648 urlWithoutFragment(loader->url()).getString(), std::move(requestInfo), 650 loader ? urlWithoutFragment(loader->url()).getString() : "",
649 monotonicallyIncreasingTime(), currentTime(), std::move(initiatorObject), 651 std::move(requestInfo), monotonicallyIncreasingTime(), currentTime(),
652 std::move(initiatorObject),
650 buildObjectForResourceResponse(redirectResponse), resourceType); 653 buildObjectForResourceResponse(redirectResponse), resourceType);
651 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) 654 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async())
652 frontend()->flush(); 655 frontend()->flush();
653 } 656 }
654 657
655 void InspectorNetworkAgent::willSendRequest( 658 void InspectorNetworkAgent::willSendRequest(
656 LocalFrame* frame,
657 unsigned long identifier, 659 unsigned long identifier,
658 DocumentLoader* loader, 660 DocumentLoader* loader,
659 ResourceRequest& request, 661 ResourceRequest& request,
660 const ResourceResponse& redirectResponse, 662 const ResourceResponse& redirectResponse,
661 const FetchInitiatorInfo& initiatorInfo) { 663 const FetchInitiatorInfo& initiatorInfo) {
662 // Ignore the request initiated internally. 664 // Ignore the request initiated internally.
663 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) 665 if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
664 return; 666 return;
665 667
666 if (initiatorInfo.name == FetchInitiatorTypeNames::document && 668 if (initiatorInfo.name == FetchInitiatorTypeNames::document &&
(...skipping 19 matching lines...) Expand all
686 request.requestContext() != WebURLRequest::RequestContextInternal) { 688 request.requestContext() != WebURLRequest::RequestContextInternal) {
687 request.setCachePolicy(WebCachePolicy::BypassCacheLoadOnlyFromCache); 689 request.setCachePolicy(WebCachePolicy::BypassCacheLoadOnlyFromCache);
688 } else { 690 } else {
689 request.setCachePolicy(WebCachePolicy::BypassingCache); 691 request.setCachePolicy(WebCachePolicy::BypassingCache);
690 } 692 }
691 request.setShouldResetAppCache(true); 693 request.setShouldResetAppCache(true);
692 } 694 }
693 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false)) 695 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false))
694 request.setServiceWorkerMode(WebURLRequest::ServiceWorkerMode::None); 696 request.setServiceWorkerMode(WebURLRequest::ServiceWorkerMode::None);
695 697
696 willSendRequestInternal(frame, identifier, loader, request, redirectResponse, 698 willSendRequestInternal(identifier, loader, request, redirectResponse,
697 initiatorInfo); 699 initiatorInfo);
698 700
699 if (!m_hostId.isEmpty()) 701 if (!m_hostId.isEmpty())
700 request.addHTTPHeaderField( 702 request.addHTTPHeaderField(
701 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, 703 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id,
702 AtomicString(m_hostId)); 704 AtomicString(m_hostId));
703 705
704 request.setHTTPHeaderField( 706 request.setHTTPHeaderField(
705 HTTPNames::X_DevTools_Request_Id, 707 HTTPNames::X_DevTools_Request_Id,
706 AtomicString(IdentifiersFactory::requestId(identifier))); 708 AtomicString(IdentifiersFactory::requestId(identifier)));
707 } 709 }
708 710
709 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) { 711 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) {
710 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier)); 712 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier));
711 } 713 }
712 714
713 void InspectorNetworkAgent::didReceiveResourceResponse( 715 void InspectorNetworkAgent::didReceiveResourceResponse(
714 LocalFrame* frame,
715 unsigned long identifier, 716 unsigned long identifier,
716 DocumentLoader* loader, 717 DocumentLoader* loader,
717 const ResourceResponse& response, 718 const ResourceResponse& response,
718 Resource* cachedResource) { 719 Resource* cachedResource) {
719 String requestId = IdentifiersFactory::requestId(identifier); 720 String requestId = IdentifiersFactory::requestId(identifier);
720 bool isNotModified = response.httpStatusCode() == 304; 721 bool isNotModified = response.httpStatusCode() == 304;
721 722
722 bool resourceIsEmpty = true; 723 bool resourceIsEmpty = true;
723 std::unique_ptr<protocol::Network::Response> resourceResponse = 724 std::unique_ptr<protocol::Network::Response> resourceResponse =
724 buildObjectForResourceResponse(response, cachedResource, 725 buildObjectForResourceResponse(response, cachedResource,
(...skipping 15 matching lines...) Expand all
740 if (type == InspectorPageAgent::DocumentResource && loader && 741 if (type == InspectorPageAgent::DocumentResource && loader &&
741 loader->substituteData().isValid()) 742 loader->substituteData().isValid())
742 return; 743 return;
743 744
744 // Resources are added to NetworkResourcesData as a WeakMember here and 745 // Resources are added to NetworkResourcesData as a WeakMember here and
745 // removed in willDestroyResource() called in the prefinalizer of Resource. 746 // removed in willDestroyResource() called in the prefinalizer of Resource.
746 // Because NetworkResourceData retains weak references only, it 747 // Because NetworkResourceData retains weak references only, it
747 // doesn't affect Resource lifetime. 748 // doesn't affect Resource lifetime.
748 if (cachedResource) 749 if (cachedResource)
749 m_resourcesData->addResource(requestId, cachedResource); 750 m_resourcesData->addResource(requestId, cachedResource);
750 String frameId = IdentifiersFactory::frameId(frame); 751 String frameId = loader && loader->frame()
752 ? IdentifiersFactory::frameId(loader->frame())
753 : "";
751 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : ""; 754 String loaderId = loader ? IdentifiersFactory::loaderId(loader) : "";
752 m_resourcesData->responseReceived(requestId, frameId, response); 755 m_resourcesData->responseReceived(requestId, frameId, response);
753 m_resourcesData->setResourceType(requestId, type); 756 m_resourcesData->setResourceType(requestId, type);
754 757
755 if (response.getSecurityStyle() != ResourceResponse::SecurityStyleUnknown && 758 if (response.getSecurityStyle() != ResourceResponse::SecurityStyleUnknown &&
756 response.getSecurityStyle() != 759 response.getSecurityStyle() !=
757 ResourceResponse::SecurityStyleUnauthenticated) { 760 ResourceResponse::SecurityStyleUnauthenticated) {
758 const ResourceResponse::SecurityDetails* responseSecurityDetails = 761 const ResourceResponse::SecurityDetails* responseSecurityDetails =
759 response.getSecurityDetails(); 762 response.getSecurityDetails();
760 m_resourcesData->setCertificate(requestId, 763 m_resourcesData->setCertificate(requestId,
761 responseSecurityDetails->certificate); 764 responseSecurityDetails->certificate);
762 } 765 }
763 766
764 if (resourceResponse && !resourceIsEmpty) 767 if (resourceResponse && !resourceIsEmpty)
765 frontend()->responseReceived(requestId, frameId, loaderId, 768 frontend()->responseReceived(requestId, frameId, loaderId,
766 monotonicallyIncreasingTime(), 769 monotonicallyIncreasingTime(),
767 InspectorPageAgent::resourceTypeJson(type), 770 InspectorPageAgent::resourceTypeJson(type),
768 std::move(resourceResponse)); 771 std::move(resourceResponse));
769 // If we revalidated the resource and got Not modified, send content length 772 // If we revalidated the resource and got Not modified, send content length
770 // following didReceiveResponse as there will be no calls to didReceiveData 773 // following didReceiveResponse as there will be no calls to didReceiveData
771 // from the network stack. 774 // from the network stack.
772 if (isNotModified && cachedResource && cachedResource->encodedSize()) 775 if (isNotModified && cachedResource && cachedResource->encodedSize())
773 didReceiveData(frame, identifier, 0, cachedResource->encodedSize()); 776 didReceiveData(identifier, loader, 0, cachedResource->encodedSize());
774 } 777 }
775 778
776 static bool isErrorStatusCode(int statusCode) { 779 static bool isErrorStatusCode(int statusCode) {
777 return statusCode >= 400; 780 return statusCode >= 400;
778 } 781 }
779 782
780 void InspectorNetworkAgent::didReceiveData(LocalFrame*, 783 void InspectorNetworkAgent::didReceiveData(unsigned long identifier,
781 unsigned long identifier, 784 DocumentLoader* loader,
782 const char* data, 785 const char* data,
783 int dataLength) { 786 int dataLength) {
784 String requestId = IdentifiersFactory::requestId(identifier); 787 String requestId = IdentifiersFactory::requestId(identifier);
785 788
786 if (data) { 789 if (data) {
787 NetworkResourcesData::ResourceData const* resourceData = 790 NetworkResourcesData::ResourceData const* resourceData =
788 m_resourcesData->data(requestId); 791 m_resourcesData->data(requestId);
789 if (resourceData && 792 if (resourceData &&
790 (!resourceData->cachedResource() || 793 (!resourceData->cachedResource() ||
791 resourceData->cachedResource()->getDataBufferingPolicy() == 794 resourceData->cachedResource()->getDataBufferingPolicy() ==
792 DoNotBufferData || 795 DoNotBufferData ||
793 isErrorStatusCode(resourceData->httpStatusCode()))) 796 isErrorStatusCode(resourceData->httpStatusCode())))
794 m_resourcesData->maybeAddResourceData(requestId, data, dataLength); 797 m_resourcesData->maybeAddResourceData(requestId, data, dataLength);
795 } 798 }
796 799
797 frontend()->dataReceived( 800 frontend()->dataReceived(
798 requestId, monotonicallyIncreasingTime(), dataLength, 801 requestId, monotonicallyIncreasingTime(), dataLength,
799 m_resourcesData->getAndClearPendingEncodedDataLength(requestId)); 802 m_resourcesData->getAndClearPendingEncodedDataLength(requestId));
800 } 803 }
801 804
802 void InspectorNetworkAgent::didReceiveEncodedDataLength( 805 void InspectorNetworkAgent::didReceiveEncodedDataLength(
803 LocalFrame*,
804 unsigned long identifier, 806 unsigned long identifier,
805 int encodedDataLength) { 807 int encodedDataLength) {
806 String requestId = IdentifiersFactory::requestId(identifier); 808 String requestId = IdentifiersFactory::requestId(identifier);
807 m_resourcesData->addPendingEncodedDataLength(requestId, encodedDataLength); 809 m_resourcesData->addPendingEncodedDataLength(requestId, encodedDataLength);
808 } 810 }
809 811
810 void InspectorNetworkAgent::didFinishLoading(LocalFrame*, 812 void InspectorNetworkAgent::didFinishLoading(unsigned long identifier,
811 unsigned long identifier, 813 DocumentLoader*,
812 double monotonicFinishTime, 814 double monotonicFinishTime,
813 int64_t encodedDataLength, 815 int64_t encodedDataLength,
814 int64_t decodedBodyLength) { 816 int64_t decodedBodyLength) {
815 String requestId = IdentifiersFactory::requestId(identifier); 817 String requestId = IdentifiersFactory::requestId(identifier);
816 NetworkResourcesData::ResourceData const* resourceData = 818 NetworkResourcesData::ResourceData const* resourceData =
817 m_resourcesData->data(requestId); 819 m_resourcesData->data(requestId);
818 820
819 int pendingEncodedDataLength = 821 int pendingEncodedDataLength =
820 m_resourcesData->getAndClearPendingEncodedDataLength(requestId); 822 m_resourcesData->getAndClearPendingEncodedDataLength(requestId);
821 if (pendingEncodedDataLength > 0) { 823 if (pendingEncodedDataLength > 0) {
(...skipping 16 matching lines...) Expand all
838 encodedDataLength); 840 encodedDataLength);
839 } 841 }
840 842
841 void InspectorNetworkAgent::didReceiveCORSRedirectResponse( 843 void InspectorNetworkAgent::didReceiveCORSRedirectResponse(
842 LocalFrame* frame, 844 LocalFrame* frame,
843 unsigned long identifier, 845 unsigned long identifier,
844 DocumentLoader* loader, 846 DocumentLoader* loader,
845 const ResourceResponse& response, 847 const ResourceResponse& response,
846 Resource* resource) { 848 Resource* resource) {
847 // Update the response and finish loading 849 // Update the response and finish loading
848 didReceiveResourceResponse(frame, identifier, loader, response, resource); 850 didReceiveResourceResponse(identifier, loader, response, resource);
849 didFinishLoading(frame, identifier, 0, 851 didFinishLoading(identifier, loader, 0,
850 WebURLLoaderClient::kUnknownEncodedDataLength, 0); 852 WebURLLoaderClient::kUnknownEncodedDataLength, 0);
851 } 853 }
852 854
853 void InspectorNetworkAgent::didFailLoading(unsigned long identifier, 855 void InspectorNetworkAgent::didFailLoading(unsigned long identifier,
854 const ResourceError& error) { 856 const ResourceError& error) {
855 String requestId = IdentifiersFactory::requestId(identifier); 857 String requestId = IdentifiersFactory::requestId(identifier);
856 bool canceled = error.isCancellation(); 858 bool canceled = error.isCancellation();
857 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), 859 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(),
858 InspectorPageAgent::resourceTypeJson( 860 InspectorPageAgent::resourceTypeJson(
859 m_resourcesData->resourceType(requestId)), 861 m_resourcesData->resourceType(requestId)),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 m_pendingXHRReplayData = XHRReplayData::create( 927 m_pendingXHRReplayData = XHRReplayData::create(
926 xhr->getExecutionContext(), method, urlWithoutFragment(url), async, 928 xhr->getExecutionContext(), method, urlWithoutFragment(url), async,
927 formData.get(), includeCredentials); 929 formData.get(), includeCredentials);
928 for (const auto& header : headers) 930 for (const auto& header : headers)
929 m_pendingXHRReplayData->addHeader(header.key, header.value); 931 m_pendingXHRReplayData->addHeader(header.key, header.value);
930 } 932 }
931 933
932 void InspectorNetworkAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr) { 934 void InspectorNetworkAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr) {
933 if (!m_replayXHRs.contains(xhr)) 935 if (!m_replayXHRs.contains(xhr))
934 return; 936 return;
937 // TODO(horo): |m_removeFinishedReplayXHRTimer| is null on workers.
938 DCHECK(m_removeFinishedReplayXHRTimer);
935 m_replayXHRsToBeDeleted.insert(xhr); 939 m_replayXHRsToBeDeleted.insert(xhr);
936 m_replayXHRs.erase(xhr); 940 m_replayXHRs.erase(xhr);
937 m_removeFinishedReplayXHRTimer.startOneShot(0, BLINK_FROM_HERE); 941 m_removeFinishedReplayXHRTimer->startOneShot(0, BLINK_FROM_HERE);
938 } 942 }
939 943
940 void InspectorNetworkAgent::didFailXHRLoading(ExecutionContext* context, 944 void InspectorNetworkAgent::didFailXHRLoading(ExecutionContext* context,
941 XMLHttpRequest* xhr, 945 XMLHttpRequest* xhr,
942 ThreadableLoaderClient* client, 946 ThreadableLoaderClient* client,
943 const AtomicString& method, 947 const AtomicString& method,
944 const String& url) { 948 const String& url) {
945 didFinishXHRInternal(context, xhr, client, method, url, false); 949 didFinishXHRInternal(context, xhr, client, method, url, false);
946 } 950 }
947 951
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 else 1420 else
1417 networkStateNotifier().clearOverride(); 1421 networkStateNotifier().clearOverride();
1418 return Response::OK(); 1422 return Response::OK();
1419 } 1423 }
1420 1424
1421 Response InspectorNetworkAgent::setCacheDisabled(bool cacheDisabled) { 1425 Response InspectorNetworkAgent::setCacheDisabled(bool cacheDisabled) {
1422 // TODO(ananta) 1426 // TODO(ananta)
1423 // We should extract network cache state into a global entity which can be 1427 // We should extract network cache state into a global entity which can be
1424 // queried from FrameLoader and other places. 1428 // queried from FrameLoader and other places.
1425 m_state->setBoolean(NetworkAgentState::cacheDisabled, cacheDisabled); 1429 m_state->setBoolean(NetworkAgentState::cacheDisabled, cacheDisabled);
1426 if (cacheDisabled) 1430 if (cacheDisabled && isMainThread())
1427 memoryCache()->evictResources(); 1431 memoryCache()->evictResources();
1428 return Response::OK(); 1432 return Response::OK();
1429 } 1433 }
1430 1434
1431 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) { 1435 Response InspectorNetworkAgent::setBypassServiceWorker(bool bypass) {
1432 m_state->setBoolean(NetworkAgentState::bypassServiceWorker, bypass); 1436 m_state->setBoolean(NetworkAgentState::bypassServiceWorker, bypass);
1433 return Response::OK(); 1437 return Response::OK();
1434 } 1438 }
1435 1439
1436 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int maxTotal, 1440 Response InspectorNetworkAgent::setDataSizeLimitsForTest(int maxTotal,
(...skipping 19 matching lines...) Expand all
1456 } 1460 }
1457 } 1461 }
1458 return Response::OK(); 1462 return Response::OK();
1459 } 1463 }
1460 1464
1461 void InspectorNetworkAgent::didCommitLoad(LocalFrame* frame, 1465 void InspectorNetworkAgent::didCommitLoad(LocalFrame* frame,
1462 DocumentLoader* loader) { 1466 DocumentLoader* loader) {
1463 if (loader->frame() != m_inspectedFrames->root()) 1467 if (loader->frame() != m_inspectedFrames->root())
1464 return; 1468 return;
1465 1469
1466 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false)) 1470 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false) &&
1471 isMainThread())
1467 memoryCache()->evictResources(MemoryCache::DoNotEvictUnusedPreloads); 1472 memoryCache()->evictResources(MemoryCache::DoNotEvictUnusedPreloads);
1468 1473
1469 m_resourcesData->clear(IdentifiersFactory::loaderId(loader)); 1474 m_resourcesData->clear(IdentifiersFactory::loaderId(loader));
1470 } 1475 }
1471 1476
1472 void InspectorNetworkAgent::frameScheduledNavigation(LocalFrame* frame, 1477 void InspectorNetworkAgent::frameScheduledNavigation(LocalFrame* frame,
1473 double) { 1478 double) {
1474 String frameId = IdentifiersFactory::frameId(frame); 1479 String frameId = IdentifiersFactory::frameId(frame);
1475 m_framesWithScheduledNavigation.insert(frameId); 1480 m_framesWithScheduledNavigation.insert(frameId);
1476 if (!m_framesWithScheduledClientNavigation.contains(frameId)) { 1481 if (!m_framesWithScheduledClientNavigation.contains(frameId)) {
(...skipping 29 matching lines...) Expand all
1506 void InspectorNetworkAgent::setHostId(const String& hostId) { 1511 void InspectorNetworkAgent::setHostId(const String& hostId) {
1507 m_hostId = hostId; 1512 m_hostId = hostId;
1508 } 1513 }
1509 1514
1510 bool InspectorNetworkAgent::fetchResourceContent(Document* document, 1515 bool InspectorNetworkAgent::fetchResourceContent(Document* document,
1511 const KURL& url, 1516 const KURL& url,
1512 String* content, 1517 String* content,
1513 bool* base64Encoded) { 1518 bool* base64Encoded) {
1514 // First try to fetch content from the cached resource. 1519 // First try to fetch content from the cached resource.
1515 Resource* cachedResource = document->fetcher()->cachedResource(url); 1520 Resource* cachedResource = document->fetcher()->cachedResource(url);
1516 if (!cachedResource) 1521 if (!cachedResource && isMainThread()) {
1517 cachedResource = memoryCache()->resourceForURL( 1522 cachedResource = memoryCache()->resourceForURL(
1518 url, document->fetcher()->getCacheIdentifier()); 1523 url, document->fetcher()->getCacheIdentifier());
1524 }
1519 if (cachedResource && InspectorPageAgent::cachedResourceContent( 1525 if (cachedResource && InspectorPageAgent::cachedResourceContent(
1520 cachedResource, content, base64Encoded)) 1526 cachedResource, content, base64Encoded))
1521 return true; 1527 return true;
1522 1528
1523 // Then fall back to resource data. 1529 // Then fall back to resource data.
1524 for (auto& resource : m_resourcesData->resources()) { 1530 for (auto& resource : m_resourcesData->resources()) {
1525 if (resource->requestedURL() == url) { 1531 if (resource->requestedURL() == url) {
1526 *content = resource->content(); 1532 *content = resource->content();
1527 *base64Encoded = resource->base64Encoded(); 1533 *base64Encoded = resource->base64Encoded();
1528 return true; 1534 return true;
(...skipping 11 matching lines...) Expand all
1540 void InspectorNetworkAgent::removeFinishedReplayXHRFired(TimerBase*) { 1546 void InspectorNetworkAgent::removeFinishedReplayXHRFired(TimerBase*) {
1541 m_replayXHRsToBeDeleted.clear(); 1547 m_replayXHRsToBeDeleted.clear();
1542 } 1548 }
1543 1549
1544 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspectedFrames) 1550 InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspectedFrames)
1545 : m_inspectedFrames(inspectedFrames), 1551 : m_inspectedFrames(inspectedFrames),
1546 m_resourcesData(NetworkResourcesData::create(maximumTotalBufferSize, 1552 m_resourcesData(NetworkResourcesData::create(maximumTotalBufferSize,
1547 maximumResourceBufferSize)), 1553 maximumResourceBufferSize)),
1548 m_pendingRequest(nullptr), 1554 m_pendingRequest(nullptr),
1549 m_removeFinishedReplayXHRTimer( 1555 m_removeFinishedReplayXHRTimer(
1550 TaskRunnerHelper::get(TaskType::UnspecedLoading, 1556 inspectedFrames
1551 inspectedFrames->root()), 1557 ? new TaskRunnerTimer<InspectorNetworkAgent>(
1552 this, 1558 TaskRunnerHelper::get(TaskType::UnspecedLoading,
1553 &InspectorNetworkAgent::removeFinishedReplayXHRFired) {} 1559 inspectedFrames->root()),
1560 this,
1561 &InspectorNetworkAgent::removeFinishedReplayXHRFired)
1562 : nullptr) {}
1554 1563
1555 void InspectorNetworkAgent::shouldForceCORSPreflight(bool* result) { 1564 void InspectorNetworkAgent::shouldForceCORSPreflight(bool* result) {
1556 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false)) 1565 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false))
1557 *result = true; 1566 *result = true;
1558 } 1567 }
1559 1568
1560 } // namespace blink 1569 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698