Commit cdf61249 authored by haraken's avatar haraken Committed by Commit bot

Remove ContextClient from NavigatorBeacon

Now that Navigator's Supplements can retrieve the Navigator object with host(),
those Supplements don't need to observe ContextClient.

BUG=610176

Review-Url: https://codereview.chromium.org/2611133002
Cr-Commit-Position: refs/heads/master@{#442873}
parent 23c0a165
...@@ -22,12 +22,11 @@ ...@@ -22,12 +22,11 @@
namespace blink { namespace blink {
NavigatorBeacon::NavigatorBeacon(Navigator& navigator) NavigatorBeacon::NavigatorBeacon(Navigator& navigator)
: ContextClient(navigator.frame()), m_transmittedBytes(0) {} : Supplement<Navigator>(navigator), m_transmittedBytes(0) {}
NavigatorBeacon::~NavigatorBeacon() {} NavigatorBeacon::~NavigatorBeacon() {}
DEFINE_TRACE(NavigatorBeacon) { DEFINE_TRACE(NavigatorBeacon) {
ContextClient::trace(visitor);
Supplement<Navigator>::trace(visitor); Supplement<Navigator>::trace(visitor);
} }
...@@ -71,15 +70,15 @@ bool NavigatorBeacon::canSendBeacon(ExecutionContext* context, ...@@ -71,15 +70,15 @@ bool NavigatorBeacon::canSendBeacon(ExecutionContext* context,
} }
// If detached from frame, do not allow sending a Beacon. // If detached from frame, do not allow sending a Beacon.
if (!frame() || !frame()->client()) if (!host()->frame())
return false; return false;
return true; return true;
} }
int NavigatorBeacon::maxAllowance() const { int NavigatorBeacon::maxAllowance() const {
DCHECK(frame()); DCHECK(host()->frame());
const Settings* settings = frame()->settings(); const Settings* settings = host()->frame()->settings();
if (settings) { if (settings) {
int maxAllowed = settings->getMaxBeaconTransmission(); int maxAllowed = settings->getMaxBeaconTransmission();
if (maxAllowed < m_transmittedBytes) if (maxAllowed < m_transmittedBytes)
...@@ -100,19 +99,26 @@ bool NavigatorBeacon::sendBeacon( ...@@ -100,19 +99,26 @@ bool NavigatorBeacon::sendBeacon(
const String& urlstring, const String& urlstring,
const ArrayBufferViewOrBlobOrStringOrFormData& data, const ArrayBufferViewOrBlobOrStringOrFormData& data,
ExceptionState& exceptionState) { ExceptionState& exceptionState) {
NavigatorBeacon& impl = NavigatorBeacon::from(navigator); return NavigatorBeacon::from(navigator).sendBeaconImpl(scriptState, urlstring,
data, exceptionState);
}
bool NavigatorBeacon::sendBeaconImpl(
ScriptState* scriptState,
const String& urlstring,
const ArrayBufferViewOrBlobOrStringOrFormData& data,
ExceptionState& exceptionState) {
ExecutionContext* context = scriptState->getExecutionContext(); ExecutionContext* context = scriptState->getExecutionContext();
KURL url = context->completeURL(urlstring); KURL url = context->completeURL(urlstring);
if (!impl.canSendBeacon(context, url, exceptionState)) if (!canSendBeacon(context, url, exceptionState))
return false; return false;
int allowance = impl.maxAllowance(); int allowance = maxAllowance();
int bytes = 0; int bytes = 0;
bool allowed; bool allowed;
if (data.isArrayBufferView()) { if (data.isArrayBufferView()) {
allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, allowed = PingLoader::sendBeacon(host()->frame(), allowance, url,
data.getAsArrayBufferView(), bytes); data.getAsArrayBufferView(), bytes);
} else if (data.isBlob()) { } else if (data.isBlob()) {
Blob* blob = data.getAsBlob(); Blob* blob = data.getAsBlob();
...@@ -128,20 +134,21 @@ bool NavigatorBeacon::sendBeacon( ...@@ -128,20 +134,21 @@ bool NavigatorBeacon::sendBeacon(
return false; return false;
} }
} }
allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, blob, bytes); allowed =
PingLoader::sendBeacon(host()->frame(), allowance, url, blob, bytes);
} else if (data.isString()) { } else if (data.isString()) {
allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, allowed = PingLoader::sendBeacon(host()->frame(), allowance, url,
data.getAsString(), bytes); data.getAsString(), bytes);
} else if (data.isFormData()) { } else if (data.isFormData()) {
allowed = PingLoader::sendBeacon(impl.frame(), allowance, url, allowed = PingLoader::sendBeacon(host()->frame(), allowance, url,
data.getAsFormData(), bytes); data.getAsFormData(), bytes);
} else { } else {
allowed = allowed = PingLoader::sendBeacon(host()->frame(), allowance, url, String(),
PingLoader::sendBeacon(impl.frame(), allowance, url, String(), bytes); bytes);
} }
if (allowed) { if (allowed) {
impl.addTransmittedBytes(bytes); addTransmittedBytes(bytes);
return true; return true;
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef NavigatorBeacon_h #ifndef NavigatorBeacon_h
#define NavigatorBeacon_h #define NavigatorBeacon_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h" #include "core/frame/Navigator.h"
#include "platform/Supplementable.h" #include "platform/Supplementable.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
...@@ -18,7 +17,6 @@ class KURL; ...@@ -18,7 +17,6 @@ class KURL;
class ArrayBufferViewOrBlobOrStringOrFormData; class ArrayBufferViewOrBlobOrStringOrFormData;
class NavigatorBeacon final : public GarbageCollectedFinalized<NavigatorBeacon>, class NavigatorBeacon final : public GarbageCollectedFinalized<NavigatorBeacon>,
public ContextClient,
public Supplement<Navigator> { public Supplement<Navigator> {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorBeacon); USING_GARBAGE_COLLECTED_MIXIN(NavigatorBeacon);
...@@ -39,6 +37,10 @@ class NavigatorBeacon final : public GarbageCollectedFinalized<NavigatorBeacon>, ...@@ -39,6 +37,10 @@ class NavigatorBeacon final : public GarbageCollectedFinalized<NavigatorBeacon>,
static const char* supplementName(); static const char* supplementName();
bool sendBeaconImpl(ScriptState*,
const String&,
const ArrayBufferViewOrBlobOrStringOrFormData&,
ExceptionState&);
bool canSendBeacon(ExecutionContext*, const KURL&, ExceptionState&); bool canSendBeacon(ExecutionContext*, const KURL&, ExceptionState&);
int maxAllowance() const; int maxAllowance() const;
void addTransmittedBytes(int sentBytes); void addTransmittedBytes(int sentBytes);
......
...@@ -98,7 +98,12 @@ class Supplement : public GarbageCollectedMixin { ...@@ -98,7 +98,12 @@ class Supplement : public GarbageCollectedMixin {
// TODO(haraken): Remove the default constructor. // TODO(haraken): Remove the default constructor.
// All Supplement objects should be instantiated with m_host. // All Supplement objects should be instantiated with m_host.
Supplement() {} Supplement() {}
explicit Supplement(T& host) : m_host(&host) {} explicit Supplement(T& host) : m_host(&host) {}
// Supplementable and its supplements live and die together.
// Thus host() should never return null (if the default constructor
// is completely removed).
T* host() const { return m_host; } T* host() const { return m_host; }
static void provideTo(Supplementable<T>& host, static void provideTo(Supplementable<T>& host,
......
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