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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/PingLoader.cpp
diff --git a/third_party/WebKit/Source/core/loader/PingLoader.cpp b/third_party/WebKit/Source/core/loader/PingLoader.cpp
index fa733126c2e6906bda7f77904539d4f836d55821..874cfe138c6127e5ce0f3438682f147278c816ab 100644
--- a/third_party/WebKit/Source/core/loader/PingLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/PingLoader.cpp
@@ -420,11 +420,24 @@ bool sendPingCommon(LocalFrame* frame,
return true;
}
+// Decide if a beacon with the given size is allowed to go ahead
+// given some overall allowance limit.
+bool allowBeaconWithSize(int allowance, unsigned long long size) {
+ // If a negative allowance is supplied, no size constraint is imposed.
+ if (allowance < 0)
+ return true;
+
+ if (static_cast<unsigned long long>(allowance) < size)
+ return false;
+
+ return true;
+}
+
bool sendBeaconCommon(LocalFrame* frame,
int allowance,
const KURL& url,
const Beacon& beacon,
- int& payloadLength) {
+ size_t& beaconSize) {
if (!frame->document())
return false;
@@ -435,11 +448,11 @@ bool sendBeaconCommon(LocalFrame* frame,
return true;
}
- unsigned long long entitySize = beacon.size();
- if (allowance < 0 || static_cast<unsigned long long>(allowance) < entitySize)
+ unsigned long long size = beacon.size();
+ if (!allowBeaconWithSize(allowance, size))
return false;
- payloadLength = entitySize;
+ beaconSize = size;
ResourceRequest request(url);
request.setHTTPMethod(HTTPNames::POST);
@@ -541,36 +554,36 @@ bool PingLoader::sendBeacon(LocalFrame* frame,
int allowance,
const KURL& beaconURL,
const String& data,
- int& payloadLength) {
+ size_t& beaconSize) {
BeaconString beacon(data);
- return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
+ return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
}
bool PingLoader::sendBeacon(LocalFrame* frame,
int allowance,
const KURL& beaconURL,
DOMArrayBufferView* data,
- int& payloadLength) {
+ size_t& beaconSize) {
BeaconDOMArrayBufferView beacon(data);
- return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
+ return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
}
bool PingLoader::sendBeacon(LocalFrame* frame,
int allowance,
const KURL& beaconURL,
FormData* data,
- int& payloadLength) {
+ size_t& beaconSize) {
BeaconFormData beacon(data);
- return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
+ return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
}
bool PingLoader::sendBeacon(LocalFrame* frame,
int allowance,
const KURL& beaconURL,
Blob* data,
- int& payloadLength) {
+ size_t& beaconSize) {
BeaconBlob beacon(data);
- return sendBeaconCommon(frame, allowance, beaconURL, beacon, payloadLength);
+ return sendBeaconCommon(frame, allowance, beaconURL, beacon, beaconSize);
}
} // namespace blink
« 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