OLD | NEW |
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 28 matching lines...) Expand all Loading... |
39 #include "bindings/core/v8/V8HTMLFormElement.h" | 39 #include "bindings/core/v8/V8HTMLFormElement.h" |
40 #include "bindings/core/v8/V8HiddenValue.h" | 40 #include "bindings/core/v8/V8HiddenValue.h" |
41 #include "bindings/core/v8/V8Node.h" | 41 #include "bindings/core/v8/V8Node.h" |
42 #include "bindings/core/v8/V8ScriptRunner.h" | 42 #include "bindings/core/v8/V8ScriptRunner.h" |
43 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
44 #include "core/dom/Node.h" | 44 #include "core/dom/Node.h" |
45 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
46 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
47 #include "core/html/HTMLElement.h" | 47 #include "core/html/HTMLElement.h" |
48 #include "core/html/HTMLFormElement.h" | 48 #include "core/html/HTMLFormElement.h" |
49 #include "core/inspector/InspectorInstrumentation.h" | |
50 | 49 |
51 #include "wtf/StdLibExtras.h" | 50 #include "wtf/StdLibExtras.h" |
52 | 51 |
53 namespace blink { | 52 namespace blink { |
54 | 53 |
55 V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const
AtomicString& eventParameterName, const String& code, const String sourceURL, c
onst TextPosition& position, Node* node, v8::Isolate* isolate) | 54 V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const
AtomicString& eventParameterName, const String& code, const String sourceURL, c
onst TextPosition& position, Node* node, v8::Isolate* isolate) |
56 : V8AbstractEventListener(true, DOMWrapperWorld::mainWorld(), isolate) | 55 : V8AbstractEventListener(true, DOMWrapperWorld::mainWorld(), isolate) |
57 , m_functionName(functionName) | 56 , m_functionName(functionName) |
58 , m_eventParameterName(eventParameterName) | 57 , m_eventParameterName(eventParameterName) |
59 , m_code(code) | 58 , m_code(code) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 124 |
126 if (!toDocument(executionContext)->allowInlineEventHandlers(m_node, this, m_
sourceURL, m_position.m_line)) { | 125 if (!toDocument(executionContext)->allowInlineEventHandlers(m_node, this, m_
sourceURL, m_position.m_line)) { |
127 clearListenerObject(); | 126 clearListenerObject(); |
128 return; | 127 return; |
129 } | 128 } |
130 | 129 |
131 if (hasExistingListenerObject()) | 130 if (hasExistingListenerObject()) |
132 return; | 131 return; |
133 | 132 |
134 ScriptState::Scope scope(scriptState); | 133 ScriptState::Scope scope(scriptState); |
135 String listenerSource = InspectorInstrumentation::preprocessEventListener(t
oDocument(executionContext)->frame(), m_code, m_sourceURL, m_functionName); | |
136 | 134 |
137 // FIXME: Remove the following 'with' hack. | 135 // FIXME: Remove the following 'with' hack. |
138 // | 136 // |
139 // Nodes other than the document object, when executing inline event | 137 // Nodes other than the document object, when executing inline event |
140 // handlers push document, form owner, and the target node on the scope chai
n. | 138 // handlers push document, form owner, and the target node on the scope chai
n. |
141 // We do this by using 'with' statement. | 139 // We do this by using 'with' statement. |
142 // See chrome/fast/forms/form-action.html | 140 // See chrome/fast/forms/form-action.html |
143 // chrome/fast/forms/selected-index-value.html | 141 // chrome/fast/forms/selected-index-value.html |
144 // base/fast/overflow/onscroll-layer-self-destruct.html | 142 // base/fast/overflow/onscroll-layer-self-destruct.html |
145 // | 143 // |
146 // Don't use new lines so that lines in the modified handler | 144 // Don't use new lines so that lines in the modified handler |
147 // have the same numbers as in the original code. | 145 // have the same numbers as in the original code. |
148 // FIXME: V8 does not allow us to programmatically create object environment
s so | 146 // FIXME: V8 does not allow us to programmatically create object environment
s so |
149 // we have to do this hack! What if m_code escapes to run arbitrary s
cript? | 147 // we have to do this hack! What if m_code escapes to run arbitrary s
cript? |
150 // | 148 // |
151 // Call with 4 arguments instead of 3, pass additional null as the last para
meter. | 149 // Call with 4 arguments instead of 3, pass additional null as the last para
meter. |
152 // By calling the function with 4 arguments, we create a setter on arguments
object | 150 // By calling the function with 4 arguments, we create a setter on arguments
object |
153 // which would shadow property "3" on the prototype. | 151 // which would shadow property "3" on the prototype. |
154 String code = "(function() {" | 152 String code = "(function() {" |
155 "with (this[2]) {" | 153 "with (this[2]) {" |
156 "with (this[1]) {" | 154 "with (this[1]) {" |
157 "with (this[0]) {" | 155 "with (this[0]) {" |
158 "return function(" + m_eventParameterName + ") {" + | 156 "return function(" + m_eventParameterName + ") {" + |
159 listenerSource + "\n" // Insert '\n' otherwise //-style comments
could break the handler. | 157 m_code + "\n" // Insert '\n' otherwise //-style comments could b
reak the handler. |
160 "};" | 158 "};" |
161 "}}}})"; | 159 "}}}})"; |
162 | 160 |
163 v8::Handle<v8::String> codeExternalString = v8String(isolate(), code); | 161 v8::Handle<v8::String> codeExternalString = v8String(isolate(), code); |
164 | 162 |
165 v8::Local<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(co
deExternalString, isolate(), m_sourceURL, m_position); | 163 v8::Local<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(co
deExternalString, isolate(), m_sourceURL, m_position); |
166 if (result.IsEmpty()) | 164 if (result.IsEmpty()) |
167 return; | 165 return; |
168 | 166 |
169 // Call the outer function to get the inner function. | 167 // Call the outer function to get the inner function. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. | 218 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. |
221 // m_functionName = String(); | 219 // m_functionName = String(); |
222 // m_code = String(); | 220 // m_code = String(); |
223 // m_eventParameterName = String(); | 221 // m_eventParameterName = String(); |
224 // m_sourceURL = String(); | 222 // m_sourceURL = String(); |
225 | 223 |
226 setListenerObject(wrappedFunction); | 224 setListenerObject(wrappedFunction); |
227 } | 225 } |
228 | 226 |
229 } // namespace blink | 227 } // namespace blink |
OLD | NEW |