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

Side by Side Diff: bindings/v8/custom/V8NodeCustom.cpp

Issue 160590: A patch for http://crbug.com/17400... (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/WebCore/
Patch Set: Created 11 years, 4 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
« no previous file with comments | « bindings/v8/custom/V8ElementCustom.cpp ('k') | bindings/v8/custom/V8XMLHttpRequestCustom.cpp » ('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) 2007-2009 Google Inc. All rights reserved. 2 * Copyright (C) 2007-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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "Node.h" 32 #include "Node.h"
33 33
34 #include "Document.h" 34 #include "Document.h"
35 #include "EventListener.h" 35 #include "EventListener.h"
36 36
37 #include "V8AbstractEventListener.h"
37 #include "V8Binding.h" 38 #include "V8Binding.h"
38 #include "V8CustomBinding.h" 39 #include "V8CustomBinding.h"
39 #include "V8CustomEventListener.h" 40 #include "V8CustomEventListener.h"
41 #include "V8ObjectEventListener.h"
40 #include "V8Node.h" 42 #include "V8Node.h"
41 #include "V8Proxy.h" 43 #include "V8Proxy.h"
42 44
43 #include <wtf/RefPtr.h> 45 #include <wtf/RefPtr.h>
44 46
45 namespace WebCore { 47 namespace WebCore {
46 48
49 static inline String toEventType(v8::Local<v8::String> value)
50 {
51 String key = toWebCoreString(value);
52 ASSERT(key.startsWith("on"));
53 return key.substring(2);
54 }
55
56 static PassRefPtr<EventListener> getEventListener(Node* node, v8::Local<v8::Valu e> value, bool isAttribute, bool findOnly)
57 {
58 V8Proxy* proxy = V8Proxy::retrieve(node->scriptExecutionContext());
59 // the document might be created using createDocument,
60 // which does not have a frame, use the active frame
61 if (!proxy)
62 proxy = V8Proxy::retrieve(V8Proxy::retrieveFrameForEnteredContext());
63
64 if (proxy) {
65 V8EventListenerList* list = proxy->objectListeners();
66 return findOnly ? list->findWrapper(value, isAttribute) : list->findOrCr eateWrapper<V8ObjectEventListener>(proxy->frame(), value, isAttribute);
67 }
68
69 return PassRefPtr<EventListener>();
70 }
71
72 ACCESSOR_SETTER(NodeEventHandler)
73 {
74 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder());
75
76 String eventType = toEventType(name);
77
78 // Set handler if the value is a function. Otherwise, clear the
79 // event handler.
80 if (value->IsFunction()) {
81 RefPtr<EventListener> listener = getEventListener(node, value, true, fal se);
82 if (listener) {
83 node->setAttributeEventListener(eventType, listener);
84 createHiddenDependency(info.Holder(), value, V8Custom::kNodeEventLis tenerCacheIndex);
85 }
86 } else {
87 if (EventListener* listener = node->getAttributeEventListener(eventType) ) {
88 if (!static_cast<V8AbstractEventListener*>(listener)->isLazy()) {
89 v8::Local<v8::Object> v8Listener = static_cast<V8ObjectEventList ener*>(listener)->getListenerObject();
90 removeHiddenDependency(info.Holder(), v8Listener, V8Custom::kNod eEventListenerCacheIndex);
91 }
92 }
93 node->clearAttributeEventListener(eventType);
94 }
95 }
96
97 ACCESSOR_GETTER(NodeEventHandler)
98 {
99 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder());
100
101 EventListener* listener = node->getAttributeEventListener(toEventType(name)) ;
102 return V8DOMWrapper::convertEventListenerToV8Object(listener);
103 }
104
47 CALLBACK_FUNC_DECL(NodeAddEventListener) 105 CALLBACK_FUNC_DECL(NodeAddEventListener)
48 { 106 {
49 INC_STATS("DOM.Node.addEventListener()"); 107 INC_STATS("DOM.Node.addEventListener()");
50 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); 108 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder());
51 109
52 V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame()); 110 RefPtr<EventListener> listener = getEventListener(node, args[1], false, fals e);
53 if (!proxy)
54 return v8::Undefined();
55
56 RefPtr<EventListener> listener = proxy->eventListeners()->findOrCreateWrappe r<V8EventListener>(proxy->frame(), args[1], false);
57 if (listener) { 111 if (listener) {
58 String type = toWebCoreString(args[0]); 112 String type = toWebCoreString(args[0]);
59 bool useCapture = args[2]->BooleanValue(); 113 bool useCapture = args[2]->BooleanValue();
60 node->addEventListener(type, listener, useCapture); 114 node->addEventListener(type, listener, useCapture);
115 createHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListe nerCacheIndex);
61 } 116 }
62 return v8::Undefined(); 117 return v8::Undefined();
63 } 118 }
64 119
65 CALLBACK_FUNC_DECL(NodeRemoveEventListener) 120 CALLBACK_FUNC_DECL(NodeRemoveEventListener)
66 { 121 {
67 INC_STATS("DOM.Node.removeEventListener()"); 122 INC_STATS("DOM.Node.removeEventListener()");
68 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); 123 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder());
69 124
70 V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame());
71 // It is possbile that the owner document of the node is detached 125 // It is possbile that the owner document of the node is detached
72 // from the frame, return immediately in this case. 126 // from the frame.
73 // See issue http://b/878909 127 // See issue http://b/878909
74 if (!proxy) 128 RefPtr<EventListener> listener = getEventListener(node, args[1], false, true );
75 return v8::Undefined();
76
77 RefPtr<EventListener> listener = proxy->eventListeners()->findWrapper(args[1 ], false);
78 if (listener) { 129 if (listener) {
79 String type = toWebCoreString(args[0]); 130 String type = toWebCoreString(args[0]);
80 bool useCapture = args[2]->BooleanValue(); 131 bool useCapture = args[2]->BooleanValue();
81 node->removeEventListener(type, listener.get(), useCapture); 132 node->removeEventListener(type, listener.get(), useCapture);
133 removeHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListe nerCacheIndex);
82 } 134 }
83 135
84 return v8::Undefined(); 136 return v8::Undefined();
85 } 137 }
86 138
87 // This function is customized to take advantage of the optional 4th argument: s houldLazyAttach 139 // This function is customized to take advantage of the optional 4th argument: s houldLazyAttach
88 CALLBACK_FUNC_DECL(NodeInsertBefore) 140 CALLBACK_FUNC_DECL(NodeInsertBefore)
89 { 141 {
90 INC_STATS("DOM.Node.insertBefore"); 142 INC_STATS("DOM.Node.insertBefore");
91 v8::Handle<v8::Object> holder = args.Holder(); 143 v8::Handle<v8::Object> holder = args.Holder();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (ec) { 203 if (ec) {
152 V8Proxy::setDOMException(ec); 204 V8Proxy::setDOMException(ec);
153 return v8::Handle<v8::Value>(); 205 return v8::Handle<v8::Value>();
154 } 206 }
155 if (success) 207 if (success)
156 return args[0]; 208 return args[0];
157 return v8::Null(); 209 return v8::Null();
158 } 210 }
159 211
160 } // namespace WebCore 212 } // namespace WebCore
OLDNEW
« no previous file with comments | « bindings/v8/custom/V8ElementCustom.cpp ('k') | bindings/v8/custom/V8XMLHttpRequestCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698