Commit 105b06a6 authored by Yuki Yamada's avatar Yuki Yamada Committed by Commit Bot

Remove old EventListener and EventHandler

This is a clean-up for previous CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1215512

After submitted the previous CL, these old classes are not used from
anywhere:
    blink::V8AbstractEventHandler
    blink::V8EventListenerOrEventHandler
    blink::V8ErrorHandler
    blink::V8LazyEventListener
Therefore, this CL removes them.

Bug: 872138
Change-Id: I44e9026148e6db24f44b52c138523cce55eacd7d
Reviewed-on: https://chromium-review.googlesource.com/c/1273355Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Yamada <yukiy@google.com>
Cr-Commit-Position: refs/heads/master@{#598707}
parent 0494a9cc
...@@ -106,8 +106,6 @@ bindings_core_v8_files = ...@@ -106,8 +106,6 @@ bindings_core_v8_files =
"core/v8/use_counter_callback.h", "core/v8/use_counter_callback.h",
"core/v8/v0_custom_element_constructor_builder.cc", "core/v8/v0_custom_element_constructor_builder.cc",
"core/v8/v0_custom_element_constructor_builder.h", "core/v8/v0_custom_element_constructor_builder.h",
"core/v8/v8_abstract_event_handler.cc",
"core/v8/v8_abstract_event_handler.h",
"core/v8/v8_binding_for_core.cc", "core/v8/v8_binding_for_core.cc",
"core/v8/v8_binding_for_core.h", "core/v8/v8_binding_for_core.h",
"core/v8/v8_cache_options.h", "core/v8/v8_cache_options.h",
...@@ -117,10 +115,6 @@ bindings_core_v8_files = ...@@ -117,10 +115,6 @@ bindings_core_v8_files =
"core/v8/v8_dom_configuration.h", "core/v8/v8_dom_configuration.h",
"core/v8/v8_embedder_graph_builder.cc", "core/v8/v8_embedder_graph_builder.cc",
"core/v8/v8_embedder_graph_builder.h", "core/v8/v8_embedder_graph_builder.h",
"core/v8/v8_error_handler.cc",
"core/v8/v8_error_handler.h",
"core/v8/v8_event_listener_or_event_handler.cc",
"core/v8/v8_event_listener_or_event_handler.h",
"core/v8/v8_event_listener_helper.cc", "core/v8/v8_event_listener_helper.cc",
"core/v8/v8_event_listener_helper.h", "core/v8/v8_event_listener_helper.h",
"core/v8/v8_event_listener_info.h", "core/v8/v8_event_listener_info.h",
...@@ -139,8 +133,6 @@ bindings_core_v8_files = ...@@ -139,8 +133,6 @@ bindings_core_v8_files =
"core/v8/v8_throw_dom_exception.h", "core/v8/v8_throw_dom_exception.h",
"core/v8/v8_iterator_result_value.cc", "core/v8/v8_iterator_result_value.cc",
"core/v8/v8_iterator_result_value.h", "core/v8/v8_iterator_result_value.h",
"core/v8/v8_lazy_event_listener.cc",
"core/v8/v8_lazy_event_listener.h",
"core/v8/v8_object_builder.cc", "core/v8/v8_object_builder.cc",
"core/v8/v8_object_builder.h", "core/v8/v8_object_builder.h",
"core/v8/v8_object_parser.cc", "core/v8/v8_object_parser.cc",
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_custom_element_constructor.h" #include "third_party/blink/renderer/bindings/core/v8/v8_custom_element_constructor.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_custom_element_registry.h" #include "third_party/blink/renderer/bindings/core/v8/v8_custom_element_registry.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_element.h" #include "third_party/blink/renderer/bindings/core/v8/v8_element.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_error_handler.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_function.h" #include "third_party/blink/renderer/bindings/core/v8/v8_function.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h" #include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h" #include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
......
/*
* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ABSTRACT_EVENT_HANDLER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ABSTRACT_EVENT_HANDLER_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/event_listener.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/heap/self_keep_alive.h"
#include "v8/include/v8.h"
namespace blink {
class Event;
class EventTarget;
// There are two kinds of event listeners: HTML or non-HMTL. onload,
// onfocus, etc (attributes) are always HTML event handler type; Event
// listeners added by Window.addEventListener or
// EventTargetNode::addEventListener are non-HTML type.
//
// Why does this matter?
// WebKit does not allow duplicated HTML event handlers of the same type,
// but ALLOWs duplicated non-HTML event handlers.
class CORE_EXPORT V8AbstractEventHandler : public EventListener {
public:
~V8AbstractEventHandler() override;
static const V8AbstractEventHandler* Cast(const EventListener* listener) {
return listener->GetType() == kJSEventHandlerType
? static_cast<const V8AbstractEventHandler*>(listener)
: nullptr;
}
static V8AbstractEventHandler* Cast(EventListener* listener) {
return const_cast<V8AbstractEventHandler*>(
Cast(const_cast<const EventListener*>(listener)));
}
static v8::Local<v8::Value> GetListenerOrNull(v8::Isolate*,
EventTarget*,
EventListener*);
// Implementation of EventListener interface.
bool operator==(const EventListener& other) const override {
return this == &other;
}
void handleEvent(ExecutionContext*, Event*) final;
virtual void HandleEvent(ScriptState*, Event*);
// 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);
}
v8::Local<v8::Object> GetExistingListenerObject() {
return listener_.NewLocal(isolate_);
}
// Provides access to the underlying handle for GC. Returned
// value is a weak handle and so not guaranteed to stay alive.
v8::Persistent<v8::Object>& ExistingListenerObjectPersistentHandle() {
return listener_.Get();
}
bool HasExistingListenerObject() { return !listener_.IsEmpty(); }
void ClearListenerObject();
bool BelongsToTheCurrentWorld(ExecutionContext*) const final;
bool IsEventHandler() const final { return is_attribute_; }
v8::Isolate* GetIsolate() const { return isolate_; }
DOMWrapperWorld* GetWorldPtrForInspector() const final {
return world_.get();
}
void Trace(blink::Visitor*) override;
protected:
V8AbstractEventHandler(v8::Isolate*, bool is_attribute, DOMWrapperWorld&);
virtual v8::Local<v8::Object> GetListenerObjectInternal(
ExecutionContext* execution_context) {
return GetExistingListenerObject();
}
void SetListenerObject(ScriptState*,
v8::Local<v8::Object>,
const V8PrivateProperty::Symbol&);
void InvokeEventHandler(ScriptState*, Event*, v8::Local<v8::Value>);
// 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.
// We don't use v8::MaybeLocal because it can fail without exception.
virtual v8::Local<v8::Value>
CallListenerFunction(ScriptState*, v8::Local<v8::Value> jsevent, Event*) = 0;
virtual bool ShouldPreventDefault(v8::Local<v8::Value> return_value, Event*);
static void WrapperCleared(
const v8::WeakCallbackInfo<V8AbstractEventHandler>&);
TraceWrapperV8Reference<v8::Object> listener_;
// true if the listener is created through a DOM attribute.
bool is_attribute_;
scoped_refptr<DOMWrapperWorld> world_;
v8::Isolate* isolate_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ABSTRACT_EVENT_HANDLER_H_
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/bindings/core/v8/v8_error_handler.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_error_event.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
namespace blink {
V8ErrorHandler::V8ErrorHandler(bool is_inline, ScriptState* script_state)
: V8EventListenerOrEventHandler(is_inline, script_state) {}
v8::Local<v8::Value> V8ErrorHandler::CallListenerFunction(
ScriptState* script_state,
v8::Local<v8::Value> js_event,
Event* event) {
DCHECK(!js_event.IsEmpty());
if (!event->HasInterface(EventNames::ErrorEvent)) {
return V8EventListenerOrEventHandler::CallListenerFunction(script_state,
js_event, event);
}
ErrorEvent* error_event = static_cast<ErrorEvent*>(event);
v8::Local<v8::Context> context = script_state->GetContext();
ExecutionContext* execution_context = ToExecutionContext(context);
v8::Local<v8::Object> listener = GetListenerObjectInternal(execution_context);
if (listener.IsEmpty() || !listener->IsFunction())
return v8::Null(GetIsolate());
v8::Local<v8::Function> call_function =
v8::Local<v8::Function>::Cast(listener);
v8::Local<v8::Object> this_value = context->Global();
// The error attribute should be initialized to null for dedicated workers.
// https://html.spec.whatwg.org/multipage/workers.html#runtime-script-errors-2
ScriptValue error = error_event->error(script_state);
v8::Local<v8::Value> error_value =
(error.IsEmpty() ||
error_event->target()->InterfaceName() == EventTargetNames::Worker)
? v8::Local<v8::Value>(v8::Null(GetIsolate()))
: error.V8Value();
v8::Local<v8::Value> parameters[5] = {
V8String(GetIsolate(), error_event->message()),
V8String(GetIsolate(), error_event->filename()),
v8::Integer::New(GetIsolate(), error_event->lineno()),
v8::Integer::New(GetIsolate(), error_event->colno()), error_value};
v8::TryCatch try_catch(GetIsolate());
try_catch.SetVerbose(true);
v8::MaybeLocal<v8::Value> result = V8ScriptRunner::CallFunction(
call_function, execution_context, this_value, base::size(parameters),
parameters, GetIsolate());
v8::Local<v8::Value> return_value;
if (!result.ToLocal(&return_value))
return v8::Null(GetIsolate());
return return_value;
}
bool V8ErrorHandler::ShouldPreventDefault(v8::Local<v8::Value> return_value,
Event* event) {
// Special event handling should be done here according to HTML Standard:
// https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm
// We do not need to check current target of event because it must be window
// or worker on calling this method.
if (event->HasInterface(EventNames::ErrorEvent) && event->type() == "error")
return return_value->IsBoolean() && return_value.As<v8::Boolean>()->Value();
return return_value->IsBoolean() && !return_value.As<v8::Boolean>()->Value();
}
} // namespace blink
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ERROR_HANDLER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ERROR_HANDLER_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_event_listener_or_event_handler.h"
#include "v8/include/v8.h"
namespace blink {
class V8ErrorHandler final : public V8EventListenerOrEventHandler {
public:
static V8ErrorHandler* Create(v8::Local<v8::Object> listener,
bool is_inline,
ScriptState* script_state,
const V8PrivateProperty::Symbol& property) {
V8ErrorHandler* event_listener =
new V8ErrorHandler(is_inline, script_state);
event_listener->SetListenerObject(script_state, listener, property);
return event_listener;
}
private:
V8ErrorHandler(bool is_inline, ScriptState*);
v8::Local<v8::Value> CallListenerFunction(ScriptState*,
v8::Local<v8::Value>,
Event*) override;
bool ShouldPreventDefault(v8::Local<v8::Value> return_value, Event*) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_ERROR_HANDLER_H_
/*
* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/bindings/core/v8/v8_event_listener_or_event_handler.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
namespace blink {
V8EventListenerOrEventHandler::V8EventListenerOrEventHandler(
bool is_attribute,
ScriptState* script_state)
: V8AbstractEventHandler(script_state->GetIsolate(),
is_attribute,
script_state->World()) {}
v8::Local<v8::Function> V8EventListenerOrEventHandler::GetListenerFunction(
ScriptState* script_state) {
v8::Local<v8::Object> listener =
GetListenerObjectInternal(ExecutionContext::From(script_state));
// Has the listener been disposed?
if (listener.IsEmpty())
return v8::Local<v8::Function>();
if (listener->IsFunction())
return v8::Local<v8::Function>::Cast(listener);
// The EventHandler callback function type (used for event handler
// attributes in HTML) has [TreatNonObjectAsNull], which implies that
// non-function objects should be treated as no-op functions that return
// undefined.
if (IsEventHandler())
return v8::Local<v8::Function>();
// Getting the handleEvent property can runs script in the getter.
if (ScriptForbiddenScope::IsScriptForbidden()) {
V8ThrowException::ThrowError(GetIsolate(),
"Script execution is forbidden.");
return v8::Local<v8::Function>();
}
if (listener->IsObject()) {
// Check that no exceptions were thrown when getting the
// handleEvent property and that the value is a function.
v8::Local<v8::Value> property;
if (listener
->Get(script_state->GetContext(),
V8AtomicString(GetIsolate(), "handleEvent"))
.ToLocal(&property) &&
property->IsFunction())
return v8::Local<v8::Function>::Cast(property);
}
return v8::Local<v8::Function>();
}
v8::Local<v8::Value> V8EventListenerOrEventHandler::CallListenerFunction(
ScriptState* script_state,
v8::Local<v8::Value> js_event,
Event* event) {
DCHECK(!js_event.IsEmpty());
v8::Local<v8::Function> handler_function = GetListenerFunction(script_state);
v8::Local<v8::Object> receiver = GetReceiverObject(script_state, event);
if (handler_function.IsEmpty() || receiver.IsEmpty())
return v8::Local<v8::Value>();
ExecutionContext* execution_context =
ToExecutionContext(script_state->GetContext());
// TODO(jochen): Consider moving this check into canExecuteScripts.
// http://crbug.com/608641
if (script_state->World().IsMainWorld() &&
!execution_context->CanExecuteScripts(kAboutToExecuteScript))
return v8::Local<v8::Value>();
v8::Local<v8::Value> parameters[1] = {js_event};
v8::Local<v8::Value> result;
if (!V8ScriptRunner::CallFunction(handler_function, execution_context,
receiver, base::size(parameters),
parameters, script_state->GetIsolate())
.ToLocal(&result))
return v8::Local<v8::Value>();
return result;
}
} // namespace blink
/*
* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_EVENT_LISTENER_OR_EVENT_HANDLER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_EVENT_LISTENER_OR_EVENT_HANDLER_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_abstract_event_handler.h"
#include "v8/include/v8.h"
namespace blink {
class Event;
// V8EventListenerOrEventHandler is a wrapper of a JS object implements
// EventListener interface (has handleEvent(event) method), or a JS function
// that can handle the event.
class V8EventListenerOrEventHandler : public V8AbstractEventHandler {
public:
static V8EventListenerOrEventHandler* Create(
v8::Local<v8::Object> listener,
bool is_attribute,
ScriptState* script_state,
const V8PrivateProperty::Symbol& property) {
V8EventListenerOrEventHandler* event_listener =
new V8EventListenerOrEventHandler(is_attribute, script_state);
event_listener->SetListenerObject(script_state, listener, property);
return event_listener;
}
protected:
V8EventListenerOrEventHandler(bool is_attribute, ScriptState*);
v8::Local<v8::Function> GetListenerFunction(ScriptState*);
v8::Local<v8::Value> CallListenerFunction(ScriptState*,
v8::Local<v8::Value>,
Event*) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_EVENT_LISTENER_OR_EVENT_HANDLER_H_
/*
* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_LAZY_EVENT_LISTENER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_LAZY_EVENT_LISTENER_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_abstract_event_handler.h"
#include "third_party/blink/renderer/platform/wtf/text/text_position.h"
#include "v8/include/v8.h"
namespace blink {
class Event;
class Node;
// V8LazyEventListener is a wrapper for a JavaScript code string that is
// compiled and evaluated when an event is fired. A V8LazyEventListener is
// either a HTML or SVG event handler.
class V8LazyEventListener final : public V8AbstractEventHandler {
public:
static V8LazyEventListener* Create(const AtomicString& function_name,
const String& code,
const String& source_url,
const TextPosition& position,
Node* node,
v8::Isolate* isolate,
DOMWrapperWorld& world) {
return new V8LazyEventListener(isolate, world, function_name, code,
source_url, position, node);
}
void Trace(blink::Visitor* visitor) override {
visitor->Trace(node_);
V8AbstractEventHandler::Trace(visitor);
}
const String& Code() const override { return code_; }
protected:
v8::Local<v8::Object> GetListenerObjectInternal(ExecutionContext*) override;
private:
V8LazyEventListener(v8::Isolate*,
DOMWrapperWorld&,
const AtomicString& function_name,
const String& code,
const String source_url,
const TextPosition&,
Node*);
v8::Local<v8::Value> CallListenerFunction(ScriptState*,
v8::Local<v8::Value>,
Event*) override;
// Return true, so that event handlers from markup are not cloned twice when
// building the shadow tree for SVGUseElements.
bool IsEventHandlerForContentAttribute() const override { return true; }
void CompileScript(ScriptState*, ExecutionContext*);
void FireErrorEvent(v8::Local<v8::Context>,
ExecutionContext*,
v8::Local<v8::Message>);
bool was_compilation_failed_;
AtomicString function_name_;
String code_;
String source_url_;
Member<Node> node_;
TextPosition position_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_LAZY_EVENT_LISTENER_H_
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
namespace blink { namespace blink {
class DOMWrapperWorld;
class Event; class Event;
class ExecutionContext; class ExecutionContext;
...@@ -58,16 +57,6 @@ class CORE_EXPORT EventListener : public CustomWrappableAdapter { ...@@ -58,16 +57,6 @@ class CORE_EXPORT EventListener : public CustomWrappableAdapter {
} }
virtual bool IsEventHandler() const { return false; } virtual bool IsEventHandler() 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* GetWorldPtrForInspector() const { return nullptr; }
ListenerType GetType() const { return type_; } ListenerType GetType() const { return type_; }
// Returns true if this EventListener is implemented based on JS object. // Returns true if this EventListener is implemented based on JS object.
......
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