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

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

Issue 2545023002: Clean up around FrameFetchContext (Closed)
Patch Set: Rebase Created 4 years 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document) 196 FrameFetchContext::FrameFetchContext(DocumentLoader* loader, Document* document)
197 : m_document(document), m_documentLoader(loader) { 197 : m_document(document), m_documentLoader(loader) {
198 DCHECK(frame()); 198 DCHECK(frame());
199 } 199 }
200 200
201 FrameFetchContext::~FrameFetchContext() { 201 FrameFetchContext::~FrameFetchContext() {
202 m_document = nullptr; 202 m_document = nullptr;
203 m_documentLoader = nullptr; 203 m_documentLoader = nullptr;
204 } 204 }
205 205
206 LocalFrame* FrameFetchContext::frame() const { 206 LocalFrame* FrameFetchContext::frameOfImportsController() const {
207 LocalFrame* frame = nullptr; 207 DCHECK(m_document);
208 if (m_documentLoader) 208 HTMLImportsController* importsController = m_document->importsController();
209 frame = m_documentLoader->frame(); 209 DCHECK(importsController);
210 else if (m_document && m_document->importsController()) 210 LocalFrame* frame = importsController->master()->frame();
211 frame = m_document->importsController()->master()->frame();
212 DCHECK(frame); 211 DCHECK(frame);
213 return frame; 212 return frame;
214 } 213 }
214
215 LocalFrame* FrameFetchContext::frame() const {
216 if (!m_documentLoader)
217 return frameOfImportsController();
218
219 LocalFrame* frame = m_documentLoader->frame();
220 DCHECK(frame);
221 return frame;
222 }
215 223
216 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, 224 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request,
217 FetchResourceType type) { 225 FetchResourceType type) {
218 bool isMainResource = type == FetchMainResource; 226 bool isMainResource = type == FetchMainResource;
219 if (!isMainResource) { 227 if (!isMainResource) {
220 if (!request.didSetHTTPReferrer()) { 228 if (!request.didSetHTTPReferrer()) {
221 DCHECK(m_document); 229 DCHECK(m_document);
222 request.setHTTPReferrer(SecurityPolicy::generateReferrer( 230 request.setHTTPReferrer(SecurityPolicy::generateReferrer(
223 m_document->getReferrerPolicy(), request.url(), 231 m_document->getReferrerPolicy(), request.url(),
224 m_document->outgoingReferrer())); 232 m_document->outgoingReferrer()));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy()); 358 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy());
351 } 359 }
352 return WebCachePolicy::UseProtocolCachePolicy; 360 return WebCachePolicy::UseProtocolCachePolicy;
353 } 361 }
354 362
355 // The |m_documentLoader| is null in the FrameFetchContext of an imported 363 // The |m_documentLoader| is null in the FrameFetchContext of an imported
356 // document. 364 // document.
357 // FIXME(http://crbug.com/274173): This means Inspector, which uses 365 // FIXME(http://crbug.com/274173): This means Inspector, which uses
358 // DocumentLoader as a grouping entity, cannot see imported documents. 366 // DocumentLoader as a grouping entity, cannot see imported documents.
359 inline DocumentLoader* FrameFetchContext::masterDocumentLoader() const { 367 inline DocumentLoader* FrameFetchContext::masterDocumentLoader() const {
360 return m_documentLoader ? m_documentLoader.get() 368 if (m_documentLoader)
361 : frame()->loader().documentLoader(); 369 return m_documentLoader.get();
370
371 return frameOfImportsController()->loader().documentLoader();
362 } 372 }
363 373
364 void FrameFetchContext::dispatchDidChangeResourcePriority( 374 void FrameFetchContext::dispatchDidChangeResourcePriority(
365 unsigned long identifier, 375 unsigned long identifier,
366 ResourceLoadPriority loadPriority, 376 ResourceLoadPriority loadPriority,
367 int intraPriorityValue) { 377 int intraPriorityValue) {
368 TRACE_EVENT1( 378 TRACE_EVENT1(
369 "devtools.timeline", "ResourceChangePriority", "data", 379 "devtools.timeline", "ResourceChangePriority", "data",
370 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); 380 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority));
371 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, 381 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 494
485 if (resource->encodedSize() > 0) 495 if (resource->encodedSize() > 0)
486 dispatchDidReceiveData(identifier, 0, resource->encodedSize(), 0); 496 dispatchDidReceiveData(identifier, 0, resource->encodedSize(), 0);
487 497
488 dispatchDidFinishLoading(identifier, 0, 0); 498 dispatchDidFinishLoading(identifier, 0, 0);
489 } 499 }
490 500
491 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const { 501 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const {
492 if (!m_documentLoader) 502 if (!m_documentLoader)
493 return true; 503 return true;
504
505 FrameLoader& loader = m_documentLoader->frame()->loader();
494 if (type == Resource::MainResource) 506 if (type == Resource::MainResource)
495 return m_documentLoader == frame()->loader().provisionalDocumentLoader(); 507 return m_documentLoader == loader.provisionalDocumentLoader();
496 return m_documentLoader == frame()->loader().documentLoader(); 508 return m_documentLoader == loader.documentLoader();
497 } 509 }
498 510
499 static std::unique_ptr<TracedValue> 511 static std::unique_ptr<TracedValue>
500 loadResourceTraceData(unsigned long identifier, const KURL& url, int priority) { 512 loadResourceTraceData(unsigned long identifier, const KURL& url, int priority) {
501 String requestId = IdentifiersFactory::requestId(identifier); 513 String requestId = IdentifiersFactory::requestId(identifier);
502 514
503 std::unique_ptr<TracedValue> value = TracedValue::create(); 515 std::unique_ptr<TracedValue> value = TracedValue::create();
504 value->setString("requestId", requestId); 516 value->setString("requestId", requestId);
505 value->setString("url", url.getString()); 517 value->setString("url", url.getString());
506 value->setInteger("priority", priority); 518 value->setInteger("priority", priority);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 // explicitly return |false| here so that it is clear that the SW will be 772 // explicitly return |false| here so that it is clear that the SW will be
761 // bypassed. In particular, this is important for 773 // bypassed. In particular, this is important for
762 // ResourceFetcher::getCacheIdentifier(), which will return the SW's cache if 774 // ResourceFetcher::getCacheIdentifier(), which will return the SW's cache if
763 // the context's isControlledByServiceWorker() returns |true|, and thus will 775 // the context's isControlledByServiceWorker() returns |true|, and thus will
764 // returned cached resources from the service worker. That would have the 776 // returned cached resources from the service worker. That would have the
765 // effect of not bypassing the SW. 777 // effect of not bypassing the SW.
766 if (getSecurityOrigin() && getSecurityOrigin()->hasSuborigin()) 778 if (getSecurityOrigin() && getSecurityOrigin()->hasSuborigin())
767 return false; 779 return false;
768 780
769 if (m_documentLoader) { 781 if (m_documentLoader) {
770 return frame()->loader().client()->isControlledByServiceWorker( 782 return m_documentLoader->frame()
771 *m_documentLoader); 783 ->loader()
784 .client()
785 ->isControlledByServiceWorker(*m_documentLoader);
772 } 786 }
773 // m_documentLoader is null while loading resources from an HTML import. In 787 // m_documentLoader is null while loading resources from an HTML import. In
774 // such cases whether the request is controlled by ServiceWorker or not is 788 // such cases whether the request is controlled by ServiceWorker or not is
775 // determined by the document loader of the frame. 789 // determined by the document loader of the frame.
776 return frame()->loader().client()->isControlledByServiceWorker( 790 return frame()->loader().client()->isControlledByServiceWorker(
777 *frame()->loader().documentLoader()); 791 *frame()->loader().documentLoader());
778 } 792 }
779 793
780 int64_t FrameFetchContext::serviceWorkerID() const { 794 int64_t FrameFetchContext::serviceWorkerID() const {
781 DCHECK(m_documentLoader || frame()->loader().documentLoader()); 795 DCHECK(m_documentLoader || frame()->loader().documentLoader());
782 if (m_documentLoader) 796 if (m_documentLoader) {
783 return frame()->loader().client()->serviceWorkerID(*m_documentLoader); 797 return m_documentLoader->frame()->loader().client()->serviceWorkerID(
798 *m_documentLoader);
799 }
784 // m_documentLoader is null while loading resources from an HTML import. 800 // m_documentLoader is null while loading resources from an HTML import.
785 // In such cases a service worker ID could be retrieved from the document 801 // In such cases a service worker ID could be retrieved from the document
786 // loader of the frame. 802 // loader of the frame.
787 return frame()->loader().client()->serviceWorkerID( 803 return frame()->loader().client()->serviceWorkerID(
788 *frame()->loader().documentLoader()); 804 *frame()->loader().documentLoader());
789 } 805 }
790 806
791 bool FrameFetchContext::isMainFrame() const { 807 bool FrameFetchContext::isMainFrame() const {
792 return frame()->isMainFrame(); 808 return frame()->isMainFrame();
793 } 809 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 WebURLRequest::FrameType frameType, 984 WebURLRequest::FrameType frameType,
969 WebURLRequest::RequestContext requestContext, 985 WebURLRequest::RequestContext requestContext,
970 Resource* resource, 986 Resource* resource,
971 LinkLoader::CanLoadResources resourceLoadingPolicy) { 987 LinkLoader::CanLoadResources resourceLoadingPolicy) {
972 TRACE_EVENT1( 988 TRACE_EVENT1(
973 "devtools.timeline", "ResourceReceiveResponse", "data", 989 "devtools.timeline", "ResourceReceiveResponse", "data",
974 InspectorReceiveResponseEvent::data(identifier, frame(), response)); 990 InspectorReceiveResponseEvent::data(identifier, frame(), response));
975 MixedContentChecker::checkMixedPrivatePublic(frame(), 991 MixedContentChecker::checkMixedPrivatePublic(frame(),
976 response.remoteIPAddress()); 992 response.remoteIPAddress());
977 if (m_documentLoader && 993 if (m_documentLoader &&
978 m_documentLoader == frame()->loader().provisionalDocumentLoader()) { 994 m_documentLoader ==
995 m_documentLoader->frame()->loader().provisionalDocumentLoader()) {
979 ResourceFetcher* fetcher = nullptr; 996 ResourceFetcher* fetcher = nullptr;
980 if (frame()->document()) 997 if (frame()->document())
981 fetcher = frame()->document()->fetcher(); 998 fetcher = frame()->document()->fetcher();
982 m_documentLoader->clientHintsPreferences() 999 m_documentLoader->clientHintsPreferences()
983 .updateFromAcceptClientHintsHeader( 1000 .updateFromAcceptClientHintsHeader(
984 response.httpHeaderField(HTTPNames::Accept_CH), fetcher); 1001 response.httpHeaderField(HTTPNames::Accept_CH), fetcher);
985 // When response is received with a provisional docloader, the resource 1002 // When response is received with a provisional docloader, the resource
986 // haven't committed yet, and we cannot load resources, only preconnect. 1003 // haven't committed yet, and we cannot load resources, only preconnect.
987 resourceLoadingPolicy = LinkLoader::DoNotLoadResources; 1004 resourceLoadingPolicy = LinkLoader::DoNotLoadResources;
988 } 1005 }
(...skipping 17 matching lines...) Expand all
1006 response); 1023 response);
1007 } 1024 }
1008 1025
1009 DEFINE_TRACE(FrameFetchContext) { 1026 DEFINE_TRACE(FrameFetchContext) {
1010 visitor->trace(m_document); 1027 visitor->trace(m_document);
1011 visitor->trace(m_documentLoader); 1028 visitor->trace(m_documentLoader);
1012 FetchContext::trace(visitor); 1029 FetchContext::trace(visitor);
1013 } 1030 }
1014 1031
1015 } // namespace blink 1032 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.h ('k') | third_party/WebKit/Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698