| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 FrameFetchContext::~FrameFetchContext() | 72 FrameFetchContext::~FrameFetchContext() |
| 73 { | 73 { |
| 74 m_document = nullptr; | 74 m_document = nullptr; |
| 75 m_documentLoader = nullptr; | 75 m_documentLoader = nullptr; |
| 76 } | 76 } |
| 77 | 77 |
| 78 LocalFrame* FrameFetchContext::frame() const | 78 LocalFrame* FrameFetchContext::frame() const |
| 79 { | 79 { |
| 80 LocalFrame* frame = nullptr; |
| 80 if (m_documentLoader) | 81 if (m_documentLoader) |
| 81 return m_documentLoader->frame(); | 82 frame = m_documentLoader->frame(); |
| 82 if (m_document && m_document->importsController()) | 83 else if (m_document && m_document->importsController()) |
| 83 return m_document->importsController()->master()->frame(); | 84 frame = m_document->importsController()->master()->frame(); |
| 84 return 0; | 85 ASSERT(frame); |
| 86 return frame; |
| 85 } | 87 } |
| 86 | 88 |
| 87 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, Fe
tchResourceType type) | 89 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, Fe
tchResourceType type) |
| 88 { | 90 { |
| 89 if (!frame()) | |
| 90 return; | |
| 91 | |
| 92 bool isMainResource = type == FetchMainResource; | 91 bool isMainResource = type == FetchMainResource; |
| 93 if (!isMainResource) { | 92 if (!isMainResource) { |
| 94 String outgoingOrigin; | 93 String outgoingOrigin; |
| 95 if (!request.didSetHTTPReferrer()) { | 94 if (!request.didSetHTTPReferrer()) { |
| 96 outgoingOrigin = m_document->outgoingOrigin(); | 95 outgoingOrigin = m_document->outgoingOrigin(); |
| 97 request.setHTTPReferrer(SecurityPolicy::generateReferrer(m_document-
>referrerPolicy(), request.url(), m_document->outgoingReferrer())); | 96 request.setHTTPReferrer(SecurityPolicy::generateReferrer(m_document-
>referrerPolicy(), request.url(), m_document->outgoingReferrer())); |
| 98 } else { | 97 } else { |
| 99 RELEASE_ASSERT(SecurityPolicy::generateReferrer(request.referrerPoli
cy(), request.url(), request.httpReferrer()).referrer == request.httpReferrer())
; | 98 RELEASE_ASSERT(SecurityPolicy::generateReferrer(request.referrerPoli
cy(), request.url(), request.httpReferrer()).referrer == request.httpReferrer())
; |
| 100 outgoingOrigin = SecurityOrigin::createFromString(request.httpReferr
er())->toString(); | 99 outgoingOrigin = SecurityOrigin::createFromString(request.httpReferr
er())->toString(); |
| 101 } | 100 } |
| 102 | 101 |
| 103 request.addHTTPOriginIfNeeded(AtomicString(outgoingOrigin)); | 102 request.addHTTPOriginIfNeeded(AtomicString(outgoingOrigin)); |
| 104 } | 103 } |
| 105 | 104 |
| 106 if (m_document) | 105 if (m_document) |
| 107 request.setOriginatesFromReservedIPRange(m_document->isHostedInReservedI
PRange()); | 106 request.setOriginatesFromReservedIPRange(m_document->isHostedInReservedI
PRange()); |
| 108 | 107 |
| 109 // The remaining modifications are only necessary for HTTP and HTTPS. | 108 // The remaining modifications are only necessary for HTTP and HTTPS. |
| 110 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) | 109 if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) |
| 111 return; | 110 return; |
| 112 | 111 |
| 113 frame()->loader().applyUserAgent(request); | 112 frame()->loader().applyUserAgent(request); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void FrameFetchContext::setFirstPartyForCookies(ResourceRequest& request) | 115 void FrameFetchContext::setFirstPartyForCookies(ResourceRequest& request) |
| 117 { | 116 { |
| 118 if (!frame()) | |
| 119 return; | |
| 120 | |
| 121 if (frame()->tree().top()->isLocalFrame()) | 117 if (frame()->tree().top()->isLocalFrame()) |
| 122 request.setFirstPartyForCookies(toLocalFrame(frame()->tree().top())->doc
ument()->firstPartyForCookies()); | 118 request.setFirstPartyForCookies(toLocalFrame(frame()->tree().top())->doc
ument()->firstPartyForCookies()); |
| 123 } | 119 } |
| 124 | 120 |
| 125 CachePolicy FrameFetchContext::cachePolicy() const | 121 CachePolicy FrameFetchContext::cachePolicy() const |
| 126 { | 122 { |
| 127 if (!frame()) | |
| 128 return CachePolicyVerify; | |
| 129 | |
| 130 if (m_document && m_document->loadEventFinished()) | 123 if (m_document && m_document->loadEventFinished()) |
| 131 return CachePolicyVerify; | 124 return CachePolicyVerify; |
| 132 | 125 |
| 133 FrameLoadType loadType = frame()->loader().loadType(); | 126 FrameLoadType loadType = frame()->loader().loadType(); |
| 134 if (loadType == FrameLoadTypeReloadFromOrigin) | 127 if (loadType == FrameLoadTypeReloadFromOrigin) |
| 135 return CachePolicyReload; | 128 return CachePolicyReload; |
| 136 | 129 |
| 137 Frame* parentFrame = frame()->tree().parent(); | 130 Frame* parentFrame = frame()->tree().parent(); |
| 138 if (parentFrame && parentFrame->isLocalFrame()) { | 131 if (parentFrame && parentFrame->isLocalFrame()) { |
| 139 CachePolicy parentCachePolicy = toLocalFrame(parentFrame)->document()->f
etcher()->context().cachePolicy(); | 132 CachePolicy parentCachePolicy = toLocalFrame(parentFrame)->document()->f
etcher()->context().cachePolicy(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 return ReloadIgnoringCacheData; | 151 return ReloadIgnoringCacheData; |
| 159 if (policy == CachePolicyReload) | 152 if (policy == CachePolicyReload) |
| 160 return ReloadBypassingCache; | 153 return ReloadBypassingCache; |
| 161 if (policy == CachePolicyHistoryBuffer) | 154 if (policy == CachePolicyHistoryBuffer) |
| 162 return ReturnCacheDataElseLoad; | 155 return ReturnCacheDataElseLoad; |
| 163 return UseProtocolCachePolicy; | 156 return UseProtocolCachePolicy; |
| 164 } | 157 } |
| 165 | 158 |
| 166 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
esourceRequest& request, Resource::Type type) const | 159 ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
esourceRequest& request, Resource::Type type) const |
| 167 { | 160 { |
| 168 if (!frame()) | |
| 169 return UseProtocolCachePolicy; | |
| 170 | |
| 171 if (type == Resource::MainResource) { | 161 if (type == Resource::MainResource) { |
| 172 FrameLoadType frameLoadType = frame()->loader().loadType(); | 162 FrameLoadType frameLoadType = frame()->loader().loadType(); |
| 173 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) | 163 if (request.httpMethod() == "POST" && frameLoadType == FrameLoadTypeBack
Forward) |
| 174 return ReturnCacheDataDontLoad; | 164 return ReturnCacheDataDontLoad; |
| 175 if (!frame()->host()->overrideEncoding().isEmpty() || frameLoadType == F
rameLoadTypeBackForward) | 165 if (!frame()->host()->overrideEncoding().isEmpty() || frameLoadType == F
rameLoadTypeBackForward) |
| 176 return ReturnCacheDataElseLoad; | 166 return ReturnCacheDataElseLoad; |
| 177 if (frameLoadType == FrameLoadTypeReloadFromOrigin) | 167 if (frameLoadType == FrameLoadTypeReloadFromOrigin) |
| 178 return ReloadBypassingCache; | 168 return ReloadBypassingCache; |
| 179 if (frameLoadType == FrameLoadTypeReload || frameLoadType == FrameLoadTy
peSame || request.isConditional() || request.httpMethod() == "POST") | 169 if (frameLoadType == FrameLoadTypeReload || frameLoadType == FrameLoadTy
peSame || request.isConditional() || request.httpMethod() == "POST") |
| 180 return ReloadIgnoringCacheData; | 170 return ReloadIgnoringCacheData; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 205 // |loader| can be null if the resource is loaded from imported document. | 195 // |loader| can be null if the resource is loaded from imported document. |
| 206 // This means inspector, which uses DocumentLoader as an grouping entity, | 196 // This means inspector, which uses DocumentLoader as an grouping entity, |
| 207 // cannot see imported documents. | 197 // cannot see imported documents. |
| 208 inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() | 198 inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() |
| 209 { | 199 { |
| 210 return m_documentLoader ? m_documentLoader : frame()->loader().documentLoade
r(); | 200 return m_documentLoader ? m_documentLoader : frame()->loader().documentLoade
r(); |
| 211 } | 201 } |
| 212 | 202 |
| 213 void FrameFetchContext::dispatchDidChangeResourcePriority(unsigned long identifi
er, ResourceLoadPriority loadPriority, int intraPriorityValue) | 203 void FrameFetchContext::dispatchDidChangeResourcePriority(unsigned long identifi
er, ResourceLoadPriority loadPriority, int intraPriorityValue) |
| 214 { | 204 { |
| 215 if (!frame()) | |
| 216 return; | |
| 217 | |
| 218 frame()->loader().client()->dispatchDidChangeResourcePriority(identifier, lo
adPriority, intraPriorityValue); | 205 frame()->loader().client()->dispatchDidChangeResourcePriority(identifier, lo
adPriority, intraPriorityValue); |
| 219 } | 206 } |
| 220 | 207 |
| 221 void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour
ceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiat
orInfo& initiatorInfo) | 208 void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour
ceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiat
orInfo& initiatorInfo) |
| 222 { | 209 { |
| 223 if (!frame()) | |
| 224 return; | |
| 225 | |
| 226 frame()->loader().applyUserAgent(request); | 210 frame()->loader().applyUserAgent(request); |
| 227 frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identi
fier, request, redirectResponse); | 211 frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identi
fier, request, redirectResponse); |
| 228 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceSendRequest", TRACE_EVENT_SCOPE_THREAD, "data", InspectorSendRequestEvent::dat
a(identifier, frame(), request)); | 212 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceSendRequest", TRACE_EVENT_SCOPE_THREAD, "data", InspectorSendRequestEvent::dat
a(identifier, frame(), request)); |
| 229 InspectorInstrumentation::willSendRequest(frame(), identifier, ensureLoaderF
orNotifications(), request, redirectResponse, initiatorInfo); | 213 InspectorInstrumentation::willSendRequest(frame(), identifier, ensureLoaderF
orNotifications(), request, redirectResponse, initiatorInfo); |
| 230 } | 214 } |
| 231 | 215 |
| 232 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache(const ResourceReq
uest& request, const ResourceResponse& response) | 216 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache(const ResourceReq
uest& request, const ResourceResponse& response) |
| 233 { | 217 { |
| 234 if (!frame()) | |
| 235 return; | |
| 236 | |
| 237 frame()->loader().client()->dispatchDidLoadResourceFromMemoryCache(request,
response); | 218 frame()->loader().client()->dispatchDidLoadResourceFromMemoryCache(request,
response); |
| 238 } | 219 } |
| 239 | 220 |
| 240 void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, con
st ResourceResponse& response, ResourceLoader* resourceLoader) | 221 void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, con
st ResourceResponse& response, ResourceLoader* resourceLoader) |
| 241 { | 222 { |
| 242 if (!frame()) | |
| 243 return; | |
| 244 | |
| 245 MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddre
ss()); | 223 MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddre
ss()); |
| 246 LinkLoader::loadLinkFromHeader(response.httpHeaderField("Link"), frame()->do
cument()); | 224 LinkLoader::loadLinkFromHeader(response.httpHeaderField("Link"), frame()->do
cument()); |
| 247 if (m_documentLoader == frame()->loader().provisionalDocumentLoader()) | 225 if (m_documentLoader == frame()->loader().provisionalDocumentLoader()) |
| 248 handleAcceptClientHintsHeader(response.httpHeaderField("accept-ch"), m_d
ocumentLoader->clientHintsPreferences()); | 226 handleAcceptClientHintsHeader(response.httpHeaderField("accept-ch"), m_d
ocumentLoader->clientHintsPreferences()); |
| 249 | 227 |
| 250 frame()->loader().progress().incrementProgress(identifier, response); | 228 frame()->loader().progress().incrementProgress(identifier, response); |
| 251 frame()->loader().client()->dispatchDidReceiveResponse(m_documentLoader, ide
ntifier, response); | 229 frame()->loader().client()->dispatchDidReceiveResponse(m_documentLoader, ide
ntifier, response); |
| 252 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceiveResponse", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveResponseEv
ent::data(identifier, frame(), response)); | 230 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceiveResponse", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveResponseEv
ent::data(identifier, frame(), response)); |
| 253 DocumentLoader* documentLoader = ensureLoaderForNotifications(); | 231 DocumentLoader* documentLoader = ensureLoaderForNotifications(); |
| 254 InspectorInstrumentation::didReceiveResourceResponse(frame(), identifier, do
cumentLoader, response, resourceLoader); | 232 InspectorInstrumentation::didReceiveResourceResponse(frame(), identifier, do
cumentLoader, response, resourceLoader); |
| 255 // It is essential that inspector gets resource response BEFORE console. | 233 // It is essential that inspector gets resource response BEFORE console. |
| 256 frame()->console().reportResourceResponseReceived(documentLoader, identifier
, response); | 234 frame()->console().reportResourceResponseReceived(documentLoader, identifier
, response); |
| 257 } | 235 } |
| 258 | 236 |
| 259 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, const c
har* data, int dataLength, int encodedDataLength) | 237 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, const c
har* data, int dataLength, int encodedDataLength) |
| 260 { | 238 { |
| 261 if (!frame()) | |
| 262 return; | |
| 263 | |
| 264 frame()->loader().progress().incrementProgress(identifier, dataLength); | 239 frame()->loader().progress().incrementProgress(identifier, dataLength); |
| 265 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveDataEvent::da
ta(identifier, frame(), encodedDataLength)); | 240 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveDataEvent::da
ta(identifier, frame(), encodedDataLength)); |
| 266 InspectorInstrumentation::didReceiveData(frame(), identifier, data, dataLeng
th, encodedDataLength); | 241 InspectorInstrumentation::didReceiveData(frame(), identifier, data, dataLeng
th, encodedDataLength); |
| 267 } | 242 } |
| 268 | 243 |
| 269 void FrameFetchContext::dispatchDidDownloadData(unsigned long identifier, int da
taLength, int encodedDataLength) | 244 void FrameFetchContext::dispatchDidDownloadData(unsigned long identifier, int da
taLength, int encodedDataLength) |
| 270 { | 245 { |
| 271 if (!frame()) | |
| 272 return; | |
| 273 | |
| 274 frame()->loader().progress().incrementProgress(identifier, dataLength); | 246 frame()->loader().progress().incrementProgress(identifier, dataLength); |
| 275 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveDataEvent::da
ta(identifier, frame(), encodedDataLength)); | 247 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveDataEvent::da
ta(identifier, frame(), encodedDataLength)); |
| 276 InspectorInstrumentation::didReceiveData(frame(), identifier, 0, dataLength,
encodedDataLength); | 248 InspectorInstrumentation::didReceiveData(frame(), identifier, 0, dataLength,
encodedDataLength); |
| 277 } | 249 } |
| 278 | 250 |
| 279 void FrameFetchContext::dispatchDidFinishLoading(unsigned long identifier, doubl
e finishTime, int64_t encodedDataLength) | 251 void FrameFetchContext::dispatchDidFinishLoading(unsigned long identifier, doubl
e finishTime, int64_t encodedDataLength) |
| 280 { | 252 { |
| 281 if (!frame()) | |
| 282 return; | |
| 283 | |
| 284 frame()->loader().progress().completeProgress(identifier); | 253 frame()->loader().progress().completeProgress(identifier); |
| 285 frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, ident
ifier); | 254 frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, ident
ifier); |
| 286 | 255 |
| 287 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(
identifier, finishTime, false)); | 256 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(
identifier, finishTime, false)); |
| 288 InspectorInstrumentation::didFinishLoading(frame(), identifier, finishTime,
encodedDataLength); | 257 InspectorInstrumentation::didFinishLoading(frame(), identifier, finishTime,
encodedDataLength); |
| 289 } | 258 } |
| 290 | 259 |
| 291 void FrameFetchContext::dispatchDidFail(unsigned long identifier, const Resource
Error& error, bool isInternalRequest) | 260 void FrameFetchContext::dispatchDidFail(unsigned long identifier, const Resource
Error& error, bool isInternalRequest) |
| 292 { | 261 { |
| 293 if (!frame()) | |
| 294 return; | |
| 295 | |
| 296 frame()->loader().progress().completeProgress(identifier); | 262 frame()->loader().progress().completeProgress(identifier); |
| 297 frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, ident
ifier); | 263 frame()->loader().client()->dispatchDidFinishLoading(m_documentLoader, ident
ifier); |
| 298 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(
identifier, 0, true)); | 264 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(
identifier, 0, true)); |
| 299 InspectorInstrumentation::didFailLoading(frame(), identifier, error); | 265 InspectorInstrumentation::didFailLoading(frame(), identifier, error); |
| 300 // Notification to FrameConsole should come AFTER InspectorInstrumentation c
all, DevTools front-end relies on this. | 266 // Notification to FrameConsole should come AFTER InspectorInstrumentation c
all, DevTools front-end relies on this. |
| 301 if (!isInternalRequest) | 267 if (!isInternalRequest) |
| 302 frame()->console().didFailLoading(identifier, error); | 268 frame()->console().didFailLoading(identifier, error); |
| 303 } | 269 } |
| 304 | 270 |
| 305 void FrameFetchContext::sendRemainingDelegateMessages(unsigned long identifier,
const ResourceResponse& response, int dataLength) | 271 void FrameFetchContext::sendRemainingDelegateMessages(unsigned long identifier,
const ResourceResponse& response, int dataLength) |
| 306 { | 272 { |
| 307 if (!frame()) | |
| 308 return; | |
| 309 | |
| 310 InspectorInstrumentation::markResourceAsCached(frame(), identifier); | 273 InspectorInstrumentation::markResourceAsCached(frame(), identifier); |
| 311 if (!response.isNull()) | 274 if (!response.isNull()) |
| 312 dispatchDidReceiveResponse(identifier, response); | 275 dispatchDidReceiveResponse(identifier, response); |
| 313 | 276 |
| 314 if (dataLength > 0) | 277 if (dataLength > 0) |
| 315 dispatchDidReceiveData(identifier, 0, dataLength, 0); | 278 dispatchDidReceiveData(identifier, 0, dataLength, 0); |
| 316 | 279 |
| 317 dispatchDidFinishLoading(identifier, 0, 0); | 280 dispatchDidFinishLoading(identifier, 0, 0); |
| 318 } | 281 } |
| 319 | 282 |
| 320 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const | 283 bool FrameFetchContext::shouldLoadNewResource(Resource::Type type) const |
| 321 { | 284 { |
| 322 if (!frame()) | |
| 323 return false; | |
| 324 if (!m_documentLoader) | 285 if (!m_documentLoader) |
| 325 return true; | 286 return true; |
| 326 if (type == Resource::MainResource) | 287 if (type == Resource::MainResource) |
| 327 return m_documentLoader == frame()->loader().provisionalDocumentLoader()
; | 288 return m_documentLoader == frame()->loader().provisionalDocumentLoader()
; |
| 328 return m_documentLoader == frame()->loader().documentLoader(); | 289 return m_documentLoader == frame()->loader().documentLoader(); |
| 329 } | 290 } |
| 330 | 291 |
| 331 void FrameFetchContext::dispatchWillRequestResource(FetchRequest* request) | 292 void FrameFetchContext::dispatchWillRequestResource(FetchRequest* request) |
| 332 { | 293 { |
| 333 if (frame()) | 294 frame()->loader().client()->dispatchWillRequestResource(request); |
| 334 frame()->loader().client()->dispatchWillRequestResource(request); | |
| 335 } | 295 } |
| 336 | 296 |
| 337 void FrameFetchContext::willStartLoadingResource(ResourceRequest& request) | 297 void FrameFetchContext::willStartLoadingResource(ResourceRequest& request) |
| 338 { | 298 { |
| 339 if (m_documentLoader) | 299 if (m_documentLoader) |
| 340 m_documentLoader->applicationCacheHost()->willStartLoadingResource(reque
st); | 300 m_documentLoader->applicationCacheHost()->willStartLoadingResource(reque
st); |
| 341 } | 301 } |
| 342 | 302 |
| 343 void FrameFetchContext::didLoadResource() | 303 void FrameFetchContext::didLoadResource() |
| 344 { | 304 { |
| 345 if (frame()) | 305 frame()->loader().checkCompleted(); |
| 346 frame()->loader().checkCompleted(); | |
| 347 } | 306 } |
| 348 | 307 |
| 349 void FrameFetchContext::addResourceTiming(ResourceTimingInfo* info, bool isMainR
esource) | 308 void FrameFetchContext::addResourceTiming(ResourceTimingInfo* info, bool isMainR
esource) |
| 350 { | 309 { |
| 351 Document* initiatorDocument = m_document && isMainResource ? m_document->par
entDocument() : m_document.get(); | 310 Document* initiatorDocument = m_document && isMainResource ? m_document->par
entDocument() : m_document.get(); |
| 352 if (!frame() || !initiatorDocument || !initiatorDocument->domWindow()) | 311 if (!initiatorDocument || !initiatorDocument->domWindow()) |
| 353 return; | 312 return; |
| 354 DOMWindowPerformance::performance(*initiatorDocument->domWindow())->addResou
rceTiming(*info, initiatorDocument); | 313 DOMWindowPerformance::performance(*initiatorDocument->domWindow())->addResou
rceTiming(*info, initiatorDocument); |
| 355 } | 314 } |
| 356 | 315 |
| 357 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const | 316 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const |
| 358 { | 317 { |
| 359 return !frame() || frame()->loader().client()->allowImage(imagesEnabled, url
); | 318 return frame()->loader().client()->allowImage(imagesEnabled, url); |
| 360 } | 319 } |
| 361 | 320 |
| 362 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const | 321 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const |
| 363 { | 322 { |
| 364 if (url.isNull()) | 323 if (url.isNull()) |
| 365 return; | 324 return; |
| 366 | 325 |
| 367 String message; | 326 String message; |
| 368 if (!m_document || m_document->url().isNull()) | 327 if (!m_document || m_document->url().isNull()) |
| 369 message = "Unsafe attempt to load URL " + url.elidedString() + '.'; | 328 message = "Unsafe attempt to load URL " + url.elidedString() + '.'; |
| 370 else | 329 else |
| 371 message = "Unsafe attempt to load URL " + url.elidedString() + " from fr
ame with URL " + m_document->url().elidedString() + ". Domains, protocols and po
rts must match.\n"; | 330 message = "Unsafe attempt to load URL " + url.elidedString() + " from fr
ame with URL " + m_document->url().elidedString() + ". Domains, protocols and po
rts must match.\n"; |
| 372 | 331 |
| 373 frame()->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessag
eSource, ErrorMessageLevel, message)); | 332 frame()->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessag
eSource, ErrorMessageLevel, message)); |
| 374 } | 333 } |
| 375 | 334 |
| 376 bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r
esourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forP
reload, FetchRequest::OriginRestriction originRestriction) const | 335 bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r
esourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forP
reload, FetchRequest::OriginRestriction originRestriction) const |
| 377 { | 336 { |
| 378 // FIXME: CachingCorrectnessTest needs us to permit loads when there isn't a
frame. | |
| 379 // Once CachingCorrectnessTest can create a FetchContext mock to meet its ne
eds (without | |
| 380 // also needing to mock Document, DocumentLoader, and Frame), this should ei
ther be reverted to | |
| 381 // return false or removed entirely. | |
| 382 if (!frame()) | |
| 383 return true; | |
| 384 | |
| 385 SecurityOrigin* securityOrigin = options.securityOrigin.get(); | 337 SecurityOrigin* securityOrigin = options.securityOrigin.get(); |
| 386 if (!securityOrigin && m_document) | 338 if (!securityOrigin && m_document) |
| 387 securityOrigin = m_document->securityOrigin(); | 339 securityOrigin = m_document->securityOrigin(); |
| 388 | 340 |
| 389 if (originRestriction != FetchRequest::NoOriginRestriction && securityOrigin
&& !securityOrigin->canDisplay(url)) { | 341 if (originRestriction != FetchRequest::NoOriginRestriction && securityOrigin
&& !securityOrigin->canDisplay(url)) { |
| 390 if (!forPreload) | 342 if (!forPreload) |
| 391 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); | 343 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); |
| 392 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a
llowed by SecurityOrigin::canDisplay"); | 344 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a
llowed by SecurityOrigin::canDisplay"); |
| 393 return false; | 345 return false; |
| 394 } | 346 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 effectiveFrame = toLocalFrame(parentFrame); | 492 effectiveFrame = toLocalFrame(parentFrame); |
| 541 } | 493 } |
| 542 | 494 |
| 543 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? | 495 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? |
| 544 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; | 496 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; |
| 545 return !MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques
t, url, mixedContentReporting); | 497 return !MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques
t, url, mixedContentReporting); |
| 546 } | 498 } |
| 547 | 499 |
| 548 bool FrameFetchContext::isControlledByServiceWorker() const | 500 bool FrameFetchContext::isControlledByServiceWorker() const |
| 549 { | 501 { |
| 550 if (!frame()) | |
| 551 return false; | |
| 552 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 502 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
| 553 if (m_documentLoader) | 503 if (m_documentLoader) |
| 554 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); | 504 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); |
| 555 // m_documentLoader is null while loading resources from an HTML import. | 505 // m_documentLoader is null while loading resources from an HTML import. |
| 556 // In such cases whether the request is controlled by ServiceWorker or not | 506 // In such cases whether the request is controlled by ServiceWorker or not |
| 557 // is determined by the document loader of the frame. | 507 // is determined by the document loader of the frame. |
| 558 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); | 508 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); |
| 559 } | 509 } |
| 560 | 510 |
| 561 int64_t FrameFetchContext::serviceWorkerID() const | 511 int64_t FrameFetchContext::serviceWorkerID() const |
| 562 { | 512 { |
| 563 if (!frame()) | |
| 564 return -1; | |
| 565 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 513 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
| 566 if (m_documentLoader) | 514 if (m_documentLoader) |
| 567 return frame()->loader().client()->serviceWorkerID(*m_documentLoader); | 515 return frame()->loader().client()->serviceWorkerID(*m_documentLoader); |
| 568 // m_documentLoader is null while loading resources from an HTML import. | 516 // m_documentLoader is null while loading resources from an HTML import. |
| 569 // In such cases a service worker ID could be retrieved from the document | 517 // In such cases a service worker ID could be retrieved from the document |
| 570 // loader of the frame. | 518 // loader of the frame. |
| 571 return frame()->loader().client()->serviceWorkerID(*frame()->loader().docume
ntLoader()); | 519 return frame()->loader().client()->serviceWorkerID(*frame()->loader().docume
ntLoader()); |
| 572 } | 520 } |
| 573 | 521 |
| 574 bool FrameFetchContext::isMainFrame() const | 522 bool FrameFetchContext::isMainFrame() const |
| 575 { | 523 { |
| 576 return frame() && frame()->isMainFrame(); | 524 return frame()->isMainFrame(); |
| 577 } | 525 } |
| 578 | 526 |
| 579 bool FrameFetchContext::hasSubstituteData() const | 527 bool FrameFetchContext::hasSubstituteData() const |
| 580 { | 528 { |
| 581 return m_documentLoader && m_documentLoader->substituteData().isValid(); | 529 return m_documentLoader && m_documentLoader->substituteData().isValid(); |
| 582 } | 530 } |
| 583 | 531 |
| 584 bool FrameFetchContext::defersLoading() const | 532 bool FrameFetchContext::defersLoading() const |
| 585 { | 533 { |
| 586 return frame() && frame()->page()->defersLoading(); | 534 return frame()->page()->defersLoading(); |
| 587 } | 535 } |
| 588 | 536 |
| 589 bool FrameFetchContext::isLoadComplete() const | 537 bool FrameFetchContext::isLoadComplete() const |
| 590 { | 538 { |
| 591 return m_document && m_document->loadEventFinished(); | 539 return m_document && m_document->loadEventFinished(); |
| 592 } | 540 } |
| 593 | 541 |
| 594 bool FrameFetchContext::pageDismissalEventBeingDispatched() const | 542 bool FrameFetchContext::pageDismissalEventBeingDispatched() const |
| 595 { | 543 { |
| 596 return m_document && m_document->pageDismissalEventBeingDispatched() != Docu
ment::NoDismissal; | 544 return m_document && m_document->pageDismissalEventBeingDispatched() != Docu
ment::NoDismissal; |
| 597 } | 545 } |
| 598 | 546 |
| 599 bool FrameFetchContext::updateTimingInfoForIFrameNavigation(ResourceTimingInfo*
info) | 547 bool FrameFetchContext::updateTimingInfoForIFrameNavigation(ResourceTimingInfo*
info) |
| 600 { | 548 { |
| 601 // <iframe>s should report the initial navigation requested by the parent do
cument, but not subsequent navigations. | 549 // <iframe>s should report the initial navigation requested by the parent do
cument, but not subsequent navigations. |
| 602 // FIXME: Resource timing is broken when the parent is a remote frame. | 550 // FIXME: Resource timing is broken when the parent is a remote frame. |
| 603 if (!frame() || !frame()->deprecatedLocalOwner() || frame()->deprecatedLocal
Owner()->loadedNonEmptyDocument()) | 551 if (!frame()->deprecatedLocalOwner() || frame()->deprecatedLocalOwner()->loa
dedNonEmptyDocument()) |
| 604 return false; | 552 return false; |
| 605 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName()); | 553 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName()); |
| 606 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument(); | 554 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument(); |
| 607 return true; | 555 return true; |
| 608 } | 556 } |
| 609 | 557 |
| 610 void FrameFetchContext::sendImagePing(const KURL& url) | 558 void FrameFetchContext::sendImagePing(const KURL& url) |
| 611 { | 559 { |
| 612 if (frame()) | 560 PingLoader::loadImage(frame(), url); |
| 613 PingLoader::loadImage(frame(), url); | |
| 614 } | 561 } |
| 615 | 562 |
| 616 void FrameFetchContext::addConsoleMessage(const String& message) const | 563 void FrameFetchContext::addConsoleMessage(const String& message) const |
| 617 { | 564 { |
| 618 if (frame() && frame()->document()) | 565 if (frame()->document()) |
| 619 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); | 566 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); |
| 620 } | 567 } |
| 621 | 568 |
| 622 SecurityOrigin* FrameFetchContext::securityOrigin() const | 569 SecurityOrigin* FrameFetchContext::securityOrigin() const |
| 623 { | 570 { |
| 624 return m_document ? m_document->securityOrigin() : nullptr; | 571 return m_document ? m_document->securityOrigin() : nullptr; |
| 625 } | 572 } |
| 626 | 573 |
| 627 String FrameFetchContext::charset() const | 574 String FrameFetchContext::charset() const |
| 628 { | 575 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 659 url.setProtocol("https"); | 606 url.setProtocol("https"); |
| 660 if (url.port() == 80) | 607 if (url.port() == 80) |
| 661 url.setPort(443); | 608 url.setPort(443); |
| 662 fetchRequest.mutableResourceRequest().setURL(url); | 609 fetchRequest.mutableResourceRequest().setURL(url); |
| 663 } | 610 } |
| 664 } | 611 } |
| 665 } | 612 } |
| 666 | 613 |
| 667 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) | 614 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) |
| 668 { | 615 { |
| 669 if (!frame() || !RuntimeEnabledFeatures::clientHintsEnabled() || !m_document
) | 616 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) |
| 670 return; | 617 return; |
| 671 | 618 |
| 672 if (m_document->clientHintsPreferences().shouldSendDPR()) | 619 if (m_document->clientHintsPreferences().shouldSendDPR()) |
| 673 fetchRequest.mutableResourceRequest().addHTTPHeaderField("DPR", AtomicSt
ring(String::number(m_document->devicePixelRatio()))); | 620 fetchRequest.mutableResourceRequest().addHTTPHeaderField("DPR", AtomicSt
ring(String::number(m_document->devicePixelRatio()))); |
| 674 | 621 |
| 675 if (m_document->clientHintsPreferences().shouldSendRW() && frame()->view())
{ | 622 if (m_document->clientHintsPreferences().shouldSendRW() && frame()->view())
{ |
| 676 FetchRequest::ResourceWidth resourceWidth = fetchRequest.resourceWidth()
; | 623 FetchRequest::ResourceWidth resourceWidth = fetchRequest.resourceWidth()
; |
| 677 float usedResourceWidth = resourceWidth.isSet ? resourceWidth.width : fr
ame()->view()->viewportWidth(); | 624 float usedResourceWidth = resourceWidth.isSet ? resourceWidth.width : fr
ame()->view()->viewportWidth(); |
| 678 fetchRequest.mutableResourceRequest().addHTTPHeaderField("RW", AtomicStr
ing(String::number(usedResourceWidth))); | 625 fetchRequest.mutableResourceRequest().addHTTPHeaderField("RW", AtomicStr
ing(String::number(usedResourceWidth))); |
| 679 } | 626 } |
| 680 } | 627 } |
| 681 | 628 |
| 682 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, FetchReques
t& fetchRequest) | 629 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, FetchReques
t& fetchRequest) |
| 683 { | 630 { |
| 684 if (!document() || !frame()) | 631 if (!m_document) |
| 685 return; | 632 return; |
| 686 | 633 |
| 687 const ContentSecurityPolicy* csp = document()->contentSecurityPolicy(); | 634 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy(); |
| 688 if (csp->shouldSendCSPHeader(type)) | 635 if (csp->shouldSendCSPHeader(type)) |
| 689 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"
); | 636 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"
); |
| 690 } | 637 } |
| 691 | 638 |
| 692 DEFINE_TRACE(FrameFetchContext) | 639 DEFINE_TRACE(FrameFetchContext) |
| 693 { | 640 { |
| 694 visitor->trace(m_document); | 641 visitor->trace(m_document); |
| 695 FetchContext::trace(visitor); | 642 FetchContext::trace(visitor); |
| 696 } | 643 } |
| 697 | 644 |
| 698 } // namespace blink | 645 } // namespace blink |
| OLD | NEW |