Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: Source/bindings/core/v8/V8AbstractEventListener.h

Issue 1236473002: Fix virtual/override/final usage in Source/bindings/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/ScriptWrappable.h ('k') | Source/bindings/core/v8/V8Binding.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // There are two kinds of event listeners: HTML or non-HMTL. onload, 46 // There are two kinds of event listeners: HTML or non-HMTL. onload,
47 // onfocus, etc (attributes) are always HTML event handler type; Event 47 // onfocus, etc (attributes) are always HTML event handler type; Event
48 // listeners added by Window.addEventListener or 48 // listeners added by Window.addEventListener or
49 // EventTargetNode::addEventListener are non-HTML type. 49 // EventTargetNode::addEventListener are non-HTML type.
50 // 50 //
51 // Why does this matter? 51 // Why does this matter?
52 // WebKit does not allow duplicated HTML event handlers of the same type, 52 // WebKit does not allow duplicated HTML event handlers of the same type,
53 // but ALLOWs duplicated non-HTML event handlers. 53 // but ALLOWs duplicated non-HTML event handlers.
54 class CORE_EXPORT V8AbstractEventListener : public EventListener { 54 class CORE_EXPORT V8AbstractEventListener : public EventListener {
55 public: 55 public:
56 virtual ~V8AbstractEventListener(); 56 ~V8AbstractEventListener() override;
57 57
58 static const V8AbstractEventListener* cast(const EventListener* listener) 58 static const V8AbstractEventListener* cast(const EventListener* listener)
59 { 59 {
60 return listener->type() == JSEventListenerType 60 return listener->type() == JSEventListenerType
61 ? static_cast<const V8AbstractEventListener*>(listener) 61 ? static_cast<const V8AbstractEventListener*>(listener)
62 : 0; 62 : 0;
63 } 63 }
64 64
65 static V8AbstractEventListener* cast(EventListener* listener) 65 static V8AbstractEventListener* cast(EventListener* listener)
66 { 66 {
67 return const_cast<V8AbstractEventListener*>(cast(const_cast<const EventL istener*>(listener))); 67 return const_cast<V8AbstractEventListener*>(cast(const_cast<const EventL istener*>(listener)));
68 } 68 }
69 69
70 // Implementation of EventListener interface. 70 // Implementation of EventListener interface.
71 71
72 virtual bool operator==(const EventListener& other) override { return this = = &other; } 72 bool operator==(const EventListener& other) override { return this == &other ; }
73 73
74 virtual void handleEvent(ExecutionContext*, Event*) override final; 74 void handleEvent(ExecutionContext*, Event*) final;
75 virtual void handleEvent(ScriptState*, Event*); 75 virtual void handleEvent(ScriptState*, Event*);
76 76
77 // Returns the listener object, either a function or an object. 77 // Returns the listener object, either a function or an object.
78 v8::Local<v8::Object> getListenerObject(ExecutionContext* executionContext) 78 v8::Local<v8::Object> getListenerObject(ExecutionContext* executionContext)
79 { 79 {
80 // prepareListenerObject can potentially deref this event listener 80 // prepareListenerObject can potentially deref this event listener
81 // as it may attempt to compile a function (lazy event listener), get an error 81 // as it may attempt to compile a function (lazy event listener), get an error
82 // and invoke onerror callback which can execute arbitrary JS code. 82 // and invoke onerror callback which can execute arbitrary JS code.
83 // Protect this event listener to keep it alive. 83 // Protect this event listener to keep it alive.
84 RefPtr<V8AbstractEventListener> guard(this); 84 RefPtr<V8AbstractEventListener> guard(this);
(...skipping 16 matching lines...) Expand all
101 bool hasExistingListenerObject() 101 bool hasExistingListenerObject()
102 { 102 {
103 return !m_listener.isEmpty(); 103 return !m_listener.isEmpty();
104 } 104 }
105 105
106 void clearListenerObject() 106 void clearListenerObject()
107 { 107 {
108 m_listener.clear(); 108 m_listener.clear();
109 } 109 }
110 110
111 virtual bool belongsToTheCurrentWorld() const override final; 111 bool belongsToTheCurrentWorld() const final;
112 v8::Isolate* isolate() const { return m_isolate; } 112 v8::Isolate* isolate() const { return m_isolate; }
113 DOMWrapperWorld& world() const { return *m_world; } 113 DOMWrapperWorld& world() const { return *m_world; }
114 114
115 protected: 115 protected:
116 V8AbstractEventListener(bool isAttribute, DOMWrapperWorld&, v8::Isolate*); 116 V8AbstractEventListener(bool isAttribute, DOMWrapperWorld&, v8::Isolate*);
117 117
118 virtual void prepareListenerObject(ExecutionContext*) { } 118 virtual void prepareListenerObject(ExecutionContext*) { }
119 119
120 void setListenerObject(v8::Local<v8::Object>); 120 void setListenerObject(v8::Local<v8::Object>);
121 121
122 void invokeEventHandler(ScriptState*, Event*, v8::Local<v8::Value>); 122 void invokeEventHandler(ScriptState*, Event*, v8::Local<v8::Value>);
123 123
124 // Get the receiver object to use for event listener call. 124 // Get the receiver object to use for event listener call.
125 v8::Local<v8::Object> getReceiverObject(ScriptState*, Event*); 125 v8::Local<v8::Object> getReceiverObject(ScriptState*, Event*);
126 126
127 private: 127 private:
128 // Implementation of EventListener function. 128 // Implementation of EventListener function.
129 virtual bool virtualisAttribute() const override { return m_isAttribute; } 129 bool virtualisAttribute() const override { return m_isAttribute; }
130 130
131 // This could return an empty handle and callers need to check return value. 131 // This could return an empty handle and callers need to check return value.
132 // We don't use v8::MaybeLocal because it can fail without exception. 132 // We don't use v8::MaybeLocal because it can fail without exception.
133 virtual v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8 ::Value> jsevent, Event*) = 0; 133 virtual v8::Local<v8::Value> callListenerFunction(ScriptState*, v8::Local<v8 ::Value> jsevent, Event*) = 0;
134 134
135 virtual bool shouldPreventDefault(v8::Local<v8::Value> returnValue); 135 virtual bool shouldPreventDefault(v8::Local<v8::Value> returnValue);
136 136
137 static void setWeakCallback(const v8::WeakCallbackInfo<V8AbstractEventListen er>&); 137 static void setWeakCallback(const v8::WeakCallbackInfo<V8AbstractEventListen er>&);
138 138
139 ScopedPersistent<v8::Object> m_listener; 139 ScopedPersistent<v8::Object> m_listener;
140 140
141 // Indicates if this is an HTML type listener. 141 // Indicates if this is an HTML type listener.
142 bool m_isAttribute; 142 bool m_isAttribute;
143 143
144 RefPtr<DOMWrapperWorld> m_world; 144 RefPtr<DOMWrapperWorld> m_world;
145 v8::Isolate* m_isolate; 145 v8::Isolate* m_isolate;
146 }; 146 };
147 147
148 } // namespace blink 148 } // namespace blink
149 149
150 #endif // V8AbstractEventListener_h 150 #endif // V8AbstractEventListener_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptWrappable.h ('k') | Source/bindings/core/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698