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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2751143003: Move FrameFetchContext::dispatchDidLoadResourceFromMemoryCache logic into ResourceFetcher (Closed)
Patch Set: . Created 3 years, 9 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 redirectResponse, initiatorInfo); 451 redirectResponse, initiatorInfo);
452 if (frame()->frameScheduler()) 452 if (frame()->frameScheduler())
453 frame()->frameScheduler()->didStartLoading(identifier); 453 frame()->frameScheduler()->didStartLoading(identifier);
454 } 454 }
455 455
456 void FrameFetchContext::dispatchDidReceiveResponse( 456 void FrameFetchContext::dispatchDidReceiveResponse(
457 unsigned long identifier, 457 unsigned long identifier,
458 const ResourceResponse& response, 458 const ResourceResponse& response,
459 WebURLRequest::FrameType frameType, 459 WebURLRequest::FrameType frameType,
460 WebURLRequest::RequestContext requestContext, 460 WebURLRequest::RequestContext requestContext,
461 Resource* resource) { 461 Resource* resource,
462 dispatchDidReceiveResponseInternal(identifier, response, frameType, 462 ResourceLoadStartType startType) {
463 requestContext, resource, 463 if (startType == ResourceLoadStartType::kFromMemoryCache) {
464 LinkLoader::LoadResourcesAndPreconnect); 464 probe::markResourceAsCached(frame(), identifier);
Nate Chapin 2017/03/22 19:02:02 Is it important to do this after dispatchDidLoadRe
kinuko 2017/03/24 13:51:51 I tried it in my initial patch, but if we reverse
465 if (response.isNull())
466 return;
467 }
468
kinuko 2017/03/22 14:13:26 Code below is basically same as what dispatchDidRe
469 MixedContentChecker::checkMixedPrivatePublic(frame(),
470 response.remoteIPAddress());
471 LinkLoader::CanLoadResources resourceLoadingPolicy =
472 startType == ResourceLoadStartType::kFromMemoryCache
473 ? LinkLoader::DoNotLoadResources
474 : LinkLoader::LoadResourcesAndPreconnect;
475 if (m_documentLoader &&
476 m_documentLoader ==
477 m_documentLoader->frame()->loader().provisionalDocumentLoader()) {
478 FrameClientHintsPreferencesContext hintsContext(frame());
479 m_documentLoader->clientHintsPreferences()
480 .updateFromAcceptClientHintsHeader(
481 response.httpHeaderField(HTTPNames::Accept_CH), &hintsContext);
482 // When response is received with a provisional docloader, the resource
483 // haven't committed yet, and we cannot load resources, only preconnect.
484 resourceLoadingPolicy = LinkLoader::DoNotLoadResources;
485 }
486 LinkLoader::loadLinksFromHeader(
487 response.httpHeaderField(HTTPNames::Link), response.url(),
488 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy,
489 LinkLoader::LoadAll, nullptr);
490
491 if (response.hasMajorCertificateErrors()) {
492 MixedContentChecker::handleCertificateError(frame(), response, frameType,
493 requestContext);
494 }
495
496 frame()->loader().progress().incrementProgress(identifier, response);
497 localFrameClient()->dispatchDidReceiveResponse(response);
498 DocumentLoader* documentLoader = masterDocumentLoader();
499 probe::didReceiveResourceResponse(frame(), identifier, documentLoader,
500 response, resource);
501 // It is essential that inspector gets resource response BEFORE console.
502 frame()->console().reportResourceResponseReceived(documentLoader, identifier,
503 response);
465 } 504 }
466 505
467 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, 506 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier,
468 const char* data, 507 const char* data,
469 int dataLength) { 508 int dataLength) {
470 frame()->loader().progress().incrementProgress(identifier, dataLength); 509 frame()->loader().progress().incrementProgress(identifier, dataLength);
471 probe::didReceiveData(frame(), identifier, data, dataLength); 510 probe::didReceiveData(frame(), identifier, data, dataLength);
472 } 511 }
473 512
474 void FrameFetchContext::dispatchDidReceiveEncodedData(unsigned long identifier, 513 void FrameFetchContext::dispatchDidReceiveEncodedData(unsigned long identifier,
(...skipping 29 matching lines...) Expand all
504 // Notification to FrameConsole should come AFTER InspectorInstrumentation 543 // Notification to FrameConsole should come AFTER InspectorInstrumentation
505 // call, DevTools front-end relies on this. 544 // call, DevTools front-end relies on this.
506 if (!isInternalRequest) 545 if (!isInternalRequest)
507 frame()->console().didFailLoading(identifier, error); 546 frame()->console().didFailLoading(identifier, error);
508 if (frame()->frameScheduler()) 547 if (frame()->frameScheduler())
509 frame()->frameScheduler()->didStopLoading(identifier); 548 frame()->frameScheduler()->didStopLoading(identifier);
510 } 549 }
511 550
512 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( 551 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache(
513 unsigned long identifier, 552 unsigned long identifier,
514 Resource* resource, 553 const ResourceRequest& resourceRequest,
515 WebURLRequest::FrameType frameType, 554 const ResourceResponse& resourceResponse) {
516 WebURLRequest::RequestContext requestContext) { 555 localFrameClient()->dispatchDidLoadResourceFromMemoryCache(resourceRequest,
517 ResourceRequest request(resource->url()); 556 resourceResponse);
kinuko 2017/03/22 14:13:26 Moved most of the code in this method out of Fetch
518 request.setFrameType(frameType);
519 request.setRequestContext(requestContext);
520 localFrameClient()->dispatchDidLoadResourceFromMemoryCache(
521 request, resource->response());
522 dispatchWillSendRequest(identifier, request, ResourceResponse(),
523 resource->options().initiatorInfo);
524 probe::markResourceAsCached(frame(), identifier);
525 if (!resource->response().isNull()) {
526 dispatchDidReceiveResponseInternal(identifier, resource->response(),
527 frameType, requestContext, resource,
528 LinkLoader::DoNotLoadResources);
529 }
530
531 if (resource->encodedSize() > 0)
532 dispatchDidReceiveData(identifier, 0, resource->encodedSize());
533
534 dispatchDidFinishLoading(identifier, 0, 0,
535 resource->response().decodedBodyLength());
536 } 557 }
537 558
538 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const { 559 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const {
539 if (!m_documentLoader) 560 if (!m_documentLoader)
540 return true; 561 return true;
541 562
542 FrameLoader& loader = m_documentLoader->frame()->loader(); 563 FrameLoader& loader = m_documentLoader->frame()->loader();
543 if (type == Resource::MainResource) 564 if (type == Resource::MainResource)
544 return m_documentLoader == loader.provisionalDocumentLoader(); 565 return m_documentLoader == loader.provisionalDocumentLoader();
545 return m_documentLoader == loader.documentLoader(); 566 return m_documentLoader == loader.documentLoader();
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 if (frame()->settings()->getLowPriorityIframes() && !frame()->isMainFrame()) 1031 if (frame()->settings()->getLowPriorityIframes() && !frame()->isMainFrame())
1011 return ResourceLoadPriorityVeryLow; 1032 return ResourceLoadPriorityVeryLow;
1012 1033
1013 return priority; 1034 return priority;
1014 } 1035 }
1015 1036
1016 RefPtr<WebTaskRunner> FrameFetchContext::loadingTaskRunner() const { 1037 RefPtr<WebTaskRunner> FrameFetchContext::loadingTaskRunner() const {
1017 return frame()->frameScheduler()->loadingTaskRunner(); 1038 return frame()->frameScheduler()->loadingTaskRunner();
1018 } 1039 }
1019 1040
1020 void FrameFetchContext::dispatchDidReceiveResponseInternal(
1021 unsigned long identifier,
1022 const ResourceResponse& response,
1023 WebURLRequest::FrameType frameType,
1024 WebURLRequest::RequestContext requestContext,
1025 Resource* resource,
1026 LinkLoader::CanLoadResources resourceLoadingPolicy) {
1027 MixedContentChecker::checkMixedPrivatePublic(frame(),
1028 response.remoteIPAddress());
1029 if (m_documentLoader &&
1030 m_documentLoader ==
1031 m_documentLoader->frame()->loader().provisionalDocumentLoader()) {
1032 FrameClientHintsPreferencesContext hintsContext(frame());
1033 m_documentLoader->clientHintsPreferences()
1034 .updateFromAcceptClientHintsHeader(
1035 response.httpHeaderField(HTTPNames::Accept_CH), &hintsContext);
1036 // When response is received with a provisional docloader, the resource
1037 // haven't committed yet, and we cannot load resources, only preconnect.
1038 resourceLoadingPolicy = LinkLoader::DoNotLoadResources;
1039 }
1040 LinkLoader::loadLinksFromHeader(
1041 response.httpHeaderField(HTTPNames::Link), response.url(),
1042 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy,
1043 LinkLoader::LoadAll, nullptr);
1044
1045 if (response.hasMajorCertificateErrors()) {
1046 MixedContentChecker::handleCertificateError(frame(), response, frameType,
1047 requestContext);
1048 }
1049
1050 frame()->loader().progress().incrementProgress(identifier, response);
1051 localFrameClient()->dispatchDidReceiveResponse(response);
1052 DocumentLoader* documentLoader = masterDocumentLoader();
1053 probe::didReceiveResourceResponse(frame(), identifier, documentLoader,
1054 response, resource);
1055 // It is essential that inspector gets resource response BEFORE console.
1056 frame()->console().reportResourceResponseReceived(documentLoader, identifier,
1057 response);
1058 }
1059
1060 DEFINE_TRACE(FrameFetchContext) { 1041 DEFINE_TRACE(FrameFetchContext) {
1061 visitor->trace(m_document); 1042 visitor->trace(m_document);
1062 visitor->trace(m_documentLoader); 1043 visitor->trace(m_documentLoader);
1063 FetchContext::trace(visitor); 1044 FetchContext::trace(visitor);
1064 } 1045 }
1065 1046
1066 } // namespace blink 1047 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698