Chromium Code Reviews| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 } | 179 } |
| 180 | 180 |
| 181 const AtomicString getContentType() const { return m_contentType; } | 181 const AtomicString getContentType() const { return m_contentType; } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 const Member<FormData> m_data; | 184 const Member<FormData> m_data; |
| 185 RefPtr<EncodedFormData> m_entityBody; | 185 RefPtr<EncodedFormData> m_entityBody; |
| 186 AtomicString m_contentType; | 186 AtomicString m_contentType; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, | 189 class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
|
sof
2016/12/12 07:48:21
final
| |
| 190 public DOMWindowProperty, | |
| 191 private WebURLLoaderClient { | 190 private WebURLLoaderClient { |
| 192 USING_GARBAGE_COLLECTED_MIXIN(PingLoaderImpl); | |
| 193 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); | 191 WTF_MAKE_NONCOPYABLE(PingLoaderImpl); |
| 194 | 192 |
| 195 public: | 193 public: |
| 196 PingLoaderImpl(LocalFrame*, | 194 PingLoaderImpl(LocalFrame*, |
| 197 ResourceRequest&, | 195 ResourceRequest&, |
| 198 const AtomicString&, | 196 const AtomicString&, |
| 199 StoredCredentials, | 197 StoredCredentials, |
| 200 bool); | 198 bool); |
| 201 ~PingLoaderImpl() override; | 199 ~PingLoaderImpl() override; |
| 202 | 200 |
| 203 DECLARE_VIRTUAL_TRACE(); | 201 DECLARE_VIRTUAL_TRACE(); |
|
sof
2016/12/12 07:48:21
Can be DECLARE_TRACE() now.
| |
| 204 | 202 |
| 205 private: | 203 private: |
| 206 void dispose(); | 204 void dispose(); |
| 207 | 205 |
| 208 // WebURLLoaderClient | 206 // WebURLLoaderClient |
| 209 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; | 207 bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; |
| 210 void didReceiveResponse(const WebURLResponse&) final; | 208 void didReceiveResponse(const WebURLResponse&) final; |
| 211 void didReceiveData(const char*, int) final; | 209 void didReceiveData(const char*, int) final; |
| 212 void didFinishLoading(double, int64_t, int64_t) final; | 210 void didFinishLoading(double, int64_t, int64_t) final; |
| 213 void didFail(const WebURLError&, int64_t, int64_t) final; | 211 void didFail(const WebURLError&, int64_t, int64_t) final; |
| 214 | 212 |
| 215 void timeout(TimerBase*); | 213 void timeout(TimerBase*); |
| 216 | 214 |
| 217 void didFailLoading(LocalFrame*); | 215 void didFailLoading(LocalFrame*); |
| 218 | 216 |
| 217 WeakMember<LocalFrame> m_frame; | |
| 219 std::unique_ptr<WebURLLoader> m_loader; | 218 std::unique_ptr<WebURLLoader> m_loader; |
| 220 Timer<PingLoaderImpl> m_timeout; | 219 Timer<PingLoaderImpl> m_timeout; |
| 221 String m_url; | 220 String m_url; |
| 222 unsigned long m_identifier; | 221 unsigned long m_identifier; |
| 223 SelfKeepAlive<PingLoaderImpl> m_keepAlive; | 222 SelfKeepAlive<PingLoaderImpl> m_keepAlive; |
| 224 | 223 |
| 225 bool m_isBeacon; | 224 bool m_isBeacon; |
| 226 | 225 |
| 227 RefPtr<SecurityOrigin> m_origin; | 226 RefPtr<SecurityOrigin> m_origin; |
| 228 CORSEnabled m_corsMode; | 227 CORSEnabled m_corsMode; |
| 229 }; | 228 }; |
| 230 | 229 |
| 231 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, | 230 PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, |
| 232 ResourceRequest& request, | 231 ResourceRequest& request, |
| 233 const AtomicString& initiator, | 232 const AtomicString& initiator, |
| 234 StoredCredentials credentialsAllowed, | 233 StoredCredentials credentialsAllowed, |
| 235 bool isBeacon) | 234 bool isBeacon) |
| 236 : DOMWindowProperty(frame), | 235 : m_frame(frame), |
| 237 m_timeout(this, &PingLoaderImpl::timeout), | 236 m_timeout(this, &PingLoaderImpl::timeout), |
| 238 m_url(request.url()), | 237 m_url(request.url()), |
| 239 m_identifier(createUniqueIdentifier()), | 238 m_identifier(createUniqueIdentifier()), |
| 240 m_keepAlive(this), | 239 m_keepAlive(this), |
| 241 m_isBeacon(isBeacon), | 240 m_isBeacon(isBeacon), |
| 242 m_origin(frame->document()->getSecurityOrigin()), | 241 m_origin(frame->document()->getSecurityOrigin()), |
| 243 m_corsMode(IsCORSEnabled) { | 242 m_corsMode(IsCORSEnabled) { |
| 244 const AtomicString contentType = request.httpContentType(); | 243 const AtomicString contentType = request.httpContentType(); |
| 245 if (!contentType.isNull() && | 244 if (!contentType.isNull() && |
| 246 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) | 245 FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 DCHECK(!newRequest.isNull()); | 305 DCHECK(!newRequest.isNull()); |
| 307 DCHECK(!redirectResponse.isNull()); | 306 DCHECK(!redirectResponse.isNull()); |
| 308 | 307 |
| 309 String errorDescription; | 308 String errorDescription; |
| 310 ResourceLoaderOptions options; | 309 ResourceLoaderOptions options; |
| 311 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it | 310 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it |
| 312 // on the next time. | 311 // on the next time. |
| 313 if (!CrossOriginAccessControl::handleRedirect( | 312 if (!CrossOriginAccessControl::handleRedirect( |
| 314 m_origin, newRequest, redirectResponse, AllowStoredCredentials, | 313 m_origin, newRequest, redirectResponse, AllowStoredCredentials, |
| 315 options, errorDescription)) { | 314 options, errorDescription)) { |
| 316 if (LocalFrame* localFrame = frame()) { | 315 if (m_frame) { |
|
sof
2016/12/12 07:48:21
if (m_frame && m_frame->document()) { ... }
or if
| |
| 317 if (localFrame->document()) { | 316 if (m_frame->document()) { |
| 318 localFrame->document()->addConsoleMessage(ConsoleMessage::create( | 317 m_frame->document()->addConsoleMessage(ConsoleMessage::create( |
| 319 JSMessageSource, ErrorMessageLevel, errorDescription)); | 318 JSMessageSource, ErrorMessageLevel, errorDescription)); |
| 320 } | 319 } |
| 321 } | 320 } |
| 322 // Cancel the load and self destruct. | 321 // Cancel the load and self destruct. |
| 323 dispose(); | 322 dispose(); |
| 324 | 323 |
| 325 return false; | 324 return false; |
| 326 } | 325 } |
| 327 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of | 326 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of |
| 328 // Origin: following this successful redirect. | 327 // Origin: following this successful redirect. |
| 329 | 328 |
| 330 return true; | 329 return true; |
| 331 } | 330 } |
| 332 | 331 |
| 333 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { | 332 void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { |
| 334 if (LocalFrame* frame = this->frame()) { | 333 if (m_frame) { |
| 335 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 334 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 336 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 335 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 337 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 336 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 338 InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, | 337 InspectorInstrumentation::didReceiveResourceResponse( |
| 339 resourceResponse, 0); | 338 m_frame, m_identifier, 0, resourceResponse, 0); |
| 340 didFailLoading(frame); | 339 didFailLoading(m_frame); |
| 341 } | 340 } |
| 342 dispose(); | 341 dispose(); |
| 343 } | 342 } |
| 344 | 343 |
| 345 void PingLoaderImpl::didReceiveData(const char*, int) { | 344 void PingLoaderImpl::didReceiveData(const char*, int) { |
| 346 if (LocalFrame* frame = this->frame()) { | 345 if (m_frame) { |
| 347 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 346 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 348 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 347 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 349 didFailLoading(frame); | 348 didFailLoading(m_frame); |
| 350 } | 349 } |
| 351 dispose(); | 350 dispose(); |
| 352 } | 351 } |
| 353 | 352 |
| 354 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { | 353 void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { |
| 355 if (LocalFrame* frame = this->frame()) { | 354 if (m_frame) { |
| 356 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 355 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 357 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 356 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 358 didFailLoading(frame); | 357 didFailLoading(m_frame); |
| 359 } | 358 } |
| 360 dispose(); | 359 dispose(); |
| 361 } | 360 } |
| 362 | 361 |
| 363 void PingLoaderImpl::didFail(const WebURLError& resourceError, | 362 void PingLoaderImpl::didFail(const WebURLError& resourceError, |
| 364 int64_t, | 363 int64_t, |
| 365 int64_t) { | 364 int64_t) { |
| 366 if (LocalFrame* frame = this->frame()) { | 365 if (m_frame) { |
| 367 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 366 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 368 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 367 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 369 didFailLoading(frame); | 368 didFailLoading(m_frame); |
| 370 } | 369 } |
| 371 dispose(); | 370 dispose(); |
| 372 } | 371 } |
| 373 | 372 |
| 374 void PingLoaderImpl::timeout(TimerBase*) { | 373 void PingLoaderImpl::timeout(TimerBase*) { |
| 375 if (LocalFrame* frame = this->frame()) { | 374 if (m_frame) { |
| 376 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", | 375 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 377 InspectorResourceFinishEvent::data(m_identifier, 0, true)); | 376 InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
| 378 didFailLoading(frame); | 377 didFailLoading(m_frame); |
| 379 } | 378 } |
| 380 dispose(); | 379 dispose(); |
| 381 } | 380 } |
| 382 | 381 |
| 383 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { | 382 void PingLoaderImpl::didFailLoading(LocalFrame* frame) { |
| 384 InspectorInstrumentation::didFailLoading( | 383 InspectorInstrumentation::didFailLoading( |
| 385 frame, m_identifier, ResourceError::cancelledError(m_url)); | 384 frame, m_identifier, ResourceError::cancelledError(m_url)); |
| 386 frame->console().didFailLoading(m_identifier, | 385 frame->console().didFailLoading(m_identifier, |
| 387 ResourceError::cancelledError(m_url)); | 386 ResourceError::cancelledError(m_url)); |
| 388 } | 387 } |
| 389 | 388 |
| 390 DEFINE_TRACE(PingLoaderImpl) { | 389 DEFINE_TRACE(PingLoaderImpl) { |
| 391 DOMWindowProperty::trace(visitor); | 390 visitor->trace(m_frame); |
| 392 } | 391 } |
| 393 | 392 |
| 394 void finishPingRequestInitialization( | 393 void finishPingRequestInitialization( |
| 395 ResourceRequest& request, | 394 ResourceRequest& request, |
| 396 LocalFrame* frame, | 395 LocalFrame* frame, |
| 397 WebURLRequest::RequestContext requestContext) { | 396 WebURLRequest::RequestContext requestContext) { |
| 398 request.setRequestContext(requestContext); | 397 request.setRequestContext(requestContext); |
| 399 FetchContext& fetchContext = frame->document()->fetcher()->context(); | 398 FetchContext& fetchContext = frame->document()->fetcher()->context(); |
| 400 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); | 399 fetchContext.addAdditionalRequestHeaders(request, FetchSubresource); |
| 401 fetchContext.populateRequestData(request); | 400 fetchContext.populateRequestData(request); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 bool PingLoader::sendBeacon(LocalFrame* frame, | 552 bool PingLoader::sendBeacon(LocalFrame* frame, |
| 554 int allowance, | 553 int allowance, |
| 555 const KURL& beaconURL, | 554 const KURL& beaconURL, |
| 556 Blob* data, | 555 Blob* data, |
| 557 int& payloadLength) { | 556 int& payloadLength) { |
| 558 BeaconBlob beacon(data); | 557 BeaconBlob beacon(data); |
| 559 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); | 558 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); |
| 560 } | 559 } |
| 561 | 560 |
| 562 } // namespace blink | 561 } // namespace blink |
| OLD | NEW |