Commit e3a8a218 authored by c.shu@samsung.com's avatar c.shu@samsung.com

Use method registration approach for creating events on core and modules.

BUG=376506

Review URL: https://codereview.chromium.org/305723002

git-svn-id: svn://svn.chromium.org/blink/trunk@175179 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ad8bde44
......@@ -33,7 +33,6 @@
#include "bindings/core/v8/V8CanvasRenderingContext2D.h"
#include "bindings/core/v8/V8DOMImplementation.h"
#include "bindings/core/v8/V8Event.h"
#include "bindings/core/v8/V8Node.h"
#include "bindings/core/v8/V8Touch.h"
#include "bindings/core/v8/V8TouchList.h"
......@@ -55,7 +54,6 @@
#include "core/xml/DocumentXPathEvaluator.h"
#include "core/xml/XPathNSResolver.h"
#include "core/xml/XPathResult.h"
#include "modules/InitModules.h"
#include "wtf/RefPtr.h"
namespace WebCore {
......@@ -85,26 +83,4 @@ void V8Document::evaluateMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
v8SetReturnValueFast(info, result.release(), document.get());
}
// Customize createEvent so it can call createEventModules in modules.
// FIXME: Use method registration approach instead. http://crbug.com/358074
void V8Document::createEventMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "createEvent", "Document", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
throwMinimumArityTypeError(exceptionState, 1, info.Length());
return;
}
Document* impl = V8Document::toNative(info.Holder());
V8StringResource<> eventType;
{
TOSTRING_VOID_INTERNAL(eventType, info[0]);
}
RefPtrWillBeRawPtr<Event> result = createEventModules(eventType, exceptionState);
if (exceptionState.hadException()) {
exceptionState.throwIfNeeded();
return;
}
v8SetReturnValueFast(info, WTF::getPtr(result.release()), impl);
}
} // namespace WebCore
......@@ -46,6 +46,8 @@
#include "XLinkNames.h"
#include "XMLNSNames.h"
#include "XMLNames.h"
#include "core/dom/Document.h"
#include "core/events/EventFactory.h"
#include "core/html/parser/HTMLParserThread.h"
#include "platform/EventTracer.h"
#include "platform/Partitions.h"
......@@ -65,6 +67,16 @@ void CoreInitializer::initEventTargetNames()
EventTargetNames::init();
}
void CoreInitializer::registerEventFactory()
{
static bool isRegistered = false;
if (isRegistered)
return;
isRegistered = true;
Document::registerEventFactory(new EventFactory());
}
void CoreInitializer::init()
{
if (m_isInited)
......@@ -96,6 +108,8 @@ void CoreInitializer::init()
Partitions::init();
EventTracer::initialize();
registerEventFactory();
// Ensure that the main thread's thread-local data is initialized before
// starting any worker threads.
PlatformThreadData::current();
......
......@@ -38,6 +38,8 @@ public:
CoreInitializer() : m_isInited(false) { }
// Should be called by clients before trying to create Frames.
void init();
virtual void registerEventFactory();
virtual void initEventNames();
virtual void initEventTargetNames();
......
......@@ -3922,12 +3922,26 @@ void Document::enqueueResizeEvent()
ensureScriptedAnimationController().enqueuePerFrameEvent(event.release());
}
PassRefPtrWillBeRawPtr<Event> Document::createEvent(const String& eventType, ExceptionState& exceptionState)
Document::EventFactorySet& Document::eventFactories()
{
DEFINE_STATIC_LOCAL(EventFactorySet, s_eventFactory, ());
return s_eventFactory;
}
void Document::registerEventFactory(EventFactoryBase* eventFactory)
{
RefPtrWillBeRawPtr<Event> event = EventFactory::create(eventType);
if (event)
return event.release();
ASSERT(!eventFactories().contains(eventFactory));
eventFactories().add(eventFactory);
}
PassRefPtrWillBeRawPtr<Event> Document::createEvent(const String& eventType, ExceptionState& exceptionState)
{
RefPtrWillBeRawPtr<Event> event = nullptr;
for (EventFactorySet::const_iterator it = eventFactories().begin(); it != eventFactories().end(); ++it) {
event = (*it)->create(eventType);
if (event)
return event.release();
}
exceptionState.throwDOMException(NotSupportedError, "The provided event type ('" + eventType + "') is invalid.");
return nullptr;
}
......
......@@ -95,6 +95,7 @@ class DocumentType;
class Element;
class ElementDataCache;
class Event;
class EventFactoryBase;
class EventListener;
class ExceptionState;
class FastTextAutosizer;
......@@ -694,6 +695,7 @@ public:
void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
EventListener* getWindowAttributeEventListener(const AtomicString& eventType);
static void registerEventFactory(EventFactoryBase*);
static PassRefPtrWillBeRawPtr<Event> createEvent(const String& eventType, ExceptionState&);
// keep track of what types of event listeners are registered, so we don't
......@@ -1182,6 +1184,9 @@ private:
bool haveStylesheetsLoaded() const;
typedef HashSet<EventFactoryBase*> EventFactorySet;
static EventFactorySet& eventFactories();
DocumentLifecycle m_lifecycle;
bool m_hasNodesWithPlaceholderStyle;
......
......@@ -63,9 +63,7 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext;
// DOM Level 2 Events (DocumentEvents interface)
// Customize createEvent so it can call createEventModules in modules.
// FIXME: Use method registration approach instead. http://crbug.com/358074
[Custom, RaisesException] Event createEvent(DOMString eventType);
[RaisesException] Event createEvent(DOMString eventType);
// DOM Level 2 Traversal and Range (DocumentRange interface)
......
......@@ -34,9 +34,14 @@ namespace WebCore {
class Event;
class EventFactory {
class EventFactoryBase {
public:
static PassRefPtrWillBeRawPtr<Event> create(const String& eventType);
virtual PassRefPtrWillBeRawPtr<Event> create(const String& eventType) = 0;
};
class EventFactory : public EventFactoryBase {
public:
virtual PassRefPtrWillBeRawPtr<Event> create(const String& eventType) OVERRIDE;
};
}
......
......@@ -5,6 +5,7 @@
#ifndef EventModulesFactory_h
#define EventModulesFactory_h
#include "core/events/EventFactory.h"
#include "platform/heap/Handle.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/AtomicString.h"
......@@ -13,9 +14,9 @@ namespace WebCore {
class Event;
class EventModulesFactory {
class EventModulesFactory : public EventFactoryBase {
public:
static PassRefPtrWillBeRawPtr<Event> create(const String& eventType);
virtual PassRefPtrWillBeRawPtr<Event> create(const String& eventType) OVERRIDE;
};
}
......
......@@ -25,13 +25,10 @@ void ModulesInitializer::initEventTargetNames()
EventTargetNames::initModules();
}
PassRefPtrWillBeRawPtr<Event> createEventModules(const String& eventType, ExceptionState& exceptionState)
void ModulesInitializer::registerEventFactory()
{
RefPtrWillBeRawPtr<Event> event = EventModulesFactory::create(eventType);
if (event)
return event.release();
return Document::createEvent(eventType, exceptionState);
CoreInitializer::registerEventFactory();
Document::registerEventFactory(new EventModulesFactory());
}
} // namespace WebCore
......@@ -15,6 +15,7 @@ class ExceptionState;
class ModulesInitializer : public CoreInitializer {
public:
virtual void registerEventFactory() OVERRIDE;
virtual void initEventNames() OVERRIDE;
virtual void initEventTargetNames() OVERRIDE;
};
......
......@@ -54,7 +54,6 @@
#include "core/loader/DocumentLoader.h"
#include "core/rendering/RenderObject.h"
#include "core/rendering/RenderView.h"
#include "modules/InitModules.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/WebURL.h"
#include "public/web/WebAXObject.h"
......@@ -242,7 +241,7 @@ WebElement WebDocument::fullScreenElement() const
WebDOMEvent WebDocument::createEvent(const WebString& eventType)
{
TrackExceptionState exceptionState;
WebDOMEvent event(createEventModules(eventType, exceptionState));
WebDOMEvent event(unwrap<Document>()->createEvent(eventType, exceptionState));
if (exceptionState.hadException())
return WebDOMEvent();
return event;
......
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