| OLD | NEW |
| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (!document.settings()) | 128 if (!document.settings()) |
| 129 return false; | 129 return false; |
| 130 | 130 |
| 131 if (!document.frame()) | 131 if (!document.frame()) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 // Only block synchronously loaded (parser blocking) scripts. | 134 // Only block synchronously loaded (parser blocking) scripts. |
| 135 if (defer != FetchRequest::NoDefer) | 135 if (defer != FetchRequest::NoDefer) |
| 136 return false; | 136 return false; |
| 137 | 137 |
| 138 InspectorInstrumentation::documentWriteFetchScript(&document); | 138 probe::documentWriteFetchScript(&document); |
| 139 | 139 |
| 140 if (!request.url().protocolIsInHTTPFamily()) | 140 if (!request.url().protocolIsInHTTPFamily()) |
| 141 return false; | 141 return false; |
| 142 | 142 |
| 143 // Avoid blocking same origin scripts, as they may be used to render main | 143 // Avoid blocking same origin scripts, as they may be used to render main |
| 144 // page content, whereas cross-origin scripts inserted via document.write | 144 // page content, whereas cross-origin scripts inserted via document.write |
| 145 // are likely to be third party content. | 145 // are likely to be third party content. |
| 146 String requestHost = request.url().host(); | 146 String requestHost = request.url().host(); |
| 147 String documentHost = document.getSecurityOrigin()->domain(); | 147 String documentHost = document.getSecurityOrigin()->domain(); |
| 148 | 148 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 return frameOfImportsController()->loader().documentLoader(); | 410 return frameOfImportsController()->loader().documentLoader(); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void FrameFetchContext::dispatchDidChangeResourcePriority( | 413 void FrameFetchContext::dispatchDidChangeResourcePriority( |
| 414 unsigned long identifier, | 414 unsigned long identifier, |
| 415 ResourceLoadPriority loadPriority, | 415 ResourceLoadPriority loadPriority, |
| 416 int intraPriorityValue) { | 416 int intraPriorityValue) { |
| 417 TRACE_EVENT1( | 417 TRACE_EVENT1( |
| 418 "devtools.timeline", "ResourceChangePriority", "data", | 418 "devtools.timeline", "ResourceChangePriority", "data", |
| 419 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); | 419 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); |
| 420 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, | 420 probe::didChangeResourcePriority(frame(), identifier, loadPriority); |
| 421 loadPriority); | |
| 422 } | 421 } |
| 423 | 422 |
| 424 void FrameFetchContext::prepareRequest(ResourceRequest& request) { | 423 void FrameFetchContext::prepareRequest(ResourceRequest& request) { |
| 425 frame()->loader().applyUserAgent(request); | 424 frame()->loader().applyUserAgent(request); |
| 426 localFrameClient()->dispatchWillSendRequest(request); | 425 localFrameClient()->dispatchWillSendRequest(request); |
| 427 } | 426 } |
| 428 | 427 |
| 429 void FrameFetchContext::dispatchWillSendRequest( | 428 void FrameFetchContext::dispatchWillSendRequest( |
| 430 unsigned long identifier, | 429 unsigned long identifier, |
| 431 ResourceRequest& request, | 430 ResourceRequest& request, |
| 432 const ResourceResponse& redirectResponse, | 431 const ResourceResponse& redirectResponse, |
| 433 const FetchInitiatorInfo& initiatorInfo) { | 432 const FetchInitiatorInfo& initiatorInfo) { |
| 434 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data", | 433 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data", |
| 435 InspectorSendRequestEvent::data(identifier, frame(), request)); | 434 InspectorSendRequestEvent::data(identifier, frame(), request)); |
| 436 // For initial requests, prepareRequest() is called in | 435 // For initial requests, prepareRequest() is called in |
| 437 // willStartLoadingResource(), before revalidation policy is determined. That | 436 // willStartLoadingResource(), before revalidation policy is determined. That |
| 438 // call doesn't exist for redirects, so call preareRequest() here. | 437 // call doesn't exist for redirects, so call preareRequest() here. |
| 439 if (!redirectResponse.isNull()) { | 438 if (!redirectResponse.isNull()) { |
| 440 prepareRequest(request); | 439 prepareRequest(request); |
| 441 } else { | 440 } else { |
| 442 frame()->loader().progress().willStartLoading(identifier, | 441 frame()->loader().progress().willStartLoading(identifier, |
| 443 request.priority()); | 442 request.priority()); |
| 444 } | 443 } |
| 445 InspectorInstrumentation::willSendRequest(frame(), identifier, | 444 probe::willSendRequest(frame(), identifier, masterDocumentLoader(), request, |
| 446 masterDocumentLoader(), request, | 445 redirectResponse, initiatorInfo); |
| 447 redirectResponse, initiatorInfo); | |
| 448 if (frame()->frameScheduler()) | 446 if (frame()->frameScheduler()) |
| 449 frame()->frameScheduler()->didStartLoading(identifier); | 447 frame()->frameScheduler()->didStartLoading(identifier); |
| 450 } | 448 } |
| 451 | 449 |
| 452 void FrameFetchContext::dispatchDidReceiveResponse( | 450 void FrameFetchContext::dispatchDidReceiveResponse( |
| 453 unsigned long identifier, | 451 unsigned long identifier, |
| 454 const ResourceResponse& response, | 452 const ResourceResponse& response, |
| 455 WebURLRequest::FrameType frameType, | 453 WebURLRequest::FrameType frameType, |
| 456 WebURLRequest::RequestContext requestContext, | 454 WebURLRequest::RequestContext requestContext, |
| 457 Resource* resource) { | 455 Resource* resource) { |
| 458 dispatchDidReceiveResponseInternal(identifier, response, frameType, | 456 dispatchDidReceiveResponseInternal(identifier, response, frameType, |
| 459 requestContext, resource, | 457 requestContext, resource, |
| 460 LinkLoader::LoadResourcesAndPreconnect); | 458 LinkLoader::LoadResourcesAndPreconnect); |
| 461 } | 459 } |
| 462 | 460 |
| 463 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, | 461 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, |
| 464 const char* data, | 462 const char* data, |
| 465 int dataLength) { | 463 int dataLength) { |
| 466 frame()->loader().progress().incrementProgress(identifier, dataLength); | 464 frame()->loader().progress().incrementProgress(identifier, dataLength); |
| 467 InspectorInstrumentation::didReceiveData(frame(), identifier, data, | 465 probe::didReceiveData(frame(), identifier, data, dataLength); |
| 468 dataLength); | |
| 469 } | 466 } |
| 470 | 467 |
| 471 void FrameFetchContext::dispatchDidReceiveEncodedData(unsigned long identifier, | 468 void FrameFetchContext::dispatchDidReceiveEncodedData(unsigned long identifier, |
| 472 int encodedDataLength) { | 469 int encodedDataLength) { |
| 473 TRACE_EVENT1( | 470 TRACE_EVENT1( |
| 474 "devtools.timeline", "ResourceReceivedData", "data", | 471 "devtools.timeline", "ResourceReceivedData", "data", |
| 475 InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength)); | 472 InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength)); |
| 476 InspectorInstrumentation::didReceiveEncodedDataLength(frame(), identifier, | 473 probe::didReceiveEncodedDataLength(frame(), identifier, encodedDataLength); |
| 477 encodedDataLength); | |
| 478 } | 474 } |
| 479 | 475 |
| 480 void FrameFetchContext::dispatchDidDownloadData(unsigned long identifier, | 476 void FrameFetchContext::dispatchDidDownloadData(unsigned long identifier, |
| 481 int dataLength, | 477 int dataLength, |
| 482 int encodedDataLength) { | 478 int encodedDataLength) { |
| 483 TRACE_EVENT1( | 479 TRACE_EVENT1( |
| 484 "devtools.timeline", "ResourceReceivedData", "data", | 480 "devtools.timeline", "ResourceReceivedData", "data", |
| 485 InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength)); | 481 InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength)); |
| 486 frame()->loader().progress().incrementProgress(identifier, dataLength); | 482 frame()->loader().progress().incrementProgress(identifier, dataLength); |
| 487 InspectorInstrumentation::didReceiveData(frame(), identifier, 0, dataLength); | 483 probe::didReceiveData(frame(), identifier, 0, dataLength); |
| 488 InspectorInstrumentation::didReceiveEncodedDataLength(frame(), identifier, | 484 probe::didReceiveEncodedDataLength(frame(), identifier, encodedDataLength); |
| 489 encodedDataLength); | |
| 490 } | 485 } |
| 491 | 486 |
| 492 void FrameFetchContext::dispatchDidFinishLoading(unsigned long identifier, | 487 void FrameFetchContext::dispatchDidFinishLoading(unsigned long identifier, |
| 493 double finishTime, | 488 double finishTime, |
| 494 int64_t encodedDataLength, | 489 int64_t encodedDataLength, |
| 495 int64_t decodedBodyLength) { | 490 int64_t decodedBodyLength) { |
| 496 TRACE_EVENT1( | 491 TRACE_EVENT1( |
| 497 "devtools.timeline", "ResourceFinish", "data", | 492 "devtools.timeline", "ResourceFinish", "data", |
| 498 InspectorResourceFinishEvent::data(identifier, finishTime, false, | 493 InspectorResourceFinishEvent::data(identifier, finishTime, false, |
| 499 encodedDataLength, decodedBodyLength)); | 494 encodedDataLength, decodedBodyLength)); |
| 500 frame()->loader().progress().completeProgress(identifier); | 495 frame()->loader().progress().completeProgress(identifier); |
| 501 InspectorInstrumentation::didFinishLoading(frame(), identifier, finishTime, | 496 probe::didFinishLoading(frame(), identifier, finishTime, encodedDataLength); |
| 502 encodedDataLength); | |
| 503 if (frame()->frameScheduler()) | 497 if (frame()->frameScheduler()) |
| 504 frame()->frameScheduler()->didStopLoading(identifier); | 498 frame()->frameScheduler()->didStopLoading(identifier); |
| 505 } | 499 } |
| 506 | 500 |
| 507 void FrameFetchContext::dispatchDidFail(unsigned long identifier, | 501 void FrameFetchContext::dispatchDidFail(unsigned long identifier, |
| 508 const ResourceError& error, | 502 const ResourceError& error, |
| 509 int64_t encodedDataLength, | 503 int64_t encodedDataLength, |
| 510 bool isInternalRequest) { | 504 bool isInternalRequest) { |
| 511 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 505 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 512 InspectorResourceFinishEvent::data(identifier, 0, true, | 506 InspectorResourceFinishEvent::data(identifier, 0, true, |
| 513 encodedDataLength, 0)); | 507 encodedDataLength, 0)); |
| 514 frame()->loader().progress().completeProgress(identifier); | 508 frame()->loader().progress().completeProgress(identifier); |
| 515 InspectorInstrumentation::didFailLoading(frame(), identifier, error); | 509 probe::didFailLoading(frame(), identifier, error); |
| 516 // Notification to FrameConsole should come AFTER InspectorInstrumentation | 510 // Notification to FrameConsole should come AFTER InspectorInstrumentation |
| 517 // call, DevTools front-end relies on this. | 511 // call, DevTools front-end relies on this. |
| 518 if (!isInternalRequest) | 512 if (!isInternalRequest) |
| 519 frame()->console().didFailLoading(identifier, error); | 513 frame()->console().didFailLoading(identifier, error); |
| 520 if (frame()->frameScheduler()) | 514 if (frame()->frameScheduler()) |
| 521 frame()->frameScheduler()->didStopLoading(identifier); | 515 frame()->frameScheduler()->didStopLoading(identifier); |
| 522 } | 516 } |
| 523 | 517 |
| 524 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( | 518 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( |
| 525 unsigned long identifier, | 519 unsigned long identifier, |
| 526 Resource* resource, | 520 Resource* resource, |
| 527 WebURLRequest::FrameType frameType, | 521 WebURLRequest::FrameType frameType, |
| 528 WebURLRequest::RequestContext requestContext) { | 522 WebURLRequest::RequestContext requestContext) { |
| 529 ResourceRequest request(resource->url()); | 523 ResourceRequest request(resource->url()); |
| 530 request.setFrameType(frameType); | 524 request.setFrameType(frameType); |
| 531 request.setRequestContext(requestContext); | 525 request.setRequestContext(requestContext); |
| 532 localFrameClient()->dispatchDidLoadResourceFromMemoryCache( | 526 localFrameClient()->dispatchDidLoadResourceFromMemoryCache( |
| 533 request, resource->response()); | 527 request, resource->response()); |
| 534 dispatchWillSendRequest(identifier, request, ResourceResponse(), | 528 dispatchWillSendRequest(identifier, request, ResourceResponse(), |
| 535 resource->options().initiatorInfo); | 529 resource->options().initiatorInfo); |
| 536 | 530 |
| 537 InspectorInstrumentation::markResourceAsCached(frame(), identifier); | 531 probe::markResourceAsCached(frame(), identifier); |
| 538 if (!resource->response().isNull()) { | 532 if (!resource->response().isNull()) { |
| 539 dispatchDidReceiveResponseInternal(identifier, resource->response(), | 533 dispatchDidReceiveResponseInternal(identifier, resource->response(), |
| 540 frameType, requestContext, resource, | 534 frameType, requestContext, resource, |
| 541 LinkLoader::DoNotLoadResources); | 535 LinkLoader::DoNotLoadResources); |
| 542 } | 536 } |
| 543 | 537 |
| 544 if (resource->encodedSize() > 0) | 538 if (resource->encodedSize() > 0) |
| 545 dispatchDidReceiveData(identifier, 0, resource->encodedSize()); | 539 dispatchDidReceiveData(identifier, 0, resource->encodedSize()); |
| 546 | 540 |
| 547 dispatchDidFinishLoading(identifier, 0, 0, | 541 dispatchDidFinishLoading(identifier, 0, 0, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 const ResourceRequest& resourceRequest, | 649 const ResourceRequest& resourceRequest, |
| 656 const KURL& url, | 650 const KURL& url, |
| 657 const ResourceLoaderOptions& options, | 651 const ResourceLoaderOptions& options, |
| 658 SecurityViolationReportingPolicy reportingPolicy, | 652 SecurityViolationReportingPolicy reportingPolicy, |
| 659 FetchRequest::OriginRestriction originRestriction) const { | 653 FetchRequest::OriginRestriction originRestriction) const { |
| 660 ResourceRequestBlockedReason blockedReason = | 654 ResourceRequestBlockedReason blockedReason = |
| 661 canRequestInternal(type, resourceRequest, url, options, reportingPolicy, | 655 canRequestInternal(type, resourceRequest, url, options, reportingPolicy, |
| 662 originRestriction, resourceRequest.redirectStatus()); | 656 originRestriction, resourceRequest.redirectStatus()); |
| 663 if (blockedReason != ResourceRequestBlockedReason::None && | 657 if (blockedReason != ResourceRequestBlockedReason::None && |
| 664 reportingPolicy == SecurityViolationReportingPolicy::Report) { | 658 reportingPolicy == SecurityViolationReportingPolicy::Report) { |
| 665 InspectorInstrumentation::didBlockRequest( | 659 probe::didBlockRequest(frame(), resourceRequest, masterDocumentLoader(), |
| 666 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo, | 660 options.initiatorInfo, blockedReason); |
| 667 blockedReason); | |
| 668 } | 661 } |
| 669 return blockedReason; | 662 return blockedReason; |
| 670 } | 663 } |
| 671 | 664 |
| 672 ResourceRequestBlockedReason FrameFetchContext::allowResponse( | 665 ResourceRequestBlockedReason FrameFetchContext::allowResponse( |
| 673 Resource::Type type, | 666 Resource::Type type, |
| 674 const ResourceRequest& resourceRequest, | 667 const ResourceRequest& resourceRequest, |
| 675 const KURL& url, | 668 const KURL& url, |
| 676 const ResourceLoaderOptions& options) const { | 669 const ResourceLoaderOptions& options) const { |
| 677 ResourceRequestBlockedReason blockedReason = | 670 ResourceRequestBlockedReason blockedReason = |
| 678 canRequestInternal(type, resourceRequest, url, options, | 671 canRequestInternal(type, resourceRequest, url, options, |
| 679 SecurityViolationReportingPolicy::Report, | 672 SecurityViolationReportingPolicy::Report, |
| 680 FetchRequest::UseDefaultOriginRestrictionForType, | 673 FetchRequest::UseDefaultOriginRestrictionForType, |
| 681 RedirectStatus::FollowedRedirect); | 674 RedirectStatus::FollowedRedirect); |
| 682 if (blockedReason != ResourceRequestBlockedReason::None) { | 675 if (blockedReason != ResourceRequestBlockedReason::None) { |
| 683 InspectorInstrumentation::didBlockRequest( | 676 probe::didBlockRequest(frame(), resourceRequest, masterDocumentLoader(), |
| 684 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo, | 677 options.initiatorInfo, blockedReason); |
| 685 blockedReason); | |
| 686 } | 678 } |
| 687 return blockedReason; | 679 return blockedReason; |
| 688 } | 680 } |
| 689 | 681 |
| 690 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal( | 682 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal( |
| 691 Resource::Type type, | 683 Resource::Type type, |
| 692 const ResourceRequest& resourceRequest, | 684 const ResourceRequest& resourceRequest, |
| 693 const KURL& url, | 685 const KURL& url, |
| 694 const ResourceLoaderOptions& options, | 686 const ResourceLoaderOptions& options, |
| 695 SecurityViolationReportingPolicy reportingPolicy, | 687 SecurityViolationReportingPolicy reportingPolicy, |
| 696 FetchRequest::OriginRestriction originRestriction, | 688 FetchRequest::OriginRestriction originRestriction, |
| 697 ResourceRequest::RedirectStatus redirectStatus) const { | 689 ResourceRequest::RedirectStatus redirectStatus) const { |
| 698 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) | 690 if (probe::shouldBlockRequest(frame(), resourceRequest)) |
| 699 return ResourceRequestBlockedReason::Inspector; | 691 return ResourceRequestBlockedReason::Inspector; |
| 700 | 692 |
| 701 SecurityOrigin* securityOrigin = options.securityOrigin.get(); | 693 SecurityOrigin* securityOrigin = options.securityOrigin.get(); |
| 702 if (!securityOrigin && m_document) | 694 if (!securityOrigin && m_document) |
| 703 securityOrigin = m_document->getSecurityOrigin(); | 695 securityOrigin = m_document->getSecurityOrigin(); |
| 704 | 696 |
| 705 if (originRestriction != FetchRequest::NoOriginRestriction && | 697 if (originRestriction != FetchRequest::NoOriginRestriction && |
| 706 securityOrigin && !securityOrigin->canDisplay(url)) { | 698 securityOrigin && !securityOrigin->canDisplay(url)) { |
| 707 if (reportingPolicy == SecurityViolationReportingPolicy::Report) | 699 if (reportingPolicy == SecurityViolationReportingPolicy::Report) |
| 708 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); | 700 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 LinkLoader::LoadAll, nullptr); | 1068 LinkLoader::LoadAll, nullptr); |
| 1077 | 1069 |
| 1078 if (response.hasMajorCertificateErrors()) { | 1070 if (response.hasMajorCertificateErrors()) { |
| 1079 MixedContentChecker::handleCertificateError(frame(), response, frameType, | 1071 MixedContentChecker::handleCertificateError(frame(), response, frameType, |
| 1080 requestContext); | 1072 requestContext); |
| 1081 } | 1073 } |
| 1082 | 1074 |
| 1083 frame()->loader().progress().incrementProgress(identifier, response); | 1075 frame()->loader().progress().incrementProgress(identifier, response); |
| 1084 localFrameClient()->dispatchDidReceiveResponse(response); | 1076 localFrameClient()->dispatchDidReceiveResponse(response); |
| 1085 DocumentLoader* documentLoader = masterDocumentLoader(); | 1077 DocumentLoader* documentLoader = masterDocumentLoader(); |
| 1086 InspectorInstrumentation::didReceiveResourceResponse( | 1078 probe::didReceiveResourceResponse(frame(), identifier, documentLoader, |
| 1087 frame(), identifier, documentLoader, response, resource); | 1079 response, resource); |
| 1088 // It is essential that inspector gets resource response BEFORE console. | 1080 // It is essential that inspector gets resource response BEFORE console. |
| 1089 frame()->console().reportResourceResponseReceived(documentLoader, identifier, | 1081 frame()->console().reportResourceResponseReceived(documentLoader, identifier, |
| 1090 response); | 1082 response); |
| 1091 } | 1083 } |
| 1092 | 1084 |
| 1093 DEFINE_TRACE(FrameFetchContext) { | 1085 DEFINE_TRACE(FrameFetchContext) { |
| 1094 visitor->trace(m_document); | 1086 visitor->trace(m_document); |
| 1095 visitor->trace(m_documentLoader); | 1087 visitor->trace(m_documentLoader); |
| 1096 FetchContext::trace(visitor); | 1088 FetchContext::trace(visitor); |
| 1097 } | 1089 } |
| 1098 | 1090 |
| 1099 } // namespace blink | 1091 } // namespace blink |
| OLD | NEW |