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() ...@@ -2270,13 +2270,6 @@ void Document::shutdown()
m_timers.setTimerTaskRunner( m_timers.setTimerTaskRunner(
Platform::current()->currentThread()->scheduler()->timerTaskRunner()->clone()); 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) if (m_mediaQueryMatcher)
m_mediaQueryMatcher->documentDetached(); m_mediaQueryMatcher->documentDetached();
...@@ -2289,6 +2282,13 @@ void Document::shutdown() ...@@ -2289,6 +2282,13 @@ void Document::shutdown()
// a contextDestroyed() notification. This can happen for a document // a contextDestroyed() notification. This can happen for a document
// created by DOMImplementation::createDocument(). // created by DOMImplementation::createDocument().
ExecutionContext::notifyContextDestroyed(); 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() void Document::removeAllEventListeners()
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace blink { namespace blink {
BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebBluetoothDeviceInit> webDevice) BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebBluetoothDeviceInit> webDevice)
: ActiveDOMObject(context) : ContextLifecycleObserver(context)
, m_webDevice(std::move(webDevice)) , m_webDevice(std::move(webDevice))
, m_gatt(BluetoothRemoteGATTServer::create(this)) , m_gatt(BluetoothRemoteGATTServer::create(this))
{ {
...@@ -29,9 +29,7 @@ BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebB ...@@ -29,9 +29,7 @@ BluetoothDevice::BluetoothDevice(ExecutionContext* context, std::unique_ptr<WebB
BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, std::unique_ptr<WebBluetoothDeviceInit> webDevice) BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, std::unique_ptr<WebBluetoothDeviceInit> webDevice)
{ {
ASSERT(webDevice); ASSERT(webDevice);
BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext(), std::move(webDevice)); return new BluetoothDevice(resolver->getExecutionContext(), std::move(webDevice));
device->suspendIfNeeded();
return device;
} }
void BluetoothDevice::dispose() void BluetoothDevice::dispose()
...@@ -39,7 +37,7 @@ void BluetoothDevice::dispose() ...@@ -39,7 +37,7 @@ void BluetoothDevice::dispose()
disconnectGATTIfConnected(); disconnectGATTIfConnected();
} }
void BluetoothDevice::stop() void BluetoothDevice::contextDestroyed()
{ {
disconnectGATTIfConnected(); disconnectGATTIfConnected();
} }
...@@ -62,7 +60,7 @@ const WTF::AtomicString& BluetoothDevice::interfaceName() const ...@@ -62,7 +60,7 @@ const WTF::AtomicString& BluetoothDevice::interfaceName() const
ExecutionContext* BluetoothDevice::getExecutionContext() const ExecutionContext* BluetoothDevice::getExecutionContext() const
{ {
return ActiveDOMObject::getExecutionContext(); return ContextLifecycleObserver::getExecutionContext();
} }
void BluetoothDevice::dispatchGattServerDisconnected() void BluetoothDevice::dispatchGattServerDisconnected()
...@@ -77,7 +75,7 @@ void BluetoothDevice::dispatchGattServerDisconnected() ...@@ -77,7 +75,7 @@ void BluetoothDevice::dispatchGattServerDisconnected()
DEFINE_TRACE(BluetoothDevice) DEFINE_TRACE(BluetoothDevice)
{ {
EventTargetWithInlineData::trace(visitor); EventTargetWithInlineData::trace(visitor);
ActiveDOMObject::trace(visitor); ContextLifecycleObserver::trace(visitor);
visitor->trace(m_gatt); visitor->trace(m_gatt);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define BluetoothDevice_h #define BluetoothDevice_h
#include "bindings/core/v8/ScriptWrappable.h" #include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h" #include "core/dom/ContextLifecycleObserver.h"
#include "modules/EventTargetModules.h" #include "modules/EventTargetModules.h"
#include "modules/bluetooth/BluetoothRemoteGATTServer.h" #include "modules/bluetooth/BluetoothRemoteGATTServer.h"
#include "platform/heap/Heap.h" #include "platform/heap/Heap.h"
...@@ -29,7 +29,7 @@ class ScriptPromiseResolver; ...@@ -29,7 +29,7 @@ class ScriptPromiseResolver;
// CallbackPromiseAdapter class comments. // CallbackPromiseAdapter class comments.
class BluetoothDevice final class BluetoothDevice final
: public EventTargetWithInlineData : public EventTargetWithInlineData
, public ActiveDOMObject , public ContextLifecycleObserver
, public WebBluetoothDevice { , public WebBluetoothDevice {
USING_PRE_FINALIZER(BluetoothDevice, dispose); USING_PRE_FINALIZER(BluetoothDevice, dispose);
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
...@@ -54,8 +54,8 @@ public: ...@@ -54,8 +54,8 @@ public:
// Called before the object gets garbage collected. // Called before the object gets garbage collected.
void dispose(); void dispose();
// ActiveDOMObject interface. // ContextLifecycleObserver interface.
void stop() override; void contextDestroyed() override;
// If gatt is connected then disconnects and sets gatt.connected to false. // If gatt is connected then disconnects and sets gatt.connected to false.
// Returns true if gatt was disconnected. // 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