| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 void timeout(TimerBase*); | 216 void timeout(TimerBase*); |
| 217 | 217 |
| 218 void didFailLoading(LocalFrame*); | 218 void didFailLoading(LocalFrame*); |
| 219 | 219 |
| 220 std::unique_ptr<WebURLLoader> m_loader; | 220 std::unique_ptr<WebURLLoader> m_loader; |
| 221 Timer<PingLoaderImpl> m_timeout; | 221 Timer<PingLoaderImpl> m_timeout; |
| 222 String m_url; | 222 String m_url; |
| 223 unsigned long m_identifier; | 223 unsigned long m_identifier; |
| 224 SelfKeepAlive<PingLoaderImpl> m_keepAlive; | 224 SelfKeepAlive<PingLoaderImpl> m_keepAlive; |
| 225 AtomicString m_initiator; |
| 225 | 226 |
| 226 bool m_isBeacon; | 227 bool m_isBeacon; |
| 227 | 228 |
| 228 RefPtr<SecurityOrigin> m_origin; | 229 RefPtr<SecurityOrigin> m_origin; |
| 229 CORSEnabled m_corsMode; | 230 CORSEnabled m_corsMode; |
| 230 }; | 231 }; |
| 231 | 232 |
| 232 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, | 233 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, |
| 233 ResourceRequest& request, | 234 ResourceRequest& request, |
| 234 const AtomicString& initiator, | 235 const AtomicString& initiator, |
| 235 StoredCredentials credentialsAllowed, | 236 StoredCredentials credentialsAllowed, |
| 236 bool isBeacon) | 237 bool isBeacon) |
| 237 : ContextClient(frame), | 238 : ContextClient(frame), |
| 238 m_timeout(this, &PingLoaderImpl::timeout), | 239 m_timeout(this, &PingLoaderImpl::timeout), |
| 239 m_url(request.url()), | 240 m_url(request.url()), |
| 240 m_identifier(createUniqueIdentifier()), | 241 m_identifier(createUniqueIdentifier()), |
| 241 m_keepAlive(this), | 242 m_keepAlive(this), |
| 243 m_initiator(initiator), |
| 242 m_isBeacon(isBeacon), | 244 m_isBeacon(isBeacon), |
| 243 m_origin(frame->document()->getSecurityOrigin()), | 245 m_origin(frame->document()->getSecurityOrigin()), |
| 244 m_corsMode(IsCORSEnabled) { | 246 m_corsMode(IsCORSEnabled) { |
| 245 const AtomicString contentType = request.httpContentType(); | 247 const AtomicString contentType = request.httpContentType(); |
| 246 if (!contentType.isNull() && | 248 if (!contentType.isNull() && |
| 247 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) | 249 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) |
| 248 m_corsMode = NotCORSEnabled; | 250 m_corsMode = NotCORSEnabled; |
| 249 | 251 |
| 250 frame->loader().client()->didDispatchPingLoader(request.url()); | 252 frame->loader().client()->didDispatchPingLoader(request.url()); |
| 251 | 253 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 m_loader->cancel(); | 288 m_loader->cancel(); |
| 287 m_loader = nullptr; | 289 m_loader = nullptr; |
| 288 } | 290 } |
| 289 m_timeout.stop(); | 291 m_timeout.stop(); |
| 290 m_keepAlive.clear(); | 292 m_keepAlive.clear(); |
| 291 } | 293 } |
| 292 | 294 |
| 293 bool PingLoaderImpl::willFollowRedirect( | 295 bool PingLoaderImpl::willFollowRedirect( |
| 294 WebURLRequest& passedNewRequest, | 296 WebURLRequest& passedNewRequest, |
| 295 const WebURLResponse& passedRedirectResponse) { | 297 const WebURLResponse& passedRedirectResponse) { |
| 296 if (!m_isBeacon) | 298 if (m_isBeacon && m_corsMode == IsCORSEnabled) { |
| 297 return true; | 299 DCHECK(passedNewRequest.allowStoredCredentials()); |
| 298 | 300 |
| 299 if (m_corsMode == NotCORSEnabled) | 301 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); |
| 300 return true; | 302 const ResourceResponse& redirectResponse( |
| 303 passedRedirectResponse.toResourceResponse()); |
| 301 | 304 |
| 302 DCHECK(passedNewRequest.allowStoredCredentials()); | 305 DCHECK(!newRequest.isNull()); |
| 306 DCHECK(!redirectResponse.isNull()); |
| 303 | 307 |
| 304 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); | 308 String errorDescription; |
| 305 const ResourceResponse& redirectResponse( | 309 ResourceLoaderOptions options; |
| 306 passedRedirectResponse.toResourceResponse()); | 310 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it |
| 311 // on the next time. |
| 312 if (!CrossOriginAccessControl::handleRedirect( |
| 313 m_origin, newRequest, redirectResponse, AllowStoredCredentials, |
| 314 options, errorDescription)) { |
| 315 if (frame()) { |
| 316 if (frame()->document()) { |
| 317 frame()->document()->addConsoleMessage(ConsoleMessage::create( |
| 318 JSMessageSource, ErrorMessageLevel, errorDescription)); |
| 319 } |
| 320 } |
| 321 // Cancel the load and self destruct. |
| 322 dispose(); |
| 307 | 323 |
| 308 DCHECK(!newRequest.isNull()); | 324 return false; |
| 309 DCHECK(!redirectResponse.isNull()); | |
| 310 | |
| 311 String errorDescription; | |
| 312 ResourceLoaderOptions options; | |
| 313 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it | |
| 314 // on the next time. | |
| 315 if (!CrossOriginAccessControl::handleRedirect( | |
| 316 m_origin, newRequest, redirectResponse, AllowStoredCredentials, | |
| 317 options, errorDescription)) { | |
| 318 if (frame()) { | |
| 319 if (frame()->document()) { | |
| 320 frame()->document()->addConsoleMessage(ConsoleMessage::create( | |
| 321 JSMessageSource, ErrorMessageLevel, errorDescription)); | |
| 322 } | |
| 323 } | 325 } |
| 324 // Cancel the load and self destruct. | |
| 325 dispose(); | |
| 326 | |
| 327 return false; | |
| 328 } | 326 } |
| 329 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of | 327 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of |
| 330 // Origin: following this successful redirect. | 328 // Origin: following this successful redirect. |
| 331 | 329 |
| 330 if (frame() && frame()->document()) { |
| 331 FetchInitiatorInfo initiatorInfo; |
| 332 initiatorInfo.name = m_initiator; |
| 333 FetchContext& fetchContext = frame()->document()->fetcher()->context(); |
| 334 fetchContext.dispatchWillSendRequest( |
| 335 m_identifier, passedNewRequest.toMutableResourceRequest(), |
| 336 passedRedirectResponse.toResourceResponse(), initiatorInfo); |
| 337 } |
| 338 |
| 332 return true; | 339 return true; |
| 333 } | 340 } |
| 334 | 341 |
| 335 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { | 342 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { |
| 336 if (frame()) { | 343 if (frame()) { |
| 337 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 344 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 338 InspectorResourceFinishEvent::data(m_identifier, 0, true, 0)); | 345 InspectorResourceFinishEvent::data(m_identifier, 0, true, 0)); |
| 339 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 346 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 340 InspectorInstrumentation::didReceiveResourceResponse( | 347 InspectorInstrumentation::didReceiveResourceResponse( |
| 341 frame(), m_identifier, 0, resourceResponse, 0); | 348 frame(), m_identifier, 0, resourceResponse, 0); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 bool PingLoader::sendBeacon(LocalFrame* frame, | 568 bool PingLoader::sendBeacon(LocalFrame* frame, |
| 562 int allowance, | 569 int allowance, |
| 563 const KURL& beaconURL, | 570 const KURL& beaconURL, |
| 564 Blob* data, | 571 Blob* data, |
| 565 int& payloadLength) { | 572 int& payloadLength) { |
| 566 BeaconBlob beacon(data); | 573 BeaconBlob beacon(data); |
| 567 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); | 574 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); |
| 568 } | 575 } |
| 569 | 576 |
| 570 } // namespace blink | 577 } // namespace blink |
| OLD | NEW |