| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 * | 29 * |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "core/loader/PingLoader.h" | 32 #include "core/loader/PingLoader.h" |
| 33 | 33 |
| 34 #include "core/dom/ContextLifecycleObserver.h" |
| 34 #include "core/dom/DOMArrayBufferView.h" | 35 #include "core/dom/DOMArrayBufferView.h" |
| 35 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 36 #include "core/dom/SecurityContext.h" | 37 #include "core/dom/SecurityContext.h" |
| 37 #include "core/fetch/CrossOriginAccessControl.h" | 38 #include "core/fetch/CrossOriginAccessControl.h" |
| 38 #include "core/fetch/FetchContext.h" | 39 #include "core/fetch/FetchContext.h" |
| 39 #include "core/fetch/FetchInitiatorTypeNames.h" | 40 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 40 #include "core/fetch/FetchUtils.h" | 41 #include "core/fetch/FetchUtils.h" |
| 41 #include "core/fetch/ResourceFetcher.h" | 42 #include "core/fetch/ResourceFetcher.h" |
| 42 #include "core/fetch/UniqueIdentifier.h" | 43 #include "core/fetch/UniqueIdentifier.h" |
| 43 #include "core/fileapi/File.h" | 44 #include "core/fileapi/File.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 181 |
| 181 const AtomicString getContentType() const { return m_contentType; } | 182 const AtomicString getContentType() const { return m_contentType; } |
| 182 | 183 |
| 183 private: | 184 private: |
| 184 const Member<FormData> m_data; | 185 const Member<FormData> m_data; |
| 185 RefPtr<EncodedFormData> m_entityBody; | 186 RefPtr<EncodedFormData> m_entityBody; |
| 186 AtomicString m_contentType; | 187 AtomicString m_contentType; |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, | 190 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
| 191 public ContextClient, |
| 190 private WebURLLoaderClient { | 192 private WebURLLoaderClient { |
| 193 USING_GARBAGE_COLLECTED_MIXIN(PingLoaderImpl); |
| 191 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); | 194 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); |
| 192 | 195 |
| 193 public: | 196 public: |
| 194 PingLoaderImpl(LocalFrame*, | 197 PingLoaderImpl(LocalFrame*, |
| 195 ResourceRequest&, | 198 ResourceRequest&, |
| 196 const AtomicString&, | 199 const AtomicString&, |
| 197 StoredCredentials, | 200 StoredCredentials, |
| 198 bool); | 201 bool); |
| 199 ~PingLoaderImpl() override; | 202 ~PingLoaderImpl() override; |
| 200 | 203 |
| 201 DECLARE_VIRTUAL_TRACE(); | 204 DECLARE_VIRTUAL_TRACE(); |
| 202 | 205 |
| 203 private: | 206 private: |
| 204 void dispose(); | 207 void dispose(); |
| 205 | 208 |
| 206 // WebURLLoaderClient | 209 // WebURLLoaderClient |
| 207 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; | 210 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; |
| 208 void didReceiveResponse(const WebURLResponse&) final; | 211 void didReceiveResponse(const WebURLResponse&) final; |
| 209 void didReceiveData(const char*, int) final; | 212 void didReceiveData(const char*, int) final; |
| 210 void didFinishLoading(double, int64_t, int64_t) final; | 213 void didFinishLoading(double, int64_t, int64_t) final; |
| 211 void didFail(const WebURLError&, int64_t, int64_t) final; | 214 void didFail(const WebURLError&, int64_t, int64_t) final; |
| 212 | 215 |
| 213 void timeout(TimerBase*); | 216 void timeout(TimerBase*); |
| 214 | 217 |
| 215 void didFailLoading(LocalFrame*); | 218 void didFailLoading(LocalFrame*); |
| 216 | 219 |
| 217 WeakMember<LocalFrame> m_frame; | |
| 218 std::unique_ptr<WebURLLoader> m_loader; | 220 std::unique_ptr<WebURLLoader> m_loader; |
| 219 Timer<PingLoaderImpl> m_timeout; | 221 Timer<PingLoaderImpl> m_timeout; |
| 220 String m_url; | 222 String m_url; |
| 221 unsigned long m_identifier; | 223 unsigned long m_identifier; |
| 222 SelfKeepAlive<PingLoaderImpl> m_keepAlive; | 224 SelfKeepAlive<PingLoaderImpl> m_keepAlive; |
| 223 | 225 |
| 224 bool m_isBeacon; | 226 bool m_isBeacon; |
| 225 | 227 |
| 226 RefPtr<SecurityOrigin> m_origin; | 228 RefPtr<SecurityOrigin> m_origin; |
| 227 CORSEnabled m_corsMode; | 229 CORSEnabled m_corsMode; |
| 228 }; | 230 }; |
| 229 | 231 |
| 230 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, | 232 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, |
| 231 ResourceRequest& request, | 233 ResourceRequest& request, |
| 232 const AtomicString& initiator, | 234 const AtomicString& initiator, |
| 233 StoredCredentials credentialsAllowed, | 235 StoredCredentials credentialsAllowed, |
| 234 bool isBeacon) | 236 bool isBeacon) |
| 235 : m_frame(frame), | 237 : ContextClient(frame), |
| 236 m_timeout(this, &PingLoaderImpl::timeout), | 238 m_timeout(this, &PingLoaderImpl::timeout), |
| 237 m_url(request.url()), | 239 m_url(request.url()), |
| 238 m_identifier(createUniqueIdentifier()), | 240 m_identifier(createUniqueIdentifier()), |
| 239 m_keepAlive(this), | 241 m_keepAlive(this), |
| 240 m_isBeacon(isBeacon), | 242 m_isBeacon(isBeacon), |
| 241 m_origin(frame->document()->getSecurityOrigin()), | 243 m_origin(frame->document()->getSecurityOrigin()), |
| 242 m_corsMode(IsCORSEnabled) { | 244 m_corsMode(IsCORSEnabled) { |
| 243 const AtomicString contentType = request.httpContentType(); | 245 const AtomicString contentType = request.httpContentType(); |
| 244 if (!contentType.isNull() && | 246 if (!contentType.isNull() && |
| 245 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) | 247 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 DCHECK(!newRequest.isNull()); | 308 DCHECK(!newRequest.isNull()); |
| 307 DCHECK(!redirectResponse.isNull()); | 309 DCHECK(!redirectResponse.isNull()); |
| 308 | 310 |
| 309 String errorDescription; | 311 String errorDescription; |
| 310 ResourceLoaderOptions options; | 312 ResourceLoaderOptions options; |
| 311 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it | 313 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it |
| 312 // on the next time. | 314 // on the next time. |
| 313 if (!CrossOriginAccessControl::handleRedirect( | 315 if (!CrossOriginAccessControl::handleRedirect( |
| 314 m_origin, newRequest, redirectResponse, AllowStoredCredentials, | 316 m_origin, newRequest, redirectResponse, AllowStoredCredentials, |
| 315 options, errorDescription)) { | 317 options, errorDescription)) { |
| 316 if (m_frame) { | 318 if (frame()) { |
| 317 if (m_frame->document()) { | 319 if (frame()->document()) { |
| 318 m_frame->document()->addConsoleMessage(ConsoleMessage::create( | 320 frame()->document()->addConsoleMessage(ConsoleMessage::create( |
| 319 JSMessageSource, ErrorMessageLevel, errorDescription)); | 321 JSMessageSource, ErrorMessageLevel, errorDescription)); |
| 320 } | 322 } |
| 321 } | 323 } |
| 322 // Cancel the load and self destruct. | 324 // Cancel the load and self destruct. |
| 323 dispose(); | 325 dispose(); |
| 324 | 326 |
| 325 return false; | 327 return false; |
| 326 } | 328 } |
| 327 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of | 329 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of |
| 328 // Origin: following this successful redirect. | 330 // Origin: following this successful redirect. |
| 329 | 331 |
| 330 return true; | 332 return true; |
| 331 } | 333 } |
| 332 | 334 |
| 333 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { | 335 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { |
| 334 if (m_frame) { | 336 if (frame()) { |
| 335 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 337 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 336 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 338 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 337 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 339 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 338 InspectorInstrumentation::didReceiveResourceResponse( | 340 InspectorInstrumentation::didReceiveResourceResponse( |
| 339 m_frame, m_identifier, 0, resourceResponse, 0); | 341 frame(), m_identifier, 0, resourceResponse, 0); |
| 340 didFailLoading(m_frame); | 342 didFailLoading(frame()); |
| 341 } | 343 } |
| 342 dispose(); | 344 dispose(); |
| 343 } | 345 } |
| 344 | 346 |
| 345 void PingLoaderImpl::didReceiveData(const char*, int) { | 347 void PingLoaderImpl::didReceiveData(const char*, int) { |
| 346 if (m_frame) { | 348 if (frame()) { |
| 347 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 349 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 348 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 350 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 349 didFailLoading(m_frame); | 351 didFailLoading(frame()); |
| 350 } | 352 } |
| 351 dispose(); | 353 dispose(); |
| 352 } | 354 } |
| 353 | 355 |
| 354 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { | 356 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { |
| 355 if (m_frame) { | 357 if (frame()) { |
| 356 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 358 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 357 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 359 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 358 didFailLoading(m_frame); | 360 didFailLoading(frame()); |
| 359 } | 361 } |
| 360 dispose(); | 362 dispose(); |
| 361 } | 363 } |
| 362 | 364 |
| 363 void PingLoaderImpl::didFail(const WebURLError& resourceError, | 365 void PingLoaderImpl::didFail(const WebURLError& resourceError, |
| 364 int64_t, | 366 int64_t, |
| 365 int64_t) { | 367 int64_t) { |
| 366 if (m_frame) { | 368 if (frame()) { |
| 367 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 369 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 368 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 370 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 369 didFailLoading(m_frame); | 371 didFailLoading(frame()); |
| 370 } | 372 } |
| 371 dispose(); | 373 dispose(); |
| 372 } | 374 } |
| 373 | 375 |
| 374 void PingLoaderImpl::timeout(TimerBase*) { | 376 void PingLoaderImpl::timeout(TimerBase*) { |
| 375 if (m_frame) { | 377 if (frame()) { |
| 376 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 378 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 377 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 379 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 378 didFailLoading(m_frame); | 380 didFailLoading(frame()); |
| 379 } | 381 } |
| 380 dispose(); | 382 dispose(); |
| 381 } | 383 } |
| 382 | 384 |
| 383 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { | 385 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { |
| 384 InspectorInstrumentation::didFailLoading( | 386 InspectorInstrumentation::didFailLoading( |
| 385 frame, m_identifier, ResourceError::cancelledError(m_url)); | 387 frame, m_identifier, ResourceError::cancelledError(m_url)); |
| 386 frame->console().didFailLoading(m_identifier, | 388 frame->console().didFailLoading(m_identifier, |
| 387 ResourceError::cancelledError(m_url)); | 389 ResourceError::cancelledError(m_url)); |
| 388 } | 390 } |
| 389 | 391 |
| 390 DEFINE_TRACE(PingLoaderImpl) { | 392 DEFINE_TRACE(PingLoaderImpl) { |
| 391 visitor->trace(m_frame); | 393 ContextClient::trace(visitor); |
| 392 } | 394 } |
| 393 | 395 |
| 394 void finishPingRequestInitialization( | 396 void finishPingRequestInitialization( |
| 395 ResourceRequest& request, | 397 ResourceRequest& request, |
| 396 LocalFrame* frame, | 398 LocalFrame* frame, |
| 397 WebURLRequest::RequestContext requestContext) { | 399 WebURLRequest::RequestContext requestContext) { |
| 398 request.setRequestContext(requestContext); | 400 request.setRequestContext(requestContext); |
| 399 FetchContext& fetchContext = frame->document()->fetcher()->context(); | 401 FetchContext& fetchContext = frame->document()->fetcher()->context(); |
| 400 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); | 402 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); |
| 401 fetchContext.populateRequestData(request); | 403 fetchContext.populateRequestData(request); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 bool PingLoader::sendBeacon(LocalFrame* frame, | 555 bool PingLoader::sendBeacon(LocalFrame* frame, |
| 554 int allowance, | 556 int allowance, |
| 555 const KURL& beaconURL, | 557 const KURL& beaconURL, |
| 556 Blob* data, | 558 Blob* data, |
| 557 int& payloadLength) { | 559 int& payloadLength) { |
| 558 BeaconBlob beacon(data); | 560 BeaconBlob beacon(data); |
| 559 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); | 561 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); |
| 560 } | 562 } |
| 561 | 563 |
| 562 } // namespace blink | 564 } // namespace blink |
| OLD | NEW |