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

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

Issue 2753863003: Clarify Beacon transmission limit checking. (Closed)
Patch Set: rebased upto r459528 Created 3 years, 9 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 413
414 // The loader keeps itself alive until it receives a response and disposes 414 // The loader keeps itself alive until it receives a response and disposes
415 // itself. 415 // itself.
416 PingLoaderImpl* loader = 416 PingLoaderImpl* loader =
417 new PingLoaderImpl(frame, request, initiator, credentialsAllowed, true); 417 new PingLoaderImpl(frame, request, initiator, credentialsAllowed, true);
418 DCHECK(loader); 418 DCHECK(loader);
419 419
420 return true; 420 return true;
421 } 421 }
422 422
423 // Decide if a beacon with the given size is allowed to go ahead
424 // given some overall allowance limit.
425 bool allowBeaconWithSize(int allowance, unsigned long long size) {
426 // If a negative allowance is supplied, no size constraint is imposed.
427 if (allowance < 0)
428 return true;
429
430 if (static_cast<unsigned long long>(allowance) < size)
431 return false;
432
433 return true;
434 }
435
423 bool sendBeaconCommon(LocalFrame* frame, 436 bool sendBeaconCommon(LocalFrame* frame,
424 int allowance, 437 int allowance,
425 const KURL& url, 438 const KURL& url,
426 const Beacon& beacon, 439 const Beacon& beacon,
427 int& payloadLength) { 440 size_t& beaconSize) {
428 if (!frame->document()) 441 if (!frame->document())
429 return false; 442 return false;
430 443
431 // TODO(mkwst): CSP is not enforced on redirects, crbug.com/372197 444 // TODO(mkwst): CSP is not enforced on redirects, crbug.com/372197
432 if (!ContentSecurityPolicy::shouldBypassMainWorld(frame->document()) && 445 if (!ContentSecurityPolicy::shouldBypassMainWorld(frame->document()) &&
433 !frame->document()->contentSecurityPolicy()->allowConnectToSource(url)) { 446 !frame->document()->contentSecurityPolicy()->allowConnectToSource(url)) {
434 // We're simulating a network failure here, so we return 'true'. 447 // We're simulating a network failure here, so we return 'true'.
435 return true; 448 return true;
436 } 449 }
437 450
438 unsigned long long entitySize = beacon.size(); 451 unsigned long long size = beacon.size();
439 if (allowance < 0 || static_cast<unsigned long long>(allowance) < entitySize) 452 if (!allowBeaconWithSize(allowance, size))
440 return false; 453 return false;
441 454
442 payloadLength = entitySize; 455 beaconSize = size;
443 456
444 ResourceRequest request(url); 457 ResourceRequest request(url);
445 request.setHTTPMethod(HTTPNames::POST); 458 request.setHTTPMethod(HTTPNames::POST);
446 request.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=0"); 459 request.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=0");
447 finishPingRequestInitialization(request, frame, 460 finishPingRequestInitialization(request, frame,
448 WebURLRequest::RequestContextBeacon); 461 WebURLRequest::RequestContextBeacon);
449 462
450 beacon.serialize(request); 463 beacon.serialize(request);
451 464
452 return sendPingCommon(frame, request, FetchInitiatorTypeNames::beacon, 465 return sendPingCommon(frame, request, FetchInitiatorTypeNames::beacon,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 ? AllowStoredCredentials 547 ? AllowStoredCredentials
535 : DoNotAllowStoredCredentials; 548 : DoNotAllowStoredCredentials;
536 sendPingCommon(frame, request, FetchInitiatorTypeNames::violationreport, 549 sendPingCommon(frame, request, FetchInitiatorTypeNames::violationreport,
537 credentialsAllowed, false); 550 credentialsAllowed, false);
538 } 551 }
539 552
540 bool PingLoader::sendBeacon(LocalFrame* frame, 553 bool PingLoader::sendBeacon(LocalFrame* frame,
541 int allowance, 554 int allowance,
542 const KURL& beaconURL, 555 const KURL& beaconURL,
543 const String& data, 556 const String& data,
544 int& payloadLength) { 557 size_t& beaconSize) {
545 BeaconString beacon(data); 558 BeaconString beacon(data);
546 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 559 return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
547 } 560 }
548 561
549 bool PingLoader::sendBeacon(LocalFrame* frame, 562 bool PingLoader::sendBeacon(LocalFrame* frame,
550 int allowance, 563 int allowance,
551 const KURL& beaconURL, 564 const KURL& beaconURL,
552 DOMArrayBufferView* data, 565 DOMArrayBufferView* data,
553 int& payloadLength) { 566 size_t& beaconSize) {
554 BeaconDOMArrayBufferView beacon(data); 567 BeaconDOMArrayBufferView beacon(data);
555 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 568 return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
556 } 569 }
557 570
558 bool PingLoader::sendBeacon(LocalFrame* frame, 571 bool PingLoader::sendBeacon(LocalFrame* frame,
559 int allowance, 572 int allowance,
560 const KURL& beaconURL, 573 const KURL& beaconURL,
561 FormData* data, 574 FormData* data,
562 int& payloadLength) { 575 size_t& beaconSize) {
563 BeaconFormData beacon(data); 576 BeaconFormData beacon(data);
564 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 577 return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
565 } 578 }
566 579
567 bool PingLoader::sendBeacon(LocalFrame* frame, 580 bool PingLoader::sendBeacon(LocalFrame* frame,
568 int allowance, 581 int allowance,
569 const KURL& beaconURL, 582 const KURL& beaconURL,
570 Blob* data, 583 Blob* data,
571 int& payloadLength) { 584 size_t& beaconSize) {
572 BeaconBlob beacon(data); 585 BeaconBlob beacon(data);
573 return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength); 586 return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
574 } 587 }
575 588
576 } // namespace blink 589 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/PingLoader.h ('k') | third_party/WebKit/Source/modules/beacon/NavigatorBeacon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698