diff options
author | c.shu@samsung.com <c.shu@samsung.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2014-05-31 01:04:55 +0000 |
---|---|---|
committer | c.shu@samsung.com <c.shu@samsung.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2014-05-31 01:04:55 +0000 |
commit | e3a8a21836de498adcbe2fdf8396aeaa4bf7a6e5 (patch) | |
tree | 24fd98393d58d4a88287eea8a5c11f72e0368950 | |
parent | ad8bde44a8be37abd131f5e786f54735d8737ae3 (diff) | |
download | chromium_src-e3a8a21836de498adcbe2fdf8396aeaa4bf7a6e5.zip chromium_src-e3a8a21836de498adcbe2fdf8396aeaa4bf7a6e5.tar.gz chromium_src-e3a8a21836de498adcbe2fdf8396aeaa4bf7a6e5.tar.bz2 |
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
-rw-r--r-- | third_party/WebKit/Source/bindings/v8/custom/V8DocumentCustom.cpp | 24 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/Init.cpp | 14 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/Init.h | 2 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/dom/Document.cpp | 22 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/dom/Document.h | 5 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/dom/Document.idl | 4 | ||||
-rw-r--r-- | third_party/WebKit/Source/core/events/EventFactory.h | 9 | ||||
-rw-r--r-- | third_party/WebKit/Source/modules/EventModulesFactory.h | 5 | ||||
-rw-r--r-- | third_party/WebKit/Source/modules/InitModules.cpp | 9 | ||||
-rw-r--r-- | third_party/WebKit/Source/modules/InitModules.h | 1 | ||||
-rw-r--r-- | third_party/WebKit/Source/web/WebDocument.cpp | 3 |
11 files changed, 55 insertions, 43 deletions
diff --git a/third_party/WebKit/Source/bindings/v8/custom/V8DocumentCustom.cpp b/third_party/WebKit/Source/bindings/v8/custom/V8DocumentCustom.cpp index 4248ff3..f884832 100644 --- a/third_party/WebKit/Source/bindings/v8/custom/V8DocumentCustom.cpp +++ b/third_party/WebKit/Source/bindings/v8/custom/V8DocumentCustom.cpp @@ -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 diff --git a/third_party/WebKit/Source/core/Init.cpp b/third_party/WebKit/Source/core/Init.cpp index 178dbde..bacf2b3 100644 --- a/third_party/WebKit/Source/core/Init.cpp +++ b/third_party/WebKit/Source/core/Init.cpp @@ -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(); diff --git a/third_party/WebKit/Source/core/Init.h b/third_party/WebKit/Source/core/Init.h index 96e3fbe..a20cc33 100644 --- a/third_party/WebKit/Source/core/Init.h +++ b/third_party/WebKit/Source/core/Init.h @@ -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(); diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp index aec29e2..ae3bf69 100644 --- a/third_party/WebKit/Source/core/dom/Document.cpp +++ b/third_party/WebKit/Source/core/dom/Document.cpp @@ -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; } diff --git a/third_party/WebKit/Source/core/dom/Document.h b/third_party/WebKit/Source/core/dom/Document.h index 84e22c0..050ff54 100644 --- a/third_party/WebKit/Source/core/dom/Document.h +++ b/third_party/WebKit/Source/core/dom/Document.h @@ -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; diff --git a/third_party/WebKit/Source/core/dom/Document.idl b/third_party/WebKit/Source/core/dom/Document.idl index 796ef26..30fbc26 100644 --- a/third_party/WebKit/Source/core/dom/Document.idl +++ b/third_party/WebKit/Source/core/dom/Document.idl @@ -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) diff --git a/third_party/WebKit/Source/core/events/EventFactory.h b/third_party/WebKit/Source/core/events/EventFactory.h index fae23e9..78f7be1 100644 --- a/third_party/WebKit/Source/core/events/EventFactory.h +++ b/third_party/WebKit/Source/core/events/EventFactory.h @@ -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; }; } diff --git a/third_party/WebKit/Source/modules/EventModulesFactory.h b/third_party/WebKit/Source/modules/EventModulesFactory.h index b826e9e..61e7b2a 100644 --- a/third_party/WebKit/Source/modules/EventModulesFactory.h +++ b/third_party/WebKit/Source/modules/EventModulesFactory.h @@ -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; }; } diff --git a/third_party/WebKit/Source/modules/InitModules.cpp b/third_party/WebKit/Source/modules/InitModules.cpp index d0e8b90..0752e92 100644 --- a/third_party/WebKit/Source/modules/InitModules.cpp +++ b/third_party/WebKit/Source/modules/InitModules.cpp @@ -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 diff --git a/third_party/WebKit/Source/modules/InitModules.h b/third_party/WebKit/Source/modules/InitModules.h index 83afcc1..eccc4a6 100644 --- a/third_party/WebKit/Source/modules/InitModules.h +++ b/third_party/WebKit/Source/modules/InitModules.h @@ -15,6 +15,7 @@ class ExceptionState; class ModulesInitializer : public CoreInitializer { public: + virtual void registerEventFactory() OVERRIDE; virtual void initEventNames() OVERRIDE; virtual void initEventTargetNames() OVERRIDE; }; diff --git a/third_party/WebKit/Source/web/WebDocument.cpp b/third_party/WebKit/Source/web/WebDocument.cpp index 5224978..af379a9 100644 --- a/third_party/WebKit/Source/web/WebDocument.cpp +++ b/third_party/WebKit/Source/web/WebDocument.cpp @@ -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; |