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

Side by Side Diff: third_party/WebKit/Source/core/loader/PingLoader.cpp

Issue 2383403002: Reflow comments in core/loader (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 unsigned long long size() const override { return m_data->byteLength(); } 142 unsigned long long size() const override { return m_data->byteLength(); }
143 143
144 void serialize(ResourceRequest& request) const override { 144 void serialize(ResourceRequest& request) const override {
145 DCHECK(m_data); 145 DCHECK(m_data);
146 146
147 RefPtr<EncodedFormData> entityBody = 147 RefPtr<EncodedFormData> entityBody =
148 EncodedFormData::create(m_data->baseAddress(), m_data->byteLength()); 148 EncodedFormData::create(m_data->baseAddress(), m_data->byteLength());
149 request.setHTTPBody(entityBody.release()); 149 request.setHTTPBody(entityBody.release());
150 150
151 // FIXME: a reasonable choice, but not in the spec; should it give a default ? 151 // FIXME: a reasonable choice, but not in the spec; should it give a
152 // default?
152 request.setHTTPContentType(AtomicString("application/octet-stream")); 153 request.setHTTPContentType(AtomicString("application/octet-stream"));
153 } 154 }
154 155
155 const AtomicString getContentType() const { return nullAtom; } 156 const AtomicString getContentType() const { return nullAtom; }
156 157
157 private: 158 private:
158 const Member<DOMArrayBufferView> m_data; 159 const Member<DOMArrayBufferView> m_data;
159 }; 160 };
160 161
161 class BeaconFormData final : public Beacon { 162 class BeaconFormData final : public Beacon {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 if (frame->frameScheduler()) 262 if (frame->frameScheduler())
262 frame->frameScheduler()->didStopLoading(m_identifier); 263 frame->frameScheduler()->didStopLoading(m_identifier);
263 264
264 m_loader = wrapUnique(Platform::current()->createURLLoader()); 265 m_loader = wrapUnique(Platform::current()->createURLLoader());
265 DCHECK(m_loader); 266 DCHECK(m_loader);
266 WrappedResourceRequest wrappedRequest(request); 267 WrappedResourceRequest wrappedRequest(request);
267 wrappedRequest.setAllowStoredCredentials(credentialsAllowed == 268 wrappedRequest.setAllowStoredCredentials(credentialsAllowed ==
268 AllowStoredCredentials); 269 AllowStoredCredentials);
269 m_loader->loadAsynchronously(wrappedRequest, this); 270 m_loader->loadAsynchronously(wrappedRequest, this);
270 271
271 // If the server never responds, FrameLoader won't be able to cancel this load and 272 // If the server never responds, FrameLoader won't be able to cancel this load
272 // we'll sit here waiting forever. Set a very generous timeout, just in case. 273 // and we'll sit here waiting forever. Set a very generous timeout, just in
274 // case.
273 m_timeout.startOneShot(60000, BLINK_FROM_HERE); 275 m_timeout.startOneShot(60000, BLINK_FROM_HERE);
274 } 276 }
275 277
276 PingLoaderImpl::~PingLoaderImpl() { 278 PingLoaderImpl::~PingLoaderImpl() {
277 if (m_loader) 279 if (m_loader)
278 m_loader->cancel(); 280 m_loader->cancel();
279 } 281 }
280 282
281 void PingLoaderImpl::dispose() { 283 void PingLoaderImpl::dispose() {
282 if (m_loader) { 284 if (m_loader) {
283 m_loader->cancel(); 285 m_loader->cancel();
284 m_loader = nullptr; 286 m_loader = nullptr;
285 } 287 }
286 m_timeout.stop(); 288 m_timeout.stop();
287 m_keepAlive.clear(); 289 m_keepAlive.clear();
288 } 290 }
289 291
290 void PingLoaderImpl::willFollowRedirect( 292 void PingLoaderImpl::willFollowRedirect(
291 WebURLLoader*, 293 WebURLLoader*,
292 WebURLRequest& passedNewRequest, 294 WebURLRequest& passedNewRequest,
293 const WebURLResponse& passedRedirectResponse, 295 const WebURLResponse& passedRedirectResponse,
294 int64_t encodedDataLength) { 296 int64_t encodedDataLength) {
295 if (!m_isBeacon) 297 if (!m_isBeacon)
296 return; 298 return;
297 299
298 // TODO(tyoshino): Check if setAllowStoredCredentials() should be called 300 // TODO(tyoshino): Check if setAllowStoredCredentials() should be called also
299 // also for non beacon cases. 301 // for non beacon cases.
300 passedNewRequest.setAllowStoredCredentials(true); 302 passedNewRequest.setAllowStoredCredentials(true);
301 if (m_corsMode == NotCORSEnabled) 303 if (m_corsMode == NotCORSEnabled)
302 return; 304 return;
303 305
304 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); 306 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest());
305 const ResourceResponse& redirectResponse( 307 const ResourceResponse& redirectResponse(
306 passedRedirectResponse.toResourceResponse()); 308 passedRedirectResponse.toResourceResponse());
307 309
308 DCHECK(!newRequest.isNull()); 310 DCHECK(!newRequest.isNull());
309 DCHECK(!redirectResponse.isNull()); 311 DCHECK(!redirectResponse.isNull());
310 312
311 String errorDescription; 313 String errorDescription;
312 ResourceLoaderOptions options; 314 ResourceLoaderOptions options;
313 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it 315 // TODO(tyoshino): Save updated data in options.securityOrigin and pass it
314 // on the next time. 316 // on the next time.
315 if (!CrossOriginAccessControl::handleRedirect( 317 if (!CrossOriginAccessControl::handleRedirect(
316 m_origin, newRequest, redirectResponse, AllowStoredCredentials, 318 m_origin, newRequest, redirectResponse, AllowStoredCredentials,
317 options, errorDescription)) { 319 options, errorDescription)) {
318 if (LocalFrame* localFrame = frame()) { 320 if (LocalFrame* localFrame = frame()) {
319 if (localFrame->document()) 321 if (localFrame->document())
320 localFrame->document()->addConsoleMessage(ConsoleMessage::create( 322 localFrame->document()->addConsoleMessage(ConsoleMessage::create(
321 JSMessageSource, ErrorMessageLevel, errorDescription)); 323 JSMessageSource, ErrorMessageLevel, errorDescription));
322 } 324 }
323 // Cancel the load and self destruct. 325 // Cancel the load and self destruct.
324 dispose(); 326 dispose();
325 // Signal WebURLLoader that the redirect musn't be followed. 327 // Signal WebURLLoader that the redirect musn't be followed.
326 passedNewRequest = WebURLRequest(); 328 passedNewRequest = WebURLRequest();
327 return; 329 return;
328 } 330 }
329 // FIXME: http://crbug.com/427429 is needed to correctly propagate 331 // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of
330 // updates of Origin: following this successful redirect. 332 // Origin: following this successful redirect.
331 } 333 }
332 334
333 void PingLoaderImpl::didReceiveResponse(WebURLLoader*, 335 void PingLoaderImpl::didReceiveResponse(WebURLLoader*,
334 const WebURLResponse& response) { 336 const WebURLResponse& response) {
335 if (LocalFrame* frame = this->frame()) { 337 if (LocalFrame* frame = this->frame()) {
336 TRACE_EVENT_INSTANT1( 338 TRACE_EVENT_INSTANT1(
337 "devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", 339 "devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data",
338 InspectorResourceFinishEvent::data(m_identifier, 0, true)); 340 InspectorResourceFinishEvent::data(m_identifier, 0, true));
339 const ResourceResponse& resourceResponse = response.toResourceResponse(); 341 const ResourceResponse& resourceResponse = response.toResourceResponse();
340 InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, 342 InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 408 }
407 409
408 bool sendPingCommon(LocalFrame* frame, 410 bool sendPingCommon(LocalFrame* frame,
409 ResourceRequest& request, 411 ResourceRequest& request,
410 const AtomicString& initiator, 412 const AtomicString& initiator,
411 StoredCredentials credentialsAllowed, 413 StoredCredentials credentialsAllowed,
412 bool isBeacon) { 414 bool isBeacon) {
413 if (MixedContentChecker::shouldBlockFetch(frame, request, request.url())) 415 if (MixedContentChecker::shouldBlockFetch(frame, request, request.url()))
414 return false; 416 return false;
415 417
416 // The loader keeps itself alive until it receives a response and disposes its elf. 418 // The loader keeps itself alive until it receives a response and disposes
419 // itself.
417 PingLoaderImpl* loader = new PingLoaderImpl(frame, request, initiator, 420 PingLoaderImpl* loader = new PingLoaderImpl(frame, request, initiator,
418 AllowStoredCredentials, true); 421 AllowStoredCredentials, true);
419 DCHECK(loader); 422 DCHECK(loader);
420 423
421 return true; 424 return true;
422 } 425 }
423 426
424 bool sendBeaconCommon(LocalFrame* frame, 427 bool sendBeaconCommon(LocalFrame* frame,
425 int allowance, 428 int allowance,
426 const KURL& url, 429 const KURL& url,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 return; 475 return;
473 476
474 ResourceRequest request(pingURL); 477 ResourceRequest request(pingURL);
475 request.setHTTPMethod(HTTPNames::POST); 478 request.setHTTPMethod(HTTPNames::POST);
476 request.setHTTPContentType("text/ping"); 479 request.setHTTPContentType("text/ping");
477 request.setHTTPBody(EncodedFormData::create("PING")); 480 request.setHTTPBody(EncodedFormData::create("PING"));
478 request.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=0"); 481 request.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=0");
479 finishPingRequestInitialization(request, frame, 482 finishPingRequestInitialization(request, frame,
480 WebURLRequest::RequestContextPing); 483 WebURLRequest::RequestContextPing);
481 484
482 // addAdditionalRequestHeaders() will have added a referrer for same origin re quests, 485 // addAdditionalRequestHeaders() will have added a referrer for same origin
483 // but the spec omits the referrer. 486 // requests, but the spec omits the referrer.
484 request.clearHTTPReferrer(); 487 request.clearHTTPReferrer();
485 488
486 request.setHTTPHeaderField(HTTPNames::Ping_To, 489 request.setHTTPHeaderField(HTTPNames::Ping_To,
487 AtomicString(destinationURL.getString())); 490 AtomicString(destinationURL.getString()));
488 491
489 RefPtr<SecurityOrigin> pingOrigin = SecurityOrigin::create(pingURL); 492 RefPtr<SecurityOrigin> pingOrigin = SecurityOrigin::create(pingURL);
490 if (protocolIs(frame->document()->url().getString(), "http") || 493 if (protocolIs(frame->document()->url().getString(), "http") ||
491 frame->document()->getSecurityOrigin()->canAccess(pingOrigin.get())) 494 frame->document()->getSecurityOrigin()->canAccess(pingOrigin.get()))
492 request.setHTTPHeaderField( 495 request.setHTTPHeaderField(
493 HTTPNames::Ping_From, 496 HTTPNames::Ping_From,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 bool PingLoader::sendBeacon(LocalFrame* frame, 552 bool PingLoader::sendBeacon(LocalFrame* frame,
550 int allowance, 553 int allowance,
551 const KURL& beaconURL, 554 const KURL& beaconURL,
552 Blob* data, 555 Blob* data,
553 int& payloadLength) { 556 int& payloadLength) {
554 BeaconBlob beacon(data); 557 BeaconBlob beacon(data);
555 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 558 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
556 } 559 }
557 560
558 } // namespace blink 561 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698