| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/loader/PingLoader.h" | 32 #include "core/loader/PingLoader.h" |
| 33 | 33 |
| 34 #include "core/dom/DOMArrayBufferView.h" | 34 #include "core/dom/DOMArrayBufferView.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/SecurityContext.h" | 36 #include "core/dom/SecurityContext.h" |
| 37 #include "core/fetch/CrossOriginAccessControl.h" | 37 #include "core/fetch/CrossOriginAccessControl.h" |
| 38 #include "core/fetch/FetchContext.h" | 38 #include "core/fetch/FetchContext.h" |
| 39 #include "core/fetch/FetchInitiatorTypeNames.h" | 39 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 40 #include "core/fetch/FetchUtils.h" | 40 #include "core/fetch/FetchUtils.h" |
| 41 #include "core/fetch/ResourceFetcher.h" | 41 #include "core/fetch/ResourceFetcher.h" |
| 42 #include "core/fetch/ResourceLoaderOptions.h" | |
| 43 #include "core/fetch/UniqueIdentifier.h" | 42 #include "core/fetch/UniqueIdentifier.h" |
| 44 #include "core/fileapi/File.h" | 43 #include "core/fileapi/File.h" |
| 45 #include "core/frame/FrameConsole.h" | 44 #include "core/frame/FrameConsole.h" |
| 46 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
| 47 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 48 #include "core/html/FormData.h" | 47 #include "core/html/FormData.h" |
| 49 #include "core/inspector/ConsoleMessage.h" | 48 #include "core/inspector/ConsoleMessage.h" |
| 50 #include "core/inspector/InspectorInstrumentation.h" | 49 #include "core/inspector/InspectorInstrumentation.h" |
| 51 #include "core/inspector/InspectorTraceEvents.h" | 50 #include "core/inspector/InspectorTraceEvents.h" |
| 52 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
| 53 #include "core/loader/FrameLoaderClient.h" | 52 #include "core/loader/FrameLoaderClient.h" |
| 54 #include "core/loader/MixedContentChecker.h" | 53 #include "core/loader/MixedContentChecker.h" |
| 55 #include "core/page/Page.h" | 54 #include "core/page/Page.h" |
| 56 #include "platform/Timer.h" | |
| 57 #include "platform/WebFrameScheduler.h" | 55 #include "platform/WebFrameScheduler.h" |
| 58 #include "platform/exported/WrappedResourceRequest.h" | 56 #include "platform/exported/WrappedResourceRequest.h" |
| 59 #include "platform/exported/WrappedResourceResponse.h" | 57 #include "platform/exported/WrappedResourceResponse.h" |
| 60 #include "platform/heap/Handle.h" | |
| 61 #include "platform/heap/SelfKeepAlive.h" | |
| 62 #include "platform/network/EncodedFormData.h" | 58 #include "platform/network/EncodedFormData.h" |
| 63 #include "platform/network/ParsedContentType.h" | 59 #include "platform/network/ParsedContentType.h" |
| 64 #include "platform/network/ResourceError.h" | 60 #include "platform/network/ResourceError.h" |
| 65 #include "platform/network/ResourceRequest.h" | 61 #include "platform/network/ResourceRequest.h" |
| 66 #include "platform/network/ResourceResponse.h" | 62 #include "platform/network/ResourceResponse.h" |
| 67 #include "platform/weborigin/SecurityOrigin.h" | 63 #include "platform/weborigin/SecurityOrigin.h" |
| 68 #include "platform/weborigin/SecurityPolicy.h" | 64 #include "platform/weborigin/SecurityPolicy.h" |
| 69 #include "public/platform/Platform.h" | 65 #include "public/platform/Platform.h" |
| 70 #include "public/platform/WebURLLoader.h" | 66 #include "public/platform/WebURLLoader.h" |
| 71 #include "public/platform/WebURLLoaderClient.h" | |
| 72 #include "public/platform/WebURLRequest.h" | 67 #include "public/platform/WebURLRequest.h" |
| 73 #include "public/platform/WebURLResponse.h" | 68 #include "public/platform/WebURLResponse.h" |
| 74 #include "wtf/Compiler.h" | 69 #include "wtf/Compiler.h" |
| 75 #include "wtf/Functional.h" | 70 #include "wtf/Functional.h" |
| 76 #include "wtf/Noncopyable.h" | |
| 77 #include "wtf/PtrUtil.h" | 71 #include "wtf/PtrUtil.h" |
| 78 | 72 |
| 79 namespace blink { | 73 namespace blink { |
| 80 | 74 |
| 81 namespace { | 75 namespace { |
| 82 | 76 |
| 83 class Beacon { | 77 class Beacon { |
| 84 STACK_ALLOCATED(); | 78 STACK_ALLOCATED(); |
| 85 | 79 |
| 86 public: | 80 public: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 180 |
| 187 const AtomicString getContentType() const { return m_contentType; } | 181 const AtomicString getContentType() const { return m_contentType; } |
| 188 | 182 |
| 189 private: | 183 private: |
| 190 const Member<FormData> m_data; | 184 const Member<FormData> m_data; |
| 191 RefPtr<EncodedFormData> m_entityBody; | 185 RefPtr<EncodedFormData> m_entityBody; |
| 192 AtomicString m_contentType; | 186 AtomicString m_contentType; |
| 193 }; | 187 }; |
| 194 | 188 |
| 195 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, | 189 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
| 190 public DOMWindowProperty, |
| 196 private WebURLLoaderClient { | 191 private WebURLLoaderClient { |
| 192 USING_GARBAGE_COLLECTED_MIXIN(PingLoaderImpl); |
| 197 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); | 193 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); |
| 198 | 194 |
| 199 public: | 195 public: |
| 200 PingLoaderImpl(LocalFrame*, | 196 PingLoaderImpl(LocalFrame*, |
| 201 ResourceRequest&, | 197 ResourceRequest&, |
| 202 const AtomicString&, | 198 const AtomicString&, |
| 203 StoredCredentials, | 199 StoredCredentials, |
| 204 bool); | 200 bool); |
| 205 ~PingLoaderImpl() override; | 201 ~PingLoaderImpl() override; |
| 206 | 202 |
| 207 DECLARE_VIRTUAL_TRACE(); | 203 DECLARE_VIRTUAL_TRACE(); |
| 208 | 204 |
| 209 private: | 205 private: |
| 210 void dispose(); | 206 void dispose(); |
| 211 | 207 |
| 212 // WebURLLoaderClient | 208 // WebURLLoaderClient |
| 213 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; | 209 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; |
| 214 void didReceiveResponse(const WebURLResponse&) final; | 210 void didReceiveResponse(const WebURLResponse&) final; |
| 215 void didReceiveData(const char*, int) final; | 211 void didReceiveData(const char*, int) final; |
| 216 void didFinishLoading(double, int64_t, int64_t) final; | 212 void didFinishLoading(double, int64_t, int64_t) final; |
| 217 void didFail(const WebURLError&, int64_t, int64_t) final; | 213 void didFail(const WebURLError&, int64_t, int64_t) final; |
| 218 | 214 |
| 219 void timeout(TimerBase*); | 215 void timeout(TimerBase*); |
| 220 | 216 |
| 221 void didFailLoading(LocalFrame*); | 217 void didFailLoading(LocalFrame*); |
| 222 | 218 |
| 223 WeakMember<LocalFrame> m_frame; | |
| 224 std::unique_ptr<WebURLLoader> m_loader; | 219 std::unique_ptr<WebURLLoader> m_loader; |
| 225 Timer<PingLoaderImpl> m_timeout; | 220 Timer<PingLoaderImpl> m_timeout; |
| 226 String m_url; | 221 String m_url; |
| 227 unsigned long m_identifier; | 222 unsigned long m_identifier; |
| 228 SelfKeepAlive<PingLoaderImpl> m_keepAlive; | 223 SelfKeepAlive<PingLoaderImpl> m_keepAlive; |
| 229 | 224 |
| 230 bool m_isBeacon; | 225 bool m_isBeacon; |
| 231 | 226 |
| 232 RefPtr<SecurityOrigin> m_origin; | 227 RefPtr<SecurityOrigin> m_origin; |
| 233 CORSEnabled m_corsMode; | 228 CORSEnabled m_corsMode; |
| 234 }; | 229 }; |
| 235 | 230 |
| 236 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, | 231 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, |
| 237 ResourceRequest& request, | 232 ResourceRequest& request, |
| 238 const AtomicString& initiator, | 233 const AtomicString& initiator, |
| 239 StoredCredentials credentialsAllowed, | 234 StoredCredentials credentialsAllowed, |
| 240 bool isBeacon) | 235 bool isBeacon) |
| 241 : m_frame(frame), | 236 : DOMWindowProperty(frame), |
| 242 m_timeout(this, &PingLoaderImpl::timeout), | 237 m_timeout(this, &PingLoaderImpl::timeout), |
| 243 m_url(request.url()), | 238 m_url(request.url()), |
| 244 m_identifier(createUniqueIdentifier()), | 239 m_identifier(createUniqueIdentifier()), |
| 245 m_keepAlive(this), | 240 m_keepAlive(this), |
| 246 m_isBeacon(isBeacon), | 241 m_isBeacon(isBeacon), |
| 247 m_origin(frame->document()->getSecurityOrigin()), | 242 m_origin(frame->document()->getSecurityOrigin()), |
| 248 m_corsMode(IsCORSEnabled) { | 243 m_corsMode(IsCORSEnabled) { |
| 249 const AtomicString contentType = request.httpContentType(); | 244 const AtomicString contentType = request.httpContentType(); |
| 250 if (!contentType.isNull() && | 245 if (!contentType.isNull() && |
| 251 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) | 246 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DCHECK(!newRequest.isNull()); | 306 DCHECK(!newRequest.isNull()); |
| 312 DCHECK(!redirectResponse.isNull()); | 307 DCHECK(!redirectResponse.isNull()); |
| 313 | 308 |
| 314 String errorDescription; | 309 String errorDescription; |
| 315 ResourceLoaderOptions options; | 310 ResourceLoaderOptions options; |
| 316 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it | 311 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it |
| 317 // on the next time. | 312 // on the next time. |
| 318 if (!CrossOriginAccessControl::handleRedirect( | 313 if (!CrossOriginAccessControl::handleRedirect( |
| 319 m_origin, newRequest, redirectResponse, AllowStoredCredentials, | 314 m_origin, newRequest, redirectResponse, AllowStoredCredentials, |
| 320 options, errorDescription)) { | 315 options, errorDescription)) { |
| 321 if (m_frame) { | 316 if (LocalFrame* localFrame = frame()) { |
| 322 if (Document* document = m_frame->document()) { | 317 if (localFrame->document()) { |
| 323 document->addConsoleMessage(ConsoleMessage::create( | 318 localFrame->document()->addConsoleMessage(ConsoleMessage::create( |
| 324 JSMessageSource, ErrorMessageLevel, errorDescription)); | 319 JSMessageSource, ErrorMessageLevel, errorDescription)); |
| 325 } | 320 } |
| 326 } | 321 } |
| 327 // Cancel the load and self destruct. | 322 // Cancel the load and self destruct. |
| 328 dispose(); | 323 dispose(); |
| 329 | 324 |
| 330 return false; | 325 return false; |
| 331 } | 326 } |
| 332 // 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 |
| 333 // Origin: following this successful redirect. | 328 // Origin: following this successful redirect. |
| 334 | 329 |
| 335 return true; | 330 return true; |
| 336 } | 331 } |
| 337 | 332 |
| 338 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { | 333 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { |
| 339 if (m_frame) { | 334 if (LocalFrame* frame = this->frame()) { |
| 340 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 335 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 341 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 336 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 342 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 337 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 343 InspectorInstrumentation::didReceiveResourceResponse( | 338 InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, |
| 344 m_frame, m_identifier, 0, resourceResponse, 0); | 339 resourceResponse, 0); |
| 345 didFailLoading(m_frame); | 340 didFailLoading(frame); |
| 346 } | 341 } |
| 347 dispose(); | 342 dispose(); |
| 348 } | 343 } |
| 349 | 344 |
| 350 void PingLoaderImpl::didReceiveData(const char*, int) { | 345 void PingLoaderImpl::didReceiveData(const char*, int) { |
| 351 if (m_frame) { | 346 if (LocalFrame* frame = this->frame()) { |
| 352 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 347 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 353 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 348 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 354 didFailLoading(m_frame); | 349 didFailLoading(frame); |
| 355 } | 350 } |
| 356 dispose(); | 351 dispose(); |
| 357 } | 352 } |
| 358 | 353 |
| 359 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { | 354 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { |
| 360 if (m_frame) { | 355 if (LocalFrame* frame = this->frame()) { |
| 361 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 356 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 362 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 357 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 363 didFailLoading(m_frame); | 358 didFailLoading(frame); |
| 364 } | 359 } |
| 365 dispose(); | 360 dispose(); |
| 366 } | 361 } |
| 367 | 362 |
| 368 void PingLoaderImpl::didFail(const WebURLError& resourceError, | 363 void PingLoaderImpl::didFail(const WebURLError& resourceError, |
| 369 int64_t, | 364 int64_t, |
| 370 int64_t) { | 365 int64_t) { |
| 371 if (m_frame) { | 366 if (LocalFrame* frame = this->frame()) { |
| 372 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 367 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 373 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 368 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 374 didFailLoading(m_frame); | 369 didFailLoading(frame); |
| 375 } | 370 } |
| 376 dispose(); | 371 dispose(); |
| 377 } | 372 } |
| 378 | 373 |
| 379 void PingLoaderImpl::timeout(TimerBase*) { | 374 void PingLoaderImpl::timeout(TimerBase*) { |
| 380 if (m_frame) { | 375 if (LocalFrame* frame = this->frame()) { |
| 381 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 376 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 382 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 377 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 383 didFailLoading(m_frame); | 378 didFailLoading(frame); |
| 384 } | 379 } |
| 385 dispose(); | 380 dispose(); |
| 386 } | 381 } |
| 387 | 382 |
| 388 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { | 383 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { |
| 389 InspectorInstrumentation::didFailLoading( | 384 InspectorInstrumentation::didFailLoading( |
| 390 frame, m_identifier, ResourceError::cancelledError(m_url)); | 385 frame, m_identifier, ResourceError::cancelledError(m_url)); |
| 391 frame->console().didFailLoading(m_identifier, | 386 frame->console().didFailLoading(m_identifier, |
| 392 ResourceError::cancelledError(m_url)); | 387 ResourceError::cancelledError(m_url)); |
| 393 } | 388 } |
| 394 | 389 |
| 395 DEFINE_TRACE(PingLoaderImpl) { | 390 DEFINE_TRACE(PingLoaderImpl) { |
| 396 visitor->trace(m_frame); | 391 DOMWindowProperty::trace(visitor); |
| 397 } | 392 } |
| 398 | 393 |
| 399 void finishPingRequestInitialization( | 394 void finishPingRequestInitialization( |
| 400 ResourceRequest& request, | 395 ResourceRequest& request, |
| 401 LocalFrame* frame, | 396 LocalFrame* frame, |
| 402 WebURLRequest::RequestContext requestContext) { | 397 WebURLRequest::RequestContext requestContext) { |
| 403 request.setRequestContext(requestContext); | 398 request.setRequestContext(requestContext); |
| 404 FetchContext& fetchContext = frame->document()->fetcher()->context(); | 399 FetchContext& fetchContext = frame->document()->fetcher()->context(); |
| 405 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); | 400 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); |
| 406 fetchContext.populateRequestData(request); | 401 fetchContext.populateRequestData(request); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 bool PingLoader::sendBeacon(LocalFrame* frame, | 553 bool PingLoader::sendBeacon(LocalFrame* frame, |
| 559 int allowance, | 554 int allowance, |
| 560 const KURL& beaconURL, | 555 const KURL& beaconURL, |
| 561 Blob* data, | 556 Blob* data, |
| 562 int& payloadLength) { | 557 int& payloadLength) { |
| 563 BeaconBlob beacon(data); | 558 BeaconBlob beacon(data); |
| 564 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); | 559 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); |
| 565 } | 560 } |
| 566 | 561 |
| 567 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |