Commit 10633dff authored by avayvod's avatar avayvod Committed by Commit bot

[Android, RemotePlayback] Make RemotePlayback classes ActiveScriptWrappable's

Keeps the V8 wrappers alive as long as there're event listeners or pending
promises and such.

BUG=616761
TEST=manual, see repro steps in the bug

Review-Url: https://codereview.chromium.org/2038573002
Cr-Commit-Position: refs/heads/master@{#398014}
parent 94477194
......@@ -47,7 +47,7 @@ RemotePlayback* RemotePlayback::create(HTMLMediaElement& element)
}
RemotePlayback::RemotePlayback(HTMLMediaElement& element)
: DOMWindowProperty(element.document().frame())
: ActiveScriptWrappable(this)
, m_state(element.isPlayingRemotely() ? WebRemotePlaybackState::Connected : WebRemotePlaybackState::Disconnected)
, m_availability(element.hasRemoteRoutes())
, m_mediaElement(&element)
......@@ -61,9 +61,7 @@ const AtomicString& RemotePlayback::interfaceName() const
ExecutionContext* RemotePlayback::getExecutionContext() const
{
if (!m_frame)
return 0;
return m_frame->document();
return &m_mediaElement->document();
}
ScriptPromise RemotePlayback::getAvailability(ScriptState* scriptState)
......@@ -110,6 +108,13 @@ String RemotePlayback::state() const
return remotePlaybackStateToString(m_state);
}
bool RemotePlayback::hasPendingActivity() const
{
return hasEventListeners()
|| !m_availabilityObjects.isEmpty()
|| !m_connectPromiseResolvers.isEmpty();
}
void RemotePlayback::stateChanged(WebRemotePlaybackState state)
{
// We may get a "disconnected" state change while in the "disconnected"
......@@ -153,10 +158,9 @@ void RemotePlayback::connectCancelled()
DEFINE_TRACE(RemotePlayback)
{
visitor->trace(m_availabilityObjects);
visitor->trace(m_mediaElement);
visitor->trace(m_connectPromiseResolvers);
visitor->trace(m_mediaElement);
EventTargetWithInlineData::trace(visitor);
DOMWindowProperty::trace(visitor);
}
} // namespace blink
......@@ -5,9 +5,9 @@
#ifndef RemotePlayback_h
#define RemotePlayback_h
#include "bindings/core/v8/ActiveScriptWrappable.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "core/events/EventTarget.h"
#include "core/frame/DOMWindowProperty.h"
#include "platform/heap/Handle.h"
#include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
#include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
......@@ -24,7 +24,7 @@ class ScriptPromiseResolver;
class RemotePlayback final
: public EventTargetWithInlineData
, public DOMWindowProperty
, public ActiveScriptWrappable
, private WebRemotePlaybackClient {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(RemotePlayback);
......@@ -40,6 +40,9 @@ public:
String state() const;
// ActiveScriptWrappable implementation.
bool hasPendingActivity() const final;
DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
DECLARE_VIRTUAL_TRACE();
......
......@@ -10,6 +10,8 @@ enum RemotePlaybackState {
};
[
ActiveScriptWrappable,
DependentLifetime,
RuntimeEnabled=RemotePlayback
] interface RemotePlayback : EventTarget {
readonly attribute RemotePlaybackState state;
......
......@@ -18,7 +18,8 @@ RemotePlaybackAvailability* RemotePlaybackAvailability::take(ScriptPromiseResolv
}
RemotePlaybackAvailability::RemotePlaybackAvailability(ExecutionContext* executionContext, bool value)
: ContextLifecycleObserver(executionContext)
: ActiveScriptWrappable(this)
, ContextLifecycleObserver(executionContext)
, m_value(value)
{
ASSERT(executionContext->isDocument());
......@@ -50,6 +51,11 @@ bool RemotePlaybackAvailability::value() const
return m_value;
}
bool RemotePlaybackAvailability::hasPendingActivity() const
{
return hasEventListeners();
}
DEFINE_TRACE(RemotePlaybackAvailability)
{
EventTargetWithInlineData::trace(visitor);
......
......@@ -5,6 +5,7 @@
#ifndef RemotePlaybackAvailability_h
#define RemotePlaybackAvailability_h
#include "bindings/core/v8/ActiveScriptWrappable.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/events/EventTarget.h"
......@@ -16,7 +17,10 @@ class ScriptPromiseResolver;
// Expose whether there is a remote playback device available for a media
// element. The object will be initialized with a default value passed via
// ::take() and will then listen to availability changes.
class RemotePlaybackAvailability final : public EventTargetWithInlineData, public ContextLifecycleObserver {
class RemotePlaybackAvailability final
: public EventTargetWithInlineData
, public ActiveScriptWrappable
, public ContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(RemotePlaybackAvailability);
public:
......@@ -31,6 +35,9 @@ public:
bool value() const;
// ActiveScriptWrappable implementation.
bool hasPendingActivity() const final;
DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
DECLARE_VIRTUAL_TRACE();
......
......@@ -5,6 +5,8 @@
// https://w3c.github.io/remote-playback/#idl-def-remoteplaybackavailability
[
ActiveScriptWrappable,
DependentLifetime,
RuntimeEnabled=RemotePlayback,
] interface RemotePlaybackAvailability : EventTarget {
readonly attribute boolean value;
......
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