| 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", "data", InspectorSendRequestEvent::data(identifier, frame(), req
uest)); | 212 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceSendRequest", "data", InspectorSendRequestEvent::data(identifier, frame(), req
uest)); |
| 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"), fra
me()); | 226 handleAcceptClientHintsHeader(response.httpHeaderField("accept-ch"), fra
me()); |
| 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", "data", InspectorReceiveResponseEvent::data(identifier, fram
e(), response)); | 230 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceiveResponse", "data", InspectorReceiveResponseEvent::data(identifier, fram
e(), 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", "data", InspectorReceiveDataEvent::data(identifier, frame(), en
codedDataLength)); | 240 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", "data", InspectorReceiveDataEvent::data(identifier, frame(), en
codedDataLength)); |
| 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", "data", InspectorReceiveDataEvent::data(identifier, frame(), en
codedDataLength)); | 247 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceReceivedData", "data", InspectorReceiveDataEvent::data(identifier, frame(), en
codedDataLength)); |
| 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", "data", InspectorResourceFinishEvent::data(identifier, finishTime, fa
lse)); | 256 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", "data", InspectorResourceFinishEvent::data(identifier, finishTime, fa
lse)); |
| 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", "data", InspectorResourceFinishEvent::data(identifier, 0, true)); | 264 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Resour
ceFinish", "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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 effectiveFrame = toLocalFrame(parentFrame); | 486 effectiveFrame = toLocalFrame(parentFrame); |
| 535 } | 487 } |
| 536 | 488 |
| 537 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? | 489 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? |
| 538 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; | 490 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; |
| 539 return !MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques
t, url, mixedContentReporting); | 491 return !MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques
t, url, mixedContentReporting); |
| 540 } | 492 } |
| 541 | 493 |
| 542 bool FrameFetchContext::isControlledByServiceWorker() const | 494 bool FrameFetchContext::isControlledByServiceWorker() const |
| 543 { | 495 { |
| 544 if (!frame()) | |
| 545 return false; | |
| 546 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 496 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
| 547 if (m_documentLoader) | 497 if (m_documentLoader) |
| 548 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); | 498 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); |
| 549 // m_documentLoader is null while loading resources from an HTML import. | 499 // m_documentLoader is null while loading resources from an HTML import. |
| 550 // In such cases whether the request is controlled by ServiceWorker or not | 500 // In such cases whether the request is controlled by ServiceWorker or not |
| 551 // is determined by the document loader of the frame. | 501 // is determined by the document loader of the frame. |
| 552 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); | 502 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); |
| 553 } | 503 } |
| 554 | 504 |
| 555 int64_t FrameFetchContext::serviceWorkerID() const | 505 int64_t FrameFetchContext::serviceWorkerID() const |
| 556 { | 506 { |
| 557 if (!frame()) | |
| 558 return -1; | |
| 559 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 507 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
| 560 if (m_documentLoader) | 508 if (m_documentLoader) |
| 561 return frame()->loader().client()->serviceWorkerID(*m_documentLoader); | 509 return frame()->loader().client()->serviceWorkerID(*m_documentLoader); |
| 562 // m_documentLoader is null while loading resources from an HTML import. | 510 // m_documentLoader is null while loading resources from an HTML import. |
| 563 // In such cases a service worker ID could be retrieved from the document | 511 // In such cases a service worker ID could be retrieved from the document |
| 564 // loader of the frame. | 512 // loader of the frame. |
| 565 return frame()->loader().client()->serviceWorkerID(*frame()->loader().docume
ntLoader()); | 513 return frame()->loader().client()->serviceWorkerID(*frame()->loader().docume
ntLoader()); |
| 566 } | 514 } |
| 567 | 515 |
| 568 bool FrameFetchContext::isMainFrame() const | 516 bool FrameFetchContext::isMainFrame() const |
| 569 { | 517 { |
| 570 return frame() && frame()->isMainFrame(); | 518 return frame()->isMainFrame(); |
| 571 } | 519 } |
| 572 | 520 |
| 573 bool FrameFetchContext::hasSubstituteData() const | 521 bool FrameFetchContext::hasSubstituteData() const |
| 574 { | 522 { |
| 575 return m_documentLoader && m_documentLoader->substituteData().isValid(); | 523 return m_documentLoader && m_documentLoader->substituteData().isValid(); |
| 576 } | 524 } |
| 577 | 525 |
| 578 bool FrameFetchContext::defersLoading() const | 526 bool FrameFetchContext::defersLoading() const |
| 579 { | 527 { |
| 580 return frame() && frame()->page()->defersLoading(); | 528 return frame()->page()->defersLoading(); |
| 581 } | 529 } |
| 582 | 530 |
| 583 bool FrameFetchContext::isLoadComplete() const | 531 bool FrameFetchContext::isLoadComplete() const |
| 584 { | 532 { |
| 585 return m_document && m_document->loadEventFinished(); | 533 return m_document && m_document->loadEventFinished(); |
| 586 } | 534 } |
| 587 | 535 |
| 588 bool FrameFetchContext::pageDismissalEventBeingDispatched() const | 536 bool FrameFetchContext::pageDismissalEventBeingDispatched() const |
| 589 { | 537 { |
| 590 return m_document && m_document->pageDismissalEventBeingDispatched() != Docu
ment::NoDismissal; | 538 return m_document && m_document->pageDismissalEventBeingDispatched() != Docu
ment::NoDismissal; |
| 591 } | 539 } |
| 592 | 540 |
| 593 bool FrameFetchContext::updateTimingInfoForIFrameNavigation(ResourceTimingInfo*
info) | 541 bool FrameFetchContext::updateTimingInfoForIFrameNavigation(ResourceTimingInfo*
info) |
| 594 { | 542 { |
| 595 // <iframe>s should report the initial navigation requested by the parent do
cument, but not subsequent navigations. | 543 // <iframe>s should report the initial navigation requested by the parent do
cument, but not subsequent navigations. |
| 596 // FIXME: Resource timing is broken when the parent is a remote frame. | 544 // FIXME: Resource timing is broken when the parent is a remote frame. |
| 597 if (!frame() || !frame()->deprecatedLocalOwner() || frame()->deprecatedLocal
Owner()->loadedNonEmptyDocument()) | 545 if (!frame()->deprecatedLocalOwner() || frame()->deprecatedLocalOwner()->loa
dedNonEmptyDocument()) |
| 598 return false; | 546 return false; |
| 599 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName()); | 547 info->setInitiatorType(frame()->deprecatedLocalOwner()->localName()); |
| 600 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument(); | 548 frame()->deprecatedLocalOwner()->didLoadNonEmptyDocument(); |
| 601 return true; | 549 return true; |
| 602 } | 550 } |
| 603 | 551 |
| 604 void FrameFetchContext::sendImagePing(const KURL& url) | 552 void FrameFetchContext::sendImagePing(const KURL& url) |
| 605 { | 553 { |
| 606 if (frame()) | 554 PingLoader::loadImage(frame(), url); |
| 607 PingLoader::loadImage(frame(), url); | |
| 608 } | 555 } |
| 609 | 556 |
| 610 void FrameFetchContext::addConsoleMessage(const String& message) const | 557 void FrameFetchContext::addConsoleMessage(const String& message) const |
| 611 { | 558 { |
| 612 if (frame() && frame()->document()) | 559 if (frame()->document()) |
| 613 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); | 560 frame()->document()->addConsoleMessage(ConsoleMessage::create(JSMessageS
ource, ErrorMessageLevel, message)); |
| 614 } | 561 } |
| 615 | 562 |
| 616 SecurityOrigin* FrameFetchContext::securityOrigin() const | 563 SecurityOrigin* FrameFetchContext::securityOrigin() const |
| 617 { | 564 { |
| 618 return m_document ? m_document->securityOrigin() : nullptr; | 565 return m_document ? m_document->securityOrigin() : nullptr; |
| 619 } | 566 } |
| 620 | 567 |
| 621 String FrameFetchContext::charset() const | 568 String FrameFetchContext::charset() const |
| 622 { | 569 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 653 url.setProtocol("https"); | 600 url.setProtocol("https"); |
| 654 if (url.port() == 80) | 601 if (url.port() == 80) |
| 655 url.setPort(443); | 602 url.setPort(443); |
| 656 fetchRequest.mutableResourceRequest().setURL(url); | 603 fetchRequest.mutableResourceRequest().setURL(url); |
| 657 } | 604 } |
| 658 } | 605 } |
| 659 } | 606 } |
| 660 | 607 |
| 661 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) | 608 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) |
| 662 { | 609 { |
| 663 if (!frame() || !RuntimeEnabledFeatures::clientHintsEnabled() || !m_document
) | 610 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) |
| 664 return; | 611 return; |
| 665 | 612 |
| 666 if (frame()->shouldSendDPRHint()) | 613 if (frame()->shouldSendDPRHint()) |
| 667 fetchRequest.mutableResourceRequest().addHTTPHeaderField("DPR", AtomicSt
ring(String::number(m_document->devicePixelRatio()))); | 614 fetchRequest.mutableResourceRequest().addHTTPHeaderField("DPR", AtomicSt
ring(String::number(m_document->devicePixelRatio()))); |
| 668 | 615 |
| 669 // FIXME: Send the RW hint based on the actual resource width, when we have
it. | 616 // FIXME: Send the RW hint based on the actual resource width, when we have
it. |
| 670 if (frame()->shouldSendRWHint() && frame()->view()) | 617 if (frame()->shouldSendRWHint() && frame()->view()) |
| 671 fetchRequest.mutableResourceRequest().addHTTPHeaderField("RW", AtomicStr
ing(String::number(frame()->view()->viewportWidth()))); | 618 fetchRequest.mutableResourceRequest().addHTTPHeaderField("RW", AtomicStr
ing(String::number(frame()->view()->viewportWidth()))); |
| 672 } | 619 } |
| 673 | 620 |
| 674 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, FetchReques
t& fetchRequest) | 621 void FrameFetchContext::addCSPHeaderIfNecessary(Resource::Type type, FetchReques
t& fetchRequest) |
| 675 { | 622 { |
| 676 if (!document() || !frame()) | 623 if (!m_document) |
| 677 return; | 624 return; |
| 678 | 625 |
| 679 const ContentSecurityPolicy* csp = document()->contentSecurityPolicy(); | 626 const ContentSecurityPolicy* csp = m_document->contentSecurityPolicy(); |
| 680 if (csp->shouldSendCSPHeader(type)) | 627 if (csp->shouldSendCSPHeader(type)) |
| 681 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"
); | 628 fetchRequest.mutableResourceRequest().addHTTPHeaderField("CSP", "active"
); |
| 682 } | 629 } |
| 683 | 630 |
| 684 DEFINE_TRACE(FrameFetchContext) | 631 DEFINE_TRACE(FrameFetchContext) |
| 685 { | 632 { |
| 686 visitor->trace(m_document); | 633 visitor->trace(m_document); |
| 687 FetchContext::trace(visitor); | 634 FetchContext::trace(visitor); |
| 688 } | 635 } |
| 689 | 636 |
| 690 } // namespace blink | 637 } // namespace blink |
| OLD | NEW |