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