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

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

Issue 174381: Merge Webkit 47001 - 20090810 Vitaly Repeshko <vitalyr@quad.spb.corp.google... (Closed) Base URL: svn://chrome-svn/chrome/branches/WebKit/195/
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 | Annotate | Revision Log
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"
40 #include "V8Node.h" 41 #include "V8Node.h"
42 #include "V8ObjectEventListener.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, which does
60 // 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 0;
70 }
71
72 ACCESSOR_SETTER(NodeEventHandler)
73 {
74 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder());
75 String eventType = toEventType(name);
76
77 // Remove hidden dependency on the old event handler.
78 if (EventListener* listener = node->getAttributeEventListener(eventType)) {
79 if (static_cast<V8AbstractEventListener*>(listener)->isObjectListener()) {
80 v8::Local<v8::Object> v8Listener = static_cast<V8ObjectEventListener *>(listener)->getListenerObject();
81 removeHiddenDependency(info.Holder(), v8Listener, V8Custom::kNodeEve ntListenerCacheIndex);
82 }
83 }
84
85 // Set handler if the value is a function.
86 if (value->IsFunction()) {
87 RefPtr<EventListener> listener = getEventListener(node, value, true, fal se);
88 if (listener) {
89 node->setAttributeEventListener(eventType, listener);
90 createHiddenDependency(info.Holder(), value, V8Custom::kNodeEventLis tenerCacheIndex);
91 }
92 } else {
93 // Otherwise, clear the handler.
94 node->clearAttributeEventListener(eventType);
95 }
96 }
97
98 ACCESSOR_GETTER(NodeEventHandler)
99 {
100 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder());
101
102 EventListener* listener = node->getAttributeEventListener(toEventType(name)) ;
103 return V8DOMWrapper::convertEventListenerToV8Object(listener);
104 }
105
47 CALLBACK_FUNC_DECL(NodeAddEventListener) 106 CALLBACK_FUNC_DECL(NodeAddEventListener)
48 { 107 {
49 INC_STATS("DOM.Node.addEventListener()"); 108 INC_STATS("DOM.Node.addEventListener()");
50 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); 109 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder());
51 110
52 V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame()); 111 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) { 112 if (listener) {
58 String type = toWebCoreString(args[0]); 113 String type = toWebCoreString(args[0]);
59 bool useCapture = args[2]->BooleanValue(); 114 bool useCapture = args[2]->BooleanValue();
60 node->addEventListener(type, listener, useCapture); 115 node->addEventListener(type, listener, useCapture);
116 createHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListe nerCacheIndex);
61 } 117 }
62 return v8::Undefined(); 118 return v8::Undefined();
63 } 119 }
64 120
65 CALLBACK_FUNC_DECL(NodeRemoveEventListener) 121 CALLBACK_FUNC_DECL(NodeRemoveEventListener)
66 { 122 {
67 INC_STATS("DOM.Node.removeEventListener()"); 123 INC_STATS("DOM.Node.removeEventListener()");
68 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder()); 124 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(args.Holder());
69 125
70 V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame());
71 // It is possbile that the owner document of the node is detached 126 // It is possbile that the owner document of the node is detached
72 // from the frame, return immediately in this case. 127 // from the frame.
73 // See issue http://b/878909 128 // See issue http://b/878909
74 if (!proxy) 129 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) { 130 if (listener) {
79 String type = toWebCoreString(args[0]); 131 String type = toWebCoreString(args[0]);
80 bool useCapture = args[2]->BooleanValue(); 132 bool useCapture = args[2]->BooleanValue();
81 node->removeEventListener(type, listener.get(), useCapture); 133 node->removeEventListener(type, listener.get(), useCapture);
134 removeHiddenDependency(args.Holder(), args[1], V8Custom::kNodeEventListe nerCacheIndex);
82 } 135 }
83 136
84 return v8::Undefined(); 137 return v8::Undefined();
85 } 138 }
86 139
87 // This function is customized to take advantage of the optional 4th argument: s houldLazyAttach 140 // This function is customized to take advantage of the optional 4th argument: s houldLazyAttach
88 CALLBACK_FUNC_DECL(NodeInsertBefore) 141 CALLBACK_FUNC_DECL(NodeInsertBefore)
89 { 142 {
90 INC_STATS("DOM.Node.insertBefore"); 143 INC_STATS("DOM.Node.insertBefore");
91 v8::Handle<v8::Value> holder = args.Holder(); 144 v8::Handle<v8::Value> holder = args.Holder();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (ec) { 204 if (ec) {
152 V8Proxy::setDOMException(ec); 205 V8Proxy::setDOMException(ec);
153 return v8::Handle<v8::Value>(); 206 return v8::Handle<v8::Value>();
154 } 207 }
155 if (success) 208 if (success)
156 return args[0]; 209 return args[0];
157 return v8::Null(); 210 return v8::Null();
158 } 211 }
159 212
160 } // namespace WebCore 213 } // namespace WebCore
OLDNEW
« no previous file with comments | « WebCore/bindings/v8/custom/V8ElementCustom.cpp ('k') | WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698