Commit 9491d94f authored by jl@opera.com's avatar jl@opera.com

Use union type for NavigatorBeacon.sendBeacon()'s data argument

This lets us lose some overloading and code duplication.

BUG=430337

Review URL: https://codereview.chromium.org/714123002

git-svn-id: svn://svn.chromium.org/blink/trunk@185293 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4dad62eb
...@@ -105,7 +105,7 @@ bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac ...@@ -105,7 +105,7 @@ bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beac
return true; return true;
} }
bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beaconURL, PassRefPtrWillBeRawPtr<DOMFormData>& data, int& payloadLength) bool BeaconLoader::sendBeacon(LocalFrame* frame, int allowance, const KURL& beaconURL, PassRefPtrWillBeRawPtr<DOMFormData> data, int& payloadLength)
{ {
ASSERT(data); ASSERT(data);
ResourceRequest request(beaconURL); ResourceRequest request(beaconURL);
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
static bool sendBeacon(LocalFrame*, int, const KURL&, const String&, int&); static bool sendBeacon(LocalFrame*, int, const KURL&, const String&, int&);
static bool sendBeacon(LocalFrame*, int, const KURL&, PassRefPtr<WTF::ArrayBufferView>, int&); static bool sendBeacon(LocalFrame*, int, const KURL&, PassRefPtr<WTF::ArrayBufferView>, int&);
static bool sendBeacon(LocalFrame*, int, const KURL&, Blob*, int&); static bool sendBeacon(LocalFrame*, int, const KURL&, Blob*, int&);
static bool sendBeacon(LocalFrame*, int, const KURL&, PassRefPtrWillBeRawPtr<DOMFormData>&, int&); static bool sendBeacon(LocalFrame*, int, const KURL&, PassRefPtrWillBeRawPtr<DOMFormData>, int&);
private: private:
static void prepareRequest(LocalFrame*, ResourceRequest&); static void prepareRequest(LocalFrame*, ResourceRequest&);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "modules/beacon/NavigatorBeacon.h" #include "modules/beacon/NavigatorBeacon.h"
#include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/ExceptionState.h"
#include "bindings/modules/v8/UnionTypesModules.h"
#include "core/dom/DOMArrayBufferView.h" #include "core/dom/DOMArrayBufferView.h"
#include "core/dom/ExceptionCode.h" #include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h" #include "core/dom/ExecutionContext.h"
...@@ -88,68 +89,30 @@ bool NavigatorBeacon::beaconResult(ExecutionContext* context, bool allowed, int ...@@ -88,68 +89,30 @@ bool NavigatorBeacon::beaconResult(ExecutionContext* context, bool allowed, int
return allowed; 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); NavigatorBeacon& impl = NavigatorBeacon::from(navigator);
}
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);
}
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); KURL url = context->completeURL(urlstring);
if (!canSendBeacon(context, url, exceptionState)) if (!impl.canSendBeacon(context, url, exceptionState))
return false; return false;
int allowance = impl.maxAllowance();
int bytes = 0; int bytes = 0;
bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); bool allowed;
return beaconResult(context, result, bytes);
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 } // namespace blink
...@@ -17,27 +17,20 @@ class DOMFormData; ...@@ -17,27 +17,20 @@ class DOMFormData;
class ExceptionState; class ExceptionState;
class ExecutionContext; class ExecutionContext;
class KURL; class KURL;
class ArrayBufferViewOrBlobOrStringOrFormData;
class NavigatorBeacon final : public NoBaseWillBeGarbageCollected<NavigatorBeacon>, public WillBeHeapSupplement<Navigator> { class NavigatorBeacon final : public NoBaseWillBeGarbageCollected<NavigatorBeacon>, public WillBeHeapSupplement<Navigator> {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NavigatorBeacon); WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NavigatorBeacon);
public: public:
static NavigatorBeacon& from(Navigator&); static NavigatorBeacon& from(Navigator&);
static bool sendBeacon(ExecutionContext*, Navigator&, const String&, const String&, ExceptionState&); static bool sendBeacon(ExecutionContext*, Navigator&, const String&, const ArrayBufferViewOrBlobOrStringOrFormData&, ExceptionState&);
static bool sendBeacon(ExecutionContext*, Navigator&, const String&, PassRefPtr<DOMArrayBufferView>, ExceptionState&);
static bool sendBeacon(ExecutionContext*, Navigator&, const String&, Blob*, ExceptionState&);
static bool sendBeacon(ExecutionContext*, Navigator&, const String&, PassRefPtrWillBeRawPtr<DOMFormData>, ExceptionState&);
private: private:
explicit NavigatorBeacon(Navigator&); explicit NavigatorBeacon(Navigator&);
static const char* supplementName(); static const char* supplementName();
bool sendBeacon(ExecutionContext*, const String&, const String&, ExceptionState&);
bool sendBeacon(ExecutionContext*, const String&, PassRefPtr<DOMArrayBufferView>, ExceptionState&);
bool sendBeacon(ExecutionContext*, const String&, Blob*, ExceptionState&);
bool sendBeacon(ExecutionContext*, const String&, PassRefPtrWillBeRawPtr<DOMFormData>, ExceptionState&);
bool canSendBeacon(ExecutionContext*, const KURL&, ExceptionState&); bool canSendBeacon(ExecutionContext*, const KURL&, ExceptionState&);
int maxAllowance() const; int maxAllowance() const;
bool beaconResult(ExecutionContext*, bool allowed, int sentBytes); bool beaconResult(ExecutionContext*, bool allowed, int sentBytes);
......
...@@ -7,9 +7,5 @@ ...@@ -7,9 +7,5 @@
[ [
RuntimeEnabled=Beacon, RuntimeEnabled=Beacon,
] partial interface Navigator { ] partial interface Navigator {
// FIXME: should be union type http://crbug.com/240176 [CallWith=ExecutionContext, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(DOMString url, optional (ArrayBufferView or Blob or DOMString or FormData)? data = null);
[CallWith=ExecutionContext, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(DOMString url, ArrayBufferView data);
[CallWith=ExecutionContext, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(DOMString url, Blob data);
[CallWith=ExecutionContext, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(DOMString url, FormData data);
[CallWith=ExecutionContext, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(DOMString url, [Default=Undefined] optional DOMString data);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment