| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 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 26 matching lines...) Expand all Loading... |
| 37 #include "bindings/v8/V8Binding.h" | 37 #include "bindings/v8/V8Binding.h" |
| 38 #include "bindings/v8/V8WindowShell.h" | 38 #include "bindings/v8/V8WindowShell.h" |
| 39 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
| 40 #include "core/dom/DocumentParser.h" | 40 #include "core/dom/DocumentParser.h" |
| 41 #include "core/events/EventListener.h" | 41 #include "core/events/EventListener.h" |
| 42 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
| 43 #include <v8.h> | 43 #include <v8.h> |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 static const AtomicString& eventParameterName(bool isSVGEvent) | 47 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, const Q
ualifiedName& name, const AtomicString& value, const AtomicString& eventParamete
rName) |
| 48 { | |
| 49 DEFINE_STATIC_LOCAL(const AtomicString, eventString, ("event")); | |
| 50 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt")); | |
| 51 return isSVGEvent ? evtString : eventString; | |
| 52 } | |
| 53 | |
| 54 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, const Q
ualifiedName& name, const AtomicString& value) | |
| 55 { | 48 { |
| 56 ASSERT(node); | 49 ASSERT(node); |
| 57 if (value.isNull()) | 50 if (value.isNull()) |
| 58 return nullptr; | 51 return nullptr; |
| 59 | 52 |
| 60 // FIXME: Very strange: we initialize zero-based number with '1'. | 53 // FIXME: Very strange: we initialize zero-based number with '1'. |
| 61 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); | 54 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); |
| 62 String sourceURL; | 55 String sourceURL; |
| 63 | 56 |
| 64 v8::Isolate* isolate; | 57 v8::Isolate* isolate; |
| 65 if (LocalFrame* frame = node->document().frame()) { | 58 if (LocalFrame* frame = node->document().frame()) { |
| 66 isolate = toIsolate(frame); | 59 isolate = toIsolate(frame); |
| 67 ScriptController& scriptController = frame->script(); | 60 ScriptController& scriptController = frame->script(); |
| 68 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) | 61 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
| 69 return nullptr; | 62 return nullptr; |
| 70 position = scriptController.eventHandlerPosition(); | 63 position = scriptController.eventHandlerPosition(); |
| 71 sourceURL = node->document().url().string(); | 64 sourceURL = node->document().url().string(); |
| 72 } else { | 65 } else { |
| 73 isolate = v8::Isolate::GetCurrent(); | 66 isolate = v8::Isolate::GetCurrent(); |
| 74 } | 67 } |
| 75 | 68 |
| 76 return V8LazyEventListener::create(name.localName(), eventParameterName(node
->isSVGElement()), value, sourceURL, position, node, isolate); | 69 return V8LazyEventListener::create(name.localName(), eventParameterName, val
ue, sourceURL, position, node, isolate); |
| 77 } | 70 } |
| 78 | 71 |
| 79 PassRefPtr<V8LazyEventListener> createAttributeEventListener(LocalFrame* frame,
const QualifiedName& name, const AtomicString& value) | 72 PassRefPtr<V8LazyEventListener> createAttributeEventListener(LocalFrame* frame,
const QualifiedName& name, const AtomicString& value, const AtomicString& eventP
arameterName) |
| 80 { | 73 { |
| 81 if (!frame) | 74 if (!frame) |
| 82 return nullptr; | 75 return nullptr; |
| 83 | 76 |
| 84 if (value.isNull()) | 77 if (value.isNull()) |
| 85 return nullptr; | 78 return nullptr; |
| 86 | 79 |
| 87 ScriptController& scriptController = frame->script(); | 80 ScriptController& scriptController = frame->script(); |
| 88 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) | 81 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
| 89 return nullptr; | 82 return nullptr; |
| 90 | 83 |
| 91 TextPosition position = scriptController.eventHandlerPosition(); | 84 TextPosition position = scriptController.eventHandlerPosition(); |
| 92 String sourceURL = frame->document()->url().string(); | 85 String sourceURL = frame->document()->url().string(); |
| 93 | 86 |
| 94 return V8LazyEventListener::create(name.localName(), eventParameterName(fram
e->document()->isSVGDocument()), value, sourceURL, position, 0, toIsolate(frame)
); | 87 return V8LazyEventListener::create(name.localName(), eventParameterName, val
ue, sourceURL, position, 0, toIsolate(frame)); |
| 95 } | 88 } |
| 96 | 89 |
| 97 static v8::Handle<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isol
ate, v8::Handle<v8::Object> listenerObject) | 90 static v8::Handle<v8::Function> eventListenerEffectiveFunction(v8::Isolate* isol
ate, v8::Handle<v8::Object> listenerObject) |
| 98 { | 91 { |
| 99 v8::Handle<v8::Function> function; | 92 v8::Handle<v8::Function> function; |
| 100 if (listenerObject->IsFunction()) { | 93 if (listenerObject->IsFunction()) { |
| 101 function = v8::Handle<v8::Function>::Cast(listenerObject); | 94 function = v8::Handle<v8::Function>::Cast(listenerObject); |
| 102 } else if (listenerObject->IsObject()) { | 95 } else if (listenerObject->IsObject()) { |
| 103 // Try the "handleEvent" method (EventListener interface). | 96 // Try the "handleEvent" method (EventListener interface). |
| 104 v8::Handle<v8::Value> property = listenerObject->Get(v8AtomicString(isol
ate, "handleEvent")); | 97 v8::Handle<v8::Value> property = listenerObject->Get(v8AtomicString(isol
ate, "handleEvent")); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); | 172 v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); |
| 180 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) | 173 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) |
| 181 sourceName = toCoreString(origin.ResourceName().As<v8::String>()); | 174 sourceName = toCoreString(origin.ResourceName().As<v8::String>()); |
| 182 else | 175 else |
| 183 sourceName = ""; | 176 sourceName = ""; |
| 184 lineNumber = originalFunction->GetScriptLineNumber(); | 177 lineNumber = originalFunction->GetScriptLineNumber(); |
| 185 return true; | 178 return true; |
| 186 } | 179 } |
| 187 | 180 |
| 188 } // namespace WebCore | 181 } // namespace WebCore |
| OLD | NEW |