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

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

Issue 2557053002: Use LocalFrame::client() than getting the FrameLoader and then call client() on it. (Closed)
Patch Set: Rebase Created 3 years, 11 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // Add the metadata that this page has scripts inserted via document.write 178 // Add the metadata that this page has scripts inserted via document.write
179 // that are eligible for blocking. Note that if there are multiple scripts 179 // that are eligible for blocking. Note that if there are multiple scripts
180 // the flag will be conveyed to the browser process only once. 180 // the flag will be conveyed to the browser process only once.
181 document.loader()->didObserveLoadingBehavior( 181 document.loader()->didObserveLoadingBehavior(
182 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlock); 182 WebLoadingBehaviorFlag::WebLoadingBehaviorDocumentWriteBlock);
183 183
184 const bool is2G = 184 const bool is2G =
185 networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; 185 networkStateNotifier().connectionType() == WebConnectionTypeCellular2G;
186 WebEffectiveConnectionType effectiveConnection = 186 WebEffectiveConnectionType effectiveConnection =
187 document.frame()->loader().client()->getEffectiveConnectionType(); 187 document.frame()->client()->getEffectiveConnectionType();
188 const bool is2GOrLike2G = 188 const bool is2GOrLike2G =
189 is2G || isConnectionEffectively2G(effectiveConnection); 189 is2G || isConnectionEffectively2G(effectiveConnection);
190 190
191 return document.settings() 191 return document.settings()
192 ->getDisallowFetchForDocWrittenScriptsInMainFrame() || 192 ->getDisallowFetchForDocWrittenScriptsInMainFrame() ||
193 (document.settings() 193 (document.settings()
194 ->getDisallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections () && 194 ->getDisallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections () &&
195 is2G) || 195 is2G) ||
196 (document.settings() 196 (document.settings()
197 ->getDisallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G() && 197 ->getDisallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G() &&
(...skipping 23 matching lines...) Expand all
221 221
222 LocalFrame* FrameFetchContext::frame() const { 222 LocalFrame* FrameFetchContext::frame() const {
223 if (!m_documentLoader) 223 if (!m_documentLoader)
224 return frameOfImportsController(); 224 return frameOfImportsController();
225 225
226 LocalFrame* frame = m_documentLoader->frame(); 226 LocalFrame* frame = m_documentLoader->frame();
227 DCHECK(frame); 227 DCHECK(frame);
228 return frame; 228 return frame;
229 } 229 }
230 230
231 FrameLoaderClient* FrameFetchContext::frameLoaderClient() const {
232 return frame()->client();
233 }
234
231 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, 235 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request,
232 FetchResourceType type) { 236 FetchResourceType type) {
233 bool isMainResource = type == FetchMainResource; 237 bool isMainResource = type == FetchMainResource;
234 if (!isMainResource) { 238 if (!isMainResource) {
235 if (!request.didSetHTTPReferrer()) { 239 if (!request.didSetHTTPReferrer()) {
236 DCHECK(m_document); 240 DCHECK(m_document);
237 request.setHTTPReferrer(SecurityPolicy::generateReferrer( 241 request.setHTTPReferrer(SecurityPolicy::generateReferrer(
238 m_document->getReferrerPolicy(), request.url(), 242 m_document->getReferrerPolicy(), request.url(),
239 m_document->outgoingReferrer())); 243 m_document->outgoingReferrer()));
240 request.addHTTPOriginIfNeeded(m_document->getSecurityOrigin()); 244 request.addHTTPOriginIfNeeded(m_document->getSecurityOrigin());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 int intraPriorityValue) { 388 int intraPriorityValue) {
385 TRACE_EVENT1( 389 TRACE_EVENT1(
386 "devtools.timeline", "ResourceChangePriority", "data", 390 "devtools.timeline", "ResourceChangePriority", "data",
387 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); 391 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority));
388 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, 392 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier,
389 loadPriority); 393 loadPriority);
390 } 394 }
391 395
392 void FrameFetchContext::prepareRequest(ResourceRequest& request) { 396 void FrameFetchContext::prepareRequest(ResourceRequest& request) {
393 frame()->loader().applyUserAgent(request); 397 frame()->loader().applyUserAgent(request);
394 frame()->loader().client()->dispatchWillSendRequest(request); 398 frameLoaderClient()->dispatchWillSendRequest(request);
395 } 399 }
396 400
397 void FrameFetchContext::dispatchWillSendRequest( 401 void FrameFetchContext::dispatchWillSendRequest(
398 unsigned long identifier, 402 unsigned long identifier,
399 ResourceRequest& request, 403 ResourceRequest& request,
400 const ResourceResponse& redirectResponse, 404 const ResourceResponse& redirectResponse,
401 const FetchInitiatorInfo& initiatorInfo) { 405 const FetchInitiatorInfo& initiatorInfo) {
402 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data", 406 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data",
403 InspectorSendRequestEvent::data(identifier, frame(), request)); 407 InspectorSendRequestEvent::data(identifier, frame(), request));
404 // For initial requests, prepareRequest() is called in 408 // For initial requests, prepareRequest() is called in
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 492 }
489 493
490 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( 494 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache(
491 unsigned long identifier, 495 unsigned long identifier,
492 Resource* resource, 496 Resource* resource,
493 WebURLRequest::FrameType frameType, 497 WebURLRequest::FrameType frameType,
494 WebURLRequest::RequestContext requestContext) { 498 WebURLRequest::RequestContext requestContext) {
495 ResourceRequest request(resource->url()); 499 ResourceRequest request(resource->url());
496 request.setFrameType(frameType); 500 request.setFrameType(frameType);
497 request.setRequestContext(requestContext); 501 request.setRequestContext(requestContext);
498 frame()->loader().client()->dispatchDidLoadResourceFromMemoryCache( 502 frameLoaderClient()->dispatchDidLoadResourceFromMemoryCache(
499 request, resource->response()); 503 request, resource->response());
500 dispatchWillSendRequest(identifier, request, ResourceResponse(), 504 dispatchWillSendRequest(identifier, request, ResourceResponse(),
501 resource->options().initiatorInfo); 505 resource->options().initiatorInfo);
502 506
503 InspectorInstrumentation::markResourceAsCached(frame(), identifier); 507 InspectorInstrumentation::markResourceAsCached(frame(), identifier);
504 if (!resource->response().isNull()) { 508 if (!resource->response().isNull()) {
505 dispatchDidReceiveResponseInternal(identifier, resource->response(), 509 dispatchDidReceiveResponseInternal(identifier, resource->response(),
506 frameType, requestContext, resource, 510 frameType, requestContext, resource,
507 LinkLoader::DoNotLoadResources); 511 LinkLoader::DoNotLoadResources);
508 } 512 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 Document* initiatorDocument = m_document && info.isMainResource() 588 Document* initiatorDocument = m_document && info.isMainResource()
585 ? m_document->parentDocument() 589 ? m_document->parentDocument()
586 : m_document.get(); 590 : m_document.get();
587 if (!initiatorDocument || !initiatorDocument->domWindow()) 591 if (!initiatorDocument || !initiatorDocument->domWindow())
588 return; 592 return;
589 DOMWindowPerformance::performance(*initiatorDocument->domWindow()) 593 DOMWindowPerformance::performance(*initiatorDocument->domWindow())
590 ->addResourceTiming(info); 594 ->addResourceTiming(info);
591 } 595 }
592 596
593 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const { 597 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const {
594 return frame()->loader().client()->allowImage(imagesEnabled, url); 598 return frameLoaderClient()->allowImage(imagesEnabled, url);
595 } 599 }
596 600
597 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const { 601 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const {
598 if (url.isNull()) 602 if (url.isNull())
599 return; 603 return;
600 604
601 String message; 605 String message;
602 if (!m_document || m_document->url().isNull()) { 606 if (!m_document || m_document->url().isNull()) {
603 message = "Unsafe attempt to load URL " + url.elidedString() + '.'; 607 message = "Unsafe attempt to load URL " + url.elidedString() + '.';
604 } else if (url.isLocalFile() || m_document->url().isLocalFile()) { 608 } else if (url.isLocalFile() || m_document->url().isLocalFile()) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 if (!shouldBypassMainWorldCSP && 729 if (!shouldBypassMainWorldCSP &&
726 !m_document->contentSecurityPolicy()->allowRequest( 730 !m_document->contentSecurityPolicy()->allowRequest(
727 resourceRequest.requestContext(), url, 731 resourceRequest.requestContext(), url,
728 options.contentSecurityPolicyNonce, options.integrityMetadata, 732 options.contentSecurityPolicyNonce, options.integrityMetadata,
729 options.parserDisposition, redirectStatus, cspReporting)) 733 options.parserDisposition, redirectStatus, cspReporting))
730 return ResourceRequestBlockedReason::CSP; 734 return ResourceRequestBlockedReason::CSP;
731 } 735 }
732 736
733 if (type == Resource::Script || type == Resource::ImportResource) { 737 if (type == Resource::Script || type == Resource::ImportResource) {
734 DCHECK(frame()); 738 DCHECK(frame());
735 if (!frame()->loader().client()->allowScriptFromSource( 739 if (!frameLoaderClient()->allowScriptFromSource(
736 !frame()->settings() || frame()->settings()->getScriptEnabled(), 740 !frame()->settings() || frame()->settings()->getScriptEnabled(),
737 url)) { 741 url)) {
738 frame()->loader().client()->didNotAllowScript(); 742 frameLoaderClient()->didNotAllowScript();
739 // TODO(estark): Use a different ResourceRequestBlockedReason here, since 743 // TODO(estark): Use a different ResourceRequestBlockedReason here, since
740 // this check has nothing to do with CSP. https://crbug.com/600795 744 // this check has nothing to do with CSP. https://crbug.com/600795
741 return ResourceRequestBlockedReason::CSP; 745 return ResourceRequestBlockedReason::CSP;
742 } 746 }
743 } else if (type == Resource::Media || type == Resource::TextTrack) { 747 } else if (type == Resource::Media || type == Resource::TextTrack) {
744 DCHECK(frame()); 748 DCHECK(frame());
745 if (!frame()->loader().client()->allowMedia(url)) 749 if (!frameLoaderClient()->allowMedia(url))
746 return ResourceRequestBlockedReason::Other; 750 return ResourceRequestBlockedReason::Other;
747 } 751 }
748 752
749 // SVG Images have unique security rules that prevent all subresource requests 753 // SVG Images have unique security rules that prevent all subresource requests
750 // except for data urls. 754 // except for data urls.
751 if (type != Resource::MainResource && 755 if (type != Resource::MainResource &&
752 frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData()) 756 frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData())
753 return ResourceRequestBlockedReason::Origin; 757 return ResourceRequestBlockedReason::Origin;
754 758
755 // Measure the number of legacy URL schemes ('ftp://') and the number of 759 // Measure the number of legacy URL schemes ('ftp://') and the number of
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 816
813 if (m_documentLoader) { 817 if (m_documentLoader) {
814 return m_documentLoader->frame() 818 return m_documentLoader->frame()
815 ->loader() 819 ->loader()
816 .client() 820 .client()
817 ->isControlledByServiceWorker(*m_documentLoader); 821 ->isControlledByServiceWorker(*m_documentLoader);
818 } 822 }
819 // m_documentLoader is null while loading resources from an HTML import. In 823 // m_documentLoader is null while loading resources from an HTML import. In
820 // such cases whether the request is controlled by ServiceWorker or not is 824 // such cases whether the request is controlled by ServiceWorker or not is
821 // determined by the document loader of the frame. 825 // determined by the document loader of the frame.
822 return frame()->loader().client()->isControlledByServiceWorker( 826 return frameLoaderClient()->isControlledByServiceWorker(
823 *frame()->loader().documentLoader()); 827 *frame()->loader().documentLoader());
824 } 828 }
825 829
826 int64_t FrameFetchContext::serviceWorkerID() const { 830 int64_t FrameFetchContext::serviceWorkerID() const {
827 DCHECK(m_documentLoader || frame()->loader().documentLoader()); 831 DCHECK(m_documentLoader || frame()->loader().documentLoader());
828 if (m_documentLoader) { 832 if (m_documentLoader) {
829 return m_documentLoader->frame()->loader().client()->serviceWorkerID( 833 return m_documentLoader->frame()->client()->serviceWorkerID(
830 *m_documentLoader); 834 *m_documentLoader);
831 } 835 }
832 // m_documentLoader is null while loading resources from an HTML import. 836 // m_documentLoader is null while loading resources from an HTML import.
833 // In such cases a service worker ID could be retrieved from the document 837 // In such cases a service worker ID could be retrieved from the document
834 // loader of the frame. 838 // loader of the frame.
835 return frame()->loader().client()->serviceWorkerID( 839 return frameLoaderClient()->serviceWorkerID(
836 *frame()->loader().documentLoader()); 840 *frame()->loader().documentLoader());
837 } 841 }
838 842
839 bool FrameFetchContext::isMainFrame() const { 843 bool FrameFetchContext::isMainFrame() const {
840 return frame()->isMainFrame(); 844 return frame()->isMainFrame();
841 } 845 }
842 846
843 bool FrameFetchContext::defersLoading() const { 847 bool FrameFetchContext::defersLoading() const {
844 return frame()->page()->suspended(); 848 return frame()->page()->suspended();
845 } 849 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 response.httpHeaderField(HTTPNames::Link), response.url(), 1043 response.httpHeaderField(HTTPNames::Link), response.url(),
1040 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy, 1044 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy,
1041 LinkLoader::LoadAll, nullptr); 1045 LinkLoader::LoadAll, nullptr);
1042 1046
1043 if (response.hasMajorCertificateErrors()) { 1047 if (response.hasMajorCertificateErrors()) {
1044 MixedContentChecker::handleCertificateError(frame(), response, frameType, 1048 MixedContentChecker::handleCertificateError(frame(), response, frameType,
1045 requestContext); 1049 requestContext);
1046 } 1050 }
1047 1051
1048 frame()->loader().progress().incrementProgress(identifier, response); 1052 frame()->loader().progress().incrementProgress(identifier, response);
1049 frame()->loader().client()->dispatchDidReceiveResponse(response); 1053 frameLoaderClient()->dispatchDidReceiveResponse(response);
1050 DocumentLoader* documentLoader = masterDocumentLoader(); 1054 DocumentLoader* documentLoader = masterDocumentLoader();
1051 InspectorInstrumentation::didReceiveResourceResponse( 1055 InspectorInstrumentation::didReceiveResourceResponse(
1052 frame(), identifier, documentLoader, response, resource); 1056 frame(), identifier, documentLoader, response, resource);
1053 // It is essential that inspector gets resource response BEFORE console. 1057 // It is essential that inspector gets resource response BEFORE console.
1054 frame()->console().reportResourceResponseReceived(documentLoader, identifier, 1058 frame()->console().reportResourceResponseReceived(documentLoader, identifier,
1055 response); 1059 response);
1056 } 1060 }
1057 1061
1058 DEFINE_TRACE(FrameFetchContext) { 1062 DEFINE_TRACE(FrameFetchContext) {
1059 visitor->trace(m_document); 1063 visitor->trace(m_document);
1060 visitor->trace(m_documentLoader); 1064 visitor->trace(m_documentLoader);
1061 FetchContext::trace(visitor); 1065 FetchContext::trace(visitor);
1062 } 1066 }
1063 1067
1064 } // namespace blink 1068 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.h ('k') | third_party/WebKit/Source/core/loader/ProgressTracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698