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

Unified Diff: Source/modules/beacon/NavigatorBeacon.cpp

Issue 714123002: Use union type for NavigatorBeacon.sendBeacon()'s data argument (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 1 month 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
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/beacon/NavigatorBeacon.cpp
diff --git a/Source/modules/beacon/NavigatorBeacon.cpp b/Source/modules/beacon/NavigatorBeacon.cpp
index aa2ff569a29fe73f07bdbcdb377144e9363a66c8..77cc13e8a774d557f73c48ecf2684305ff9d81cb 100644
--- a/Source/modules/beacon/NavigatorBeacon.cpp
+++ b/Source/modules/beacon/NavigatorBeacon.cpp
@@ -6,6 +6,7 @@
#include "modules/beacon/NavigatorBeacon.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/modules/v8/UnionTypesModules.h"
#include "core/dom/DOMArrayBufferView.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
@@ -88,68 +89,30 @@ bool NavigatorBeacon::beaconResult(ExecutionContext* context, bool allowed, int
return allowed;
}
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, const String& data, ExceptionState& exceptionState)
+bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, const ArrayBufferViewOrBlobOrStringOrFormData& data, ExceptionState& exceptionState)
{
- return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstring, const String& data, ExceptionState& exceptionState)
-{
- KURL url = context->completeURL(urlstring);
- if (!canSendBeacon(context, url, exceptionState))
- return false;
-
- int bytes = 0;
- bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- return beaconResult(context, result, bytes);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState)
-{
- return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstring, PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState)
-{
- KURL url = context->completeURL(urlstring);
- if (!canSendBeacon(context, url, exceptionState))
- return false;
-
- int bytes = 0;
- bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data->view(), bytes);
- return beaconResult(context, result, bytes);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, Blob* data, ExceptionState& exceptionState)
-{
- return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstring, Blob* data, ExceptionState& exceptionState)
-{
- KURL url = context->completeURL(urlstring);
- if (!canSendBeacon(context, url, exceptionState))
- return false;
-
- int bytes = 0;
- bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- return beaconResult(context, result, bytes);
-}
+ NavigatorBeacon& impl = NavigatorBeacon::from(navigator);
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState)
-{
- return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
-}
-
-bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState)
-{
KURL url = context->completeURL(urlstring);
- if (!canSendBeacon(context, url, exceptionState))
+ if (!impl.canSendBeacon(context, url, exceptionState))
return false;
+ int allowance = impl.maxAllowance();
int bytes = 0;
- bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- return beaconResult(context, result, bytes);
+ bool allowed;
+
+ if (data.isArrayBufferView())
+ allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, data.getAsArrayBufferView()->view(), bytes);
+ else if (data.isBlob())
+ allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, data.getAsBlob(), bytes);
+ else if (data.isString())
+ allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, data.getAsString(), bytes);
+ else if (data.isFormData())
+ allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, data.getAsFormData(), bytes);
+ else
+ allowed = BeaconLoader::sendBeacon(navigator.frame(), allowance, url, String(), bytes);
+
+ return impl.beaconResult(context, allowed, bytes);
}
} // namespace blink
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698