Commit 04226262 authored by Yuki Yamada's avatar Yuki Yamada Committed by Commit Bot

Use EventListener instead of the classes which inherits it

I am planning to replace V8AbstractEventListener and its subclasses by
new classes I will implement for redesigning EventListener/EventHandler
in https://crbug.com/872138, so it is better to remove unnecessary
dependencies on the classes which inherits blink::EventListener before
addressing that.
Basically, we should not use blink::V8AbstractEventListener or other
classes which inherits EventListener unless we have to use the methods
implemented only in child class, but there are some cases that uses
child classes without any need. Therefore this CL replaced child
classes by blink::EventListener if possible.

Bug: 872138
Change-Id: Idc82f93fdc850f532092cc021f6aa458803dcd7b
Reviewed-on: https://chromium-review.googlesource.com/1170714
Commit-Queue: Yuki Yamada <yukiy@google.com>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582861}
parent 4ffe0107
......@@ -33,12 +33,11 @@
#include "third_party/blink/renderer/bindings/core/v8/scheduled_action.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_abstract_event_listener.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_lazy_event_listener.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_parser.h"
#include "third_party/blink/renderer/core/dom/events/event_listener.h"
#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
......@@ -46,7 +45,7 @@
namespace blink {
V8LazyEventListener* CreateAttributeEventListener(
EventListener* CreateAttributeEventListener(
Node* node,
const QualifiedName& name,
const AtomicString& value,
......@@ -74,7 +73,7 @@ V8LazyEventListener* CreateAttributeEventListener(
isolate);
}
V8LazyEventListener* CreateAttributeEventListener(
EventListener* CreateAttributeEventListener(
LocalFrame* frame,
const QualifiedName& name,
const AtomicString& value,
......
......@@ -33,23 +33,20 @@
#include <memory>
#include "third_party/blink/renderer/bindings/core/v8/v8_lazy_event_listener.h"
#include "third_party/blink/renderer/core/dom/events/event_listener.h"
namespace blink {
class EventListener;
class ExecutionContext;
class LocalFrame;
class Node;
class QualifiedName;
class SourceLocation;
V8LazyEventListener* CreateAttributeEventListener(
EventListener* CreateAttributeEventListener(
Node*,
const QualifiedName&,
const AtomicString& value,
const AtomicString& event_parameter_name);
V8LazyEventListener* CreateAttributeEventListener(
EventListener* CreateAttributeEventListener(
LocalFrame*,
const QualifiedName&,
const AtomicString& value,
......
......@@ -80,8 +80,8 @@ v8::Local<v8::Value> V8AbstractEventListener::GetListenerOrNull(
EventListener* listener) {
if (listener && listener->GetType() == kJSEventListenerType) {
v8::Local<v8::Object> v8_listener =
static_cast<V8AbstractEventListener*>(listener)->GetListenerObject(
event_target->GetExecutionContext());
static_cast<V8AbstractEventListener*>(listener)
->GetListenerObjectInternal(event_target->GetExecutionContext());
if (!v8_listener.IsEmpty())
return v8_listener;
}
......
......@@ -82,6 +82,11 @@ class CORE_EXPORT V8AbstractEventListener : public EventListener {
// Returns the listener object, either a function or an object, or the empty
// handle if the user script is not compilable. No exception will be thrown
// even if the user script is not compilable.
v8::Local<v8::Object> GetListenerObjectForInspector(
ExecutionContext* execution_context) final {
return GetListenerObjectInternal(execution_context);
}
v8::Local<v8::Object> GetListenerObject(ExecutionContext* execution_context) {
return GetListenerObjectInternal(execution_context);
}
......@@ -105,7 +110,7 @@ class CORE_EXPORT V8AbstractEventListener : public EventListener {
bool IsAttribute() const final { return is_attribute_; }
v8::Isolate* GetIsolate() const { return isolate_; }
DOMWrapperWorld& World() const { return *world_; }
DOMWrapperWorld* GetWorldForInspector() const final { return world_.get(); }
void Trace(blink::Visitor*) override;
......@@ -125,6 +130,7 @@ class CORE_EXPORT V8AbstractEventListener : public EventListener {
// Get the receiver object to use for event listener call.
v8::Local<v8::Object> GetReceiverObject(ScriptState*, Event*);
DOMWrapperWorld& World() const { return *world_; }
private:
// This could return an empty handle and callers need to check return value.
......
......@@ -58,7 +58,7 @@ v8::Local<v8::Value> V8ErrorHandler::CallListenerFunction(
v8::Local<v8::Context> context = script_state->GetContext();
ExecutionContext* execution_context = ToExecutionContext(context);
v8::Local<v8::Object> listener = GetListenerObject(execution_context);
v8::Local<v8::Object> listener = GetListenerObjectInternal(execution_context);
if (listener.IsEmpty() || !listener->IsFunction())
return v8::Null(GetIsolate());
......
......@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/bindings/core/v8/custom_wrappable_adapter.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_error_handler.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_event_listener_or_event_handler.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_window.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
......@@ -58,7 +59,7 @@ ListenerType* GetEventListenerInternal(
} // namespace
// static
V8AbstractEventListener* V8EventListenerHelper::GetEventListener(
EventListener* V8EventListenerHelper::GetEventListener(
ScriptState* script_state,
v8::Local<v8::Value> value,
bool is_attribute,
......@@ -86,7 +87,7 @@ V8AbstractEventListener* V8EventListenerHelper::GetEventListener(
}
// static
V8ErrorHandler* V8EventListenerHelper::EnsureErrorHandler(
EventListener* V8EventListenerHelper::EnsureErrorHandler(
ScriptState* script_state,
v8::Local<v8::Value> value) {
if (!value->IsObject())
......
......@@ -32,15 +32,12 @@
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_EVENT_LISTENER_HELPER_H_
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_event_listener_or_event_handler.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "v8/include/v8.h"
namespace blink {
class V8ErrorHandler;
enum ListenerLookupType {
kListenerFindOnly,
kListenerFindOrCreate,
......@@ -52,14 +49,13 @@ class V8EventListenerHelper {
STATIC_ONLY(V8EventListenerHelper);
public:
CORE_EXPORT static V8AbstractEventListener* GetEventListener(
ScriptState*,
v8::Local<v8::Value>,
bool is_attribute,
ListenerLookupType);
CORE_EXPORT static EventListener* GetEventListener(ScriptState*,
v8::Local<v8::Value>,
bool is_attribute,
ListenerLookupType);
CORE_EXPORT static V8ErrorHandler* EnsureErrorHandler(ScriptState*,
v8::Local<v8::Value>);
CORE_EXPORT static EventListener* EnsureErrorHandler(ScriptState*,
v8::Local<v8::Value>);
};
} // namespace blink
......
......@@ -49,7 +49,7 @@ V8EventListenerOrEventHandler::V8EventListenerOrEventHandler(
v8::Local<v8::Function> V8EventListenerOrEventHandler::GetListenerFunction(
ScriptState* script_state) {
v8::Local<v8::Object> listener =
GetListenerObject(ExecutionContext::From(script_state));
GetListenerObjectInternal(ExecutionContext::From(script_state));
// Has the listener been disposed?
if (listener.IsEmpty())
......
......@@ -90,7 +90,8 @@ v8::Local<v8::Value> V8LazyEventListener::CallListenerFunction(
DCHECK(!js_event.IsEmpty());
ExecutionContext* execution_context =
ToExecutionContext(script_state->GetContext());
v8::Local<v8::Object> listener_object = GetListenerObject(execution_context);
v8::Local<v8::Object> listener_object =
GetListenerObjectInternal(execution_context);
if (listener_object.IsEmpty())
return v8::Local<v8::Value>();
......
......@@ -29,6 +29,7 @@
namespace blink {
class DOMWrapperWorld;
class Event;
class ExecutionContext;
......@@ -51,6 +52,16 @@ class CORE_EXPORT EventListener : public CustomWrappableAdapter {
}
virtual bool IsAttribute() const { return false; }
// Only DevTools is allowed to use this method.
// This method may return an empty handle.
virtual v8::Local<v8::Object> GetListenerObjectForInspector(
ExecutionContext* execution_context) {
return v8::Local<v8::Object>();
}
// Only DevTools is allowed to use this method.
virtual DOMWrapperWorld* GetWorldForInspector() const { return nullptr; }
ListenerType GetType() const { return type_; }
const char* NameInHeapSnapshot() const override { return "EventListener"; }
......
......@@ -39,6 +39,7 @@
#include "third_party/blink/renderer/bindings/core/v8/event_listener_options_or_boolean.h"
#include "third_party/blink/renderer/bindings/core/v8/script_event_listener.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_abstract_event_listener.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/event_dispatch_forbidden_scope.h"
#include "third_party/blink/renderer/core/dom/events/event_target_impl.h"
......@@ -839,9 +840,8 @@ bool EventTarget::FireEventListeners(Event& event,
bool passive_forced = registered_listener.PassiveForcedForDocumentTarget();
probe::UserCallback probe(context, nullptr, event.type(), false, this);
probe::AsyncTask async_task(
context, V8AbstractEventListener::Cast(listener), "event",
IsInstrumentedForAsyncStack(event.type()));
probe::AsyncTask async_task(context, listener, "event",
IsInstrumentedForAsyncStack(event.type()));
// To match Mozilla, the AT_TARGET phase fires both capturing and bubbling
// event listeners, even though that violates some versions of the DOM spec.
......
......@@ -110,10 +110,11 @@ void InspectorDOMDebuggerAgent::CollectEventListeners(
EventListener* event_listener = listeners->at(k).Callback();
if (event_listener->GetType() != EventListener::kJSEventListenerType)
continue;
V8AbstractEventListener* v8_listener =
static_cast<V8AbstractEventListener*>(event_listener);
v8::Local<v8::Context> context =
ToV8Context(execution_context, v8_listener->World());
// TODO(yukiy): Use a child class of blink::EventListener that is for v8
// event listeners here if it is implemented in redesigning
// EventListener/EventHandler: https://crbug.com/872138 .
v8::Local<v8::Context> context = ToV8Context(
execution_context, *(event_listener->GetWorldForInspector()));
// Optionally hide listeners from other contexts.
if (!report_for_all_contexts && context != isolate->GetCurrentContext())
continue;
......@@ -121,7 +122,7 @@ void InspectorDOMDebuggerAgent::CollectEventListeners(
// compiled, potentially unsuccessfully. In that case, the function
// returns the empty handle without an exception.
v8::Local<v8::Object> handler =
v8_listener->GetListenerObject(execution_context);
event_listener->GetListenerObjectForInspector(execution_context);
if (handler.IsEmpty())
continue;
bool use_capture = listeners->at(k).Capture();
......
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