| Index: Source/core/loader/FrameFetchContext.cpp
|
| diff --git a/Source/core/loader/FrameFetchContext.cpp b/Source/core/loader/FrameFetchContext.cpp
|
| index be0e2e068c99223536bb1480042a24c80dff06eb..69775e99db5a706201e2c1385c9cafd9967bedcb 100644
|
| --- a/Source/core/loader/FrameFetchContext.cpp
|
| +++ b/Source/core/loader/FrameFetchContext.cpp
|
| @@ -77,17 +77,18 @@
|
|
|
| LocalFrame* FrameFetchContext::frame() const
|
| {
|
| - LocalFrame* frame = nullptr;
|
| if (m_documentLoader)
|
| - frame = m_documentLoader->frame();
|
| - else if (m_document && m_document->importsController())
|
| - frame = m_document->importsController()->master()->frame();
|
| - ASSERT(frame);
|
| - return frame;
|
| + return m_documentLoader->frame();
|
| + if (m_document && m_document->importsController())
|
| + return m_document->importsController()->master()->frame();
|
| + return 0;
|
| }
|
|
|
| void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, FetchResourceType type)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| bool isMainResource = type == FetchMainResource;
|
| if (!isMainResource) {
|
| String outgoingOrigin;
|
| @@ -114,12 +115,18 @@
|
|
|
| void FrameFetchContext::setFirstPartyForCookies(ResourceRequest& request)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| if (frame()->tree().top()->isLocalFrame())
|
| request.setFirstPartyForCookies(toLocalFrame(frame()->tree().top())->document()->firstPartyForCookies());
|
| }
|
|
|
| CachePolicy FrameFetchContext::cachePolicy() const
|
| {
|
| + if (!frame())
|
| + return CachePolicyVerify;
|
| +
|
| if (m_document && m_document->loadEventFinished())
|
| return CachePolicyVerify;
|
|
|
| @@ -158,6 +165,9 @@
|
|
|
| ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceRequest& request, Resource::Type type) const
|
| {
|
| + if (!frame())
|
| + return UseProtocolCachePolicy;
|
| +
|
| if (type == Resource::MainResource) {
|
| FrameLoadType frameLoadType = frame()->loader().loadType();
|
| if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBackForward)
|
| @@ -202,11 +212,17 @@
|
|
|
| void FrameFetchContext::dispatchDidChangeResourcePriority(unsigned long identifier, ResourceLoadPriority loadPriority, int intraPriorityValue)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().client()->dispatchDidChangeResourcePriority(identifier, loadPriority, intraPriorityValue);
|
| }
|
|
|
| void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().applyUserAgent(request);
|
| frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identifier, request, redirectResponse);
|
| TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ResourceSendRequest", "data", InspectorSendRequestEvent::data(identifier, frame(), request));
|
| @@ -215,11 +231,17 @@
|
|
|
| void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache(const ResourceRequest& request, const ResourceResponse& response)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().client()->dispatchDidLoadResourceFromMemoryCache(request, response);
|
| }
|
|
|
| void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, const ResourceResponse& response, ResourceLoader* resourceLoader)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddress());
|
| LinkLoader::loadLinkFromHeader(response.httpHeaderField("Link"), frame()->document());
|
| if (m_documentLoader == frame()->loader().provisionalDocumentLoader())
|
| @@ -236,6 +258,9 @@
|
|
|
| void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().progress().incrementProgress(identifier, dataLength);
|
| TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ResourceReceivedData", "data", InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength));
|
| InspectorInstrumentation::didReceiveData(frame(), identifier, data, dataLength, encodedDataLength);
|
| @@ -243,6 +268,9 @@
|
|
|
| void FrameFetchContext::dispatchDidDownloadData(unsigned long identifier, int dataLength, int encodedDataLength)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().progress().incrementProgress(identifier, dataLength);
|
| TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ResourceReceivedData", "data", InspectorReceiveDataEvent::data(identifier, frame(), encodedDataLength));
|
| InspectorInstrumentation::didReceiveData(frame(), identifier, 0, dataLength, encodedDataLength);
|
| @@ -250,6 +278,9 @@
|
|
|
| void FrameFetchContext::dispatchDidFinishLoading(unsigned long identifier, double finishTime, int64_t encodedDataLength)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().progress().completeProgress(identifier);
|
| frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, identifier);
|
|
|
| @@ -259,6 +290,9 @@
|
|
|
| void FrameFetchContext::dispatchDidFail(unsigned long identifier, const ResourceError& error, bool isInternalRequest)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| frame()->loader().progress().completeProgress(identifier);
|
| frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, identifier);
|
| TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ResourceFinish", "data", InspectorResourceFinishEvent::data(identifier, 0, true));
|
| @@ -270,6 +304,9 @@
|
|
|
| void FrameFetchContext::sendRemainingDelegateMessages(unsigned long identifier, const ResourceResponse& response, int dataLength)
|
| {
|
| + if (!frame())
|
| + return;
|
| +
|
| InspectorInstrumentation::markResourceAsCached(frame(), identifier);
|
| if (!response.isNull())
|
| dispatchDidReceiveResponse(identifier, response);
|
| @@ -282,6 +319,8 @@
|
|
|
| bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const
|
| {
|
| + if (!frame())
|
| + return false;
|
| if (!m_documentLoader)
|
| return true;
|
| if (type == Resource::MainResource)
|
| @@ -291,7 +330,8 @@
|
|
|
| void FrameFetchContext::dispatchWillRequestResource(FetchRequest* request)
|
| {
|
| - frame()->loader().client()->dispatchWillRequestResource(request);
|
| + if (frame())
|
| + frame()->loader().client()->dispatchWillRequestResource(request);
|
| }
|
|
|
| void FrameFetchContext::willStartLoadingResource(ResourceRequest& request)
|
| @@ -302,20 +342,21 @@
|
|
|
| void FrameFetchContext::didLoadResource()
|
| {
|
| - frame()->loader().checkCompleted();
|
| + if (frame())
|
| + frame()->loader().checkCompleted();
|
| }
|
|
|
| void FrameFetchContext::addResourceTiming(ResourceTimingInfo* info, bool isMainResource)
|
| {
|
| Document* initiatorDocument = m_document && isMainResource ? m_document->parentDocument() : m_document.get();
|
| - if (!initiatorDocument || !initiatorDocument->domWindow())
|
| + if (!frame() || !initiatorDocument || !initiatorDocument->domWindow())
|
| return;
|
| DOMWindowPerformance::performance(*initiatorDocument->domWindow())->addResourceTiming(*info, initiatorDocument);
|
| }
|
|
|
| bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const
|
| {
|
| - return frame()->loader().client()->allowImage(imagesEnabled, url);
|
| + return !frame() || frame()->loader().client()->allowImage(imagesEnabled, url);
|
| }
|
|
|
| void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const
|
| @@ -334,6 +375,13 @@
|
|
|
| bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forPreload, FetchRequest::OriginRestriction originRestriction) const
|
| {
|
| + // FIXME: CachingCorrectnessTest needs us to permit loads when there isn't a frame.
|
| + // Once CachingCorrectnessTest can create a FetchContext mock to meet its needs (without
|
| + // also needing to mock Document, DocumentLoader, and Frame), this should either be reverted to
|
| + // return false or removed entirely.
|
| + if (!frame())
|
| + return true;
|
| +
|
| SecurityOrigin* securityOrigin = options.securityOrigin.get();
|
| if (!securityOrigin && m_document)
|
| securityOrigin = m_document->securityOrigin();
|
| @@ -493,6 +541,8 @@
|
|
|
| bool FrameFetchContext::isControlledByServiceWorker() const
|
| {
|
| + if (!frame())
|
| + return false;
|
| ASSERT(m_documentLoader || frame()->loader().documentLoader());
|
| if (m_documentLoader)
|
| return frame()->loader().client()->isControlledByServiceWorker(*m_documentLoader);
|
| @@ -504,6 +554,8 @@
|
|
|
| int64_t FrameFetchContext::serviceWorkerID() const
|
| {
|
| + if (!frame())
|
| + return -1;
|
| ASSERT(m_documentLoader || frame()->loader().documentLoader());
|
| if (m_documentLoader)
|
| return frame()->loader().client()->serviceWorkerID(*m_documentLoader);
|
| @@ -515,7 +567,7 @@
|
|
|
| bool FrameFetchContext::isMainFrame() const
|
| {
|
| - return frame()->isMainFrame();
|
| + return frame() && frame()->isMainFrame();
|
| }
|
|
|
| bool FrameFetchContext::hasSubstituteData() const
|
| @@ -525,7 +577,7 @@
|
|
|
| bool FrameFetchContext::defersLoading() const
|
| {
|
| - return frame()->page()->defersLoading();
|
| + return frame() && frame()->page()->defersLoading();
|
| }
|
|
|
| bool FrameFetchContext::isLoadComplete() const
|
| @@ -542,7 +594,7 @@
|
| {
|
| // <iframe>s should report the initial navigation requested by the parent document, but not subsequent navigations.
|
| // FIXME: Resource timing is broken when the parent is a remote frame.
|
| - if (!frame()->deprecatedLocalOwner() || frame()->deprecatedLocalOwner()->loadedNonEmptyDocument())
|
| + if (!frame() || !frame()->deprecatedLocalOwner() || frame()->deprecatedLocalOwner()->loadedNonEmptyDocument())
|
| return false;
|
| info->setInitiatorType(frame()->deprecatedLocalOwner()->localName());
|
| frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument();
|
| @@ -551,12 +603,13 @@
|
|
|
| void FrameFetchContext::sendImagePing(const KURL& url)
|
| {
|
| - PingLoader::loadImage(frame(), url);
|
| + if (frame())
|
| + PingLoader::loadImage(frame(), url);
|
| }
|
|
|
| void FrameFetchContext::addConsoleMessage(const String& message) const
|
| {
|
| - if (frame()->document())
|
| + if (frame() && frame()->document())
|
| frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
|
| }
|
|
|
| @@ -607,7 +660,7 @@
|
|
|
| void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest)
|
| {
|
| - if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document)
|
| + if (!frame() || !RuntimeEnabledFeatures::clientHintsEnabled() || !m_document)
|
| return;
|
|
|
| if (frame()->shouldSendDPRHint())
|
| @@ -620,10 +673,10 @@
|
|
|
| void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, FetchRequest& fetchRequest)
|
| {
|
| - if (!m_document)
|
| - return;
|
| -
|
| - const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy();
|
| + if (!document() || !frame())
|
| + return;
|
| +
|
| + const ContentSecurityPolicy* csp = document()->contentSecurityPolicy();
|
| if (csp->shouldSendCSPHeader(type))
|
| fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active");
|
| }
|
|
|