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

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

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

Powered by Google App Engine
This is Rietveld 408576698