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

Clear Document::m_frame after dispatching ContextLifecycleObesrver::contextDestroyed

Bluetooth needs to use document->frame() in ContextLifecycleObesrver::contextDestroyed().
Hence this CL moves m_frame=nullptr to after dispatching contextDestroyed().

See https://groups.google.com/a/chromium.org/d/topic/blink-dev/sfpRQc4LB_I/discussion for more motivation of this CL.

BUG=610176

Review-Url: https://codereview.chromium.org/2362173002
Cr-Commit-Position: refs/heads/master@{#420588}
parent 337fe8de
......@@ -2270,13 +2270,6 @@ void Document::shutdown()
m_timers.setTimerTaskRunner(
Platform::current()->currentThread()->scheduler()->timerTaskRunner()->clone());
// This is required, as our LocalFrame might delete itself as soon as it detaches
// us. However, this violates Node::detachLayoutTree() semantics, as it's never
// possible to re-attach. Eventually Document::detachLayoutTree() should be renamed,
// or this setting of the frame to 0 could be made explicit in each of the
// callers of Document::detachLayoutTree().
m_frame = nullptr;
if (m_mediaQueryMatcher)
m_mediaQueryMatcher->documentDetached();
......@@ -2289,6 +2282,13 @@ void Document::shutdown()
// a contextDestroyed() notification. This can happen for a document
// created by DOMImplementation::createDocument().
ExecutionContext::notifyContextDestroyed();
// This is required, as our LocalFrame might delete itself as soon as it detaches
// us. However, this violates Node::detachLayoutTree() semantics, as it's never
// possible to re-attach. Eventually Document::detachLayoutTree() should be renamed,
// or this setting of the frame to 0 could be made explicit in each of the
// callers of Document::detachLayoutTree().
m_frame = nullptr;
}
void Document::removeAllEventListeners()
......
......@@ -18,7 +18,7 @@
namespace blink {
BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebBluetoothDeviceInit> webDevice)
: ActiveDOMObject(context)
: ContextLifecycleObserver(context)
, m_webDevice(std::move(webDevice))
, m_gatt(BluetoothRemoteGATTServer::create(this))
{
......@@ -29,9 +29,7 @@ BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebB
BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, std::unique_ptr<WebBluetoothDeviceInit> webDevice)
{
ASSERT(webDevice);
BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext(), std::move(webDevice));
device->suspendIfNeeded();
return device;
return new BluetoothDevice(resolver->getExecutionContext(), std::move(webDevice));
}
void BluetoothDevice::dispose()
......@@ -39,7 +37,7 @@ void BluetoothDevice::dispose()
disconnectGATTIfConnected();
}
void BluetoothDevice::stop()
void BluetoothDevice::contextDestroyed()
{
disconnectGATTIfConnected();
}
......@@ -62,7 +60,7 @@ const WTF::AtomicString& BluetoothDevice::interfaceName() const
ExecutionContext* BluetoothDevice::getExecutionContext() const
{
return ActiveDOMObject::getExecutionContext();
return ContextLifecycleObserver::getExecutionContext();
}
void BluetoothDevice::dispatchGattServerDisconnected()
......@@ -77,7 +75,7 @@ void BluetoothDevice::dispatchGattServerDisconnected()
DEFINE_TRACE(BluetoothDevice)
{
EventTargetWithInlineData::trace(visitor);
ActiveDOMObject::trace(visitor);
ContextLifecycleObserver::trace(visitor);
visitor->trace(m_gatt);
}
......
......@@ -6,7 +6,7 @@
#define BluetoothDevice_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "modules/EventTargetModules.h"
#include "modules/bluetooth/BluetoothRemoteGATTServer.h"
#include "platform/heap/Heap.h"
......@@ -29,7 +29,7 @@ class ScriptPromiseResolver;
// CallbackPromiseAdapter class comments.
class BluetoothDevice final
: public EventTargetWithInlineData
, public ActiveDOMObject
, public ContextLifecycleObserver
, public WebBluetoothDevice {
USING_PRE_FINALIZER(BluetoothDevice, dispose);
DEFINE_WRAPPERTYPEINFO();
......@@ -54,8 +54,8 @@ public:
// Called before the object gets garbage collected.
void dispose();
// ActiveDOMObject interface.
void stop() override;
// ContextLifecycleObserver interface.
void contextDestroyed() override;
// If gatt is connected then disconnects and sets gatt.connected to false.
// Returns true if gatt was disconnected.
......
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