| 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/V8AbstractEventListener.h" | 37 #include "bindings/v8/V8AbstractEventListener.h" |
| 38 #include "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
| 39 #include "bindings/v8/V8WindowShell.h" | 39 #include "bindings/v8/V8WindowShell.h" |
| 40 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
| 41 #include "core/dom/DocumentParser.h" | 41 #include "core/dom/DocumentParser.h" |
| 42 #include "core/events/EventListener.h" | 42 #include "core/events/EventListener.h" |
| 43 #include "core/frame/Frame.h" | 43 #include "core/frame/Frame.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 static const String& eventParameterName(bool isSVGEvent) | 47 static const AtomicString& eventParameterName(bool isSVGEvent) |
| 48 { | 48 { |
| 49 DEFINE_STATIC_LOCAL(const String, eventString, ("event")); | 49 DEFINE_STATIC_LOCAL(const AtomicString, eventString, ("event")); |
| 50 DEFINE_STATIC_LOCAL(const String, evtString, ("evt")); | 50 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt")); |
| 51 return isSVGEvent ? evtString : eventString; | 51 return isSVGEvent ? evtString : eventString; |
| 52 } | 52 } |
| 53 | 53 |
| 54 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, const Q
ualifiedName& name, const AtomicString& value) | 54 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, const Q
ualifiedName& name, const AtomicString& value) |
| 55 { | 55 { |
| 56 ASSERT(node); | 56 ASSERT(node); |
| 57 if (value.isNull()) | 57 if (value.isNull()) |
| 58 return 0; | 58 return 0; |
| 59 | 59 |
| 60 // FIXME: Very strange: we initialize zero-based number with '1'. | 60 // FIXME: Very strange: we initialize zero-based number with '1'. |
| 61 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); | 61 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); |
| 62 String sourceURL; | 62 String sourceURL; |
| 63 | 63 |
| 64 v8::Isolate* isolate; | 64 v8::Isolate* isolate; |
| 65 if (Frame* frame = node->document().frame()) { | 65 if (Frame* frame = node->document().frame()) { |
| 66 isolate = toIsolate(frame); | 66 isolate = toIsolate(frame); |
| 67 ScriptController& scriptController = frame->script(); | 67 ScriptController& scriptController = frame->script(); |
| 68 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) | 68 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
| 69 return 0; | 69 return 0; |
| 70 position = scriptController.eventHandlerPosition(); | 70 position = scriptController.eventHandlerPosition(); |
| 71 sourceURL = node->document().url().string(); | 71 sourceURL = node->document().url().string(); |
| 72 } else { | 72 } else { |
| 73 isolate = v8::Isolate::GetCurrent(); | 73 isolate = v8::Isolate::GetCurrent(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(node->isSVGElement()), value, sourceURL, position, node, isolate); | 76 return V8LazyEventListener::create(name.localName(), eventParameterName(node
->isSVGElement()), value, sourceURL, position, node, isolate); |
| 77 } | 77 } |
| 78 | 78 |
| 79 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, const
QualifiedName& name, const AtomicString& value) | 79 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, const
QualifiedName& name, const AtomicString& value) |
| 80 { | 80 { |
| 81 if (!frame) | 81 if (!frame) |
| 82 return 0; | 82 return 0; |
| 83 | 83 |
| 84 if (value.isNull()) | 84 if (value.isNull()) |
| 85 return 0; | 85 return 0; |
| 86 | 86 |
| 87 ScriptController& scriptController = frame->script(); | 87 ScriptController& scriptController = frame->script(); |
| 88 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) | 88 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
| 89 return 0; | 89 return 0; |
| 90 | 90 |
| 91 TextPosition position = scriptController.eventHandlerPosition(); | 91 TextPosition position = scriptController.eventHandlerPosition(); |
| 92 String sourceURL = frame->document()->url().string(); | 92 String sourceURL = frame->document()->url().string(); |
| 93 | 93 |
| 94 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(frame->document()->isSVGDocument()), value, sourceURL, position, 0, toIsola
te(frame)); | 94 return V8LazyEventListener::create(name.localName(), eventParameterName(fram
e->document()->isSVGDocument()), value, sourceURL, position, 0, toIsolate(frame)
); |
| 95 } | 95 } |
| 96 | 96 |
| 97 String eventListenerHandlerBody(Document* document, EventListener* listener) | 97 String eventListenerHandlerBody(Document* document, EventListener* listener) |
| 98 { | 98 { |
| 99 if (listener->type() != EventListener::JSEventListenerType) | 99 if (listener->type() != EventListener::JSEventListenerType) |
| 100 return ""; | 100 return ""; |
| 101 | 101 |
| 102 v8::HandleScope scope(toIsolate(document)); | 102 v8::HandleScope scope(toIsolate(document)); |
| 103 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); | 103 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); |
| 104 v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world())
; | 104 v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world())
; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 v8::ScriptOrigin origin = function->GetScriptOrigin(); | 155 v8::ScriptOrigin origin = function->GetScriptOrigin(); |
| 156 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) | 156 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) |
| 157 sourceName = toWebCoreString(origin.ResourceName().As<v8::String>()); | 157 sourceName = toWebCoreString(origin.ResourceName().As<v8::String>()); |
| 158 else | 158 else |
| 159 sourceName = ""; | 159 sourceName = ""; |
| 160 lineNumber = function->GetScriptLineNumber(); | 160 lineNumber = function->GetScriptLineNumber(); |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace WebCore | 164 } // namespace WebCore |
| OLD | NEW |