Chromium Code Reviews| Index: third_party/WebKit/Source/modules/beacon/NavigatorBeacon.cpp |
| diff --git a/third_party/WebKit/Source/modules/beacon/NavigatorBeacon.cpp b/third_party/WebKit/Source/modules/beacon/NavigatorBeacon.cpp |
| index 74dbda37b5d216e237ed8f79428bf9e04954986b..db0c5f40113b18d04ccfe980043b0ef5b050f98f 100644 |
| --- a/third_party/WebKit/Source/modules/beacon/NavigatorBeacon.cpp |
| +++ b/third_party/WebKit/Source/modules/beacon/NavigatorBeacon.cpp |
| @@ -21,12 +21,11 @@ |
| namespace blink { |
| NavigatorBeacon::NavigatorBeacon(Navigator& navigator) |
| - : ContextClient(navigator.frame()), m_transmittedBytes(0) {} |
| + : m_transmittedBytes(0) {} |
|
sof
2017/01/05 12:05:40
Don't you need to invoke the Supplement<Navigator>
|
| NavigatorBeacon::~NavigatorBeacon() {} |
| DEFINE_TRACE(NavigatorBeacon) { |
| - ContextClient::trace(visitor); |
| Supplement<Navigator>::trace(visitor); |
| } |
| @@ -70,15 +69,15 @@ bool NavigatorBeacon::canSendBeacon(ExecutionContext* context, |
| } |
| // If detached from frame, do not allow sending a Beacon. |
| - if (!frame() || !frame()->client()) |
|
haraken
2017/01/05 11:48:37
frame()->client() is not needed because host()->fr
sof
2017/01/05 12:05:40
It might be worth clarifying somewhere that |host(
|
| + if (!host()->frame()) |
| return false; |
| return true; |
| } |
| int NavigatorBeacon::maxAllowance() const { |
| - DCHECK(frame()); |
| - const Settings* settings = frame()->settings(); |
| + DCHECK(host()->frame()); |
| + const Settings* settings = host()->frame()->settings(); |
| if (settings) { |
| int maxAllowed = settings->maxBeaconTransmission(); |
| if (maxAllowed < m_transmittedBytes) |
| @@ -99,18 +98,25 @@ bool NavigatorBeacon::sendBeacon( |
| const String& urlstring, |
| const ArrayBufferViewOrBlobOrStringOrFormData& data, |
| ExceptionState& exceptionState) { |
| - NavigatorBeacon& impl = NavigatorBeacon::from(navigator); |
| + return NavigatorBeacon::from(navigator).sendBeaconImpl(context, urlstring, |
| + data, exceptionState); |
| +} |
| +bool NavigatorBeacon::sendBeaconImpl( |
| + ExecutionContext* context, |
| + const String& urlstring, |
| + const ArrayBufferViewOrBlobOrStringOrFormData& data, |
| + ExceptionState& exceptionState) { |
| KURL url = context->completeURL(urlstring); |
| - if (!impl.canSendBeacon(context, url, exceptionState)) |
| + if (!canSendBeacon(context, url, exceptionState)) |
| return false; |
| - int allowance = impl.maxAllowance(); |
| + int allowance = maxAllowance(); |
| int bytes = 0; |
| bool allowed; |
| if (data.isArrayBufferView()) { |
| - allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, |
| + allowed = PingLoader::sendBeacon(host()->frame(), allowance, url, |
| data.getAsArrayBufferView(), bytes); |
| } else if (data.isBlob()) { |
| Blob* blob = data.getAsBlob(); |
| @@ -126,20 +132,21 @@ bool NavigatorBeacon::sendBeacon( |
| return false; |
| } |
| } |
| - allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, blob, bytes); |
| + allowed = |
| + PingLoader::sendBeacon(host()->frame(), allowance, url, blob, bytes); |
| } else if (data.isString()) { |
| - allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, |
| + allowed = PingLoader::sendBeacon(host()->frame(), allowance, url, |
| data.getAsString(), bytes); |
| } else if (data.isFormData()) { |
| - allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, |
| + allowed = PingLoader::sendBeacon(host()->frame(), allowance, url, |
| data.getAsFormData(), bytes); |
| } else { |
| - allowed = |
| - PingLoader::sendBeacon(impl.frame(), allowance, url, String(), bytes); |
| + allowed = PingLoader::sendBeacon(host()->frame(), allowance, url, String(), |
| + bytes); |
| } |
| if (allowed) { |
| - impl.addTransmittedBytes(bytes); |
| + addTransmittedBytes(bytes); |
| return true; |
| } |