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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (value.isNull()) | 56 if (value.isNull()) |
57 return 0; | 57 return 0; |
58 | 58 |
59 // FIXME: Very strange: we initialize zero-based number with '1'. | 59 // FIXME: Very strange: we initialize zero-based number with '1'. |
60 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); | 60 TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::fir
st()); |
61 String sourceURL; | 61 String sourceURL; |
62 | 62 |
63 v8::Isolate* isolate; | 63 v8::Isolate* isolate; |
64 if (Frame* frame = node->document().frame()) { | 64 if (Frame* frame = node->document().frame()) { |
65 isolate = toIsolate(frame); | 65 isolate = toIsolate(frame); |
66 ScriptController* scriptController = frame->script(); | 66 ScriptController& scriptController = frame->script(); |
67 if (!scriptController->canExecuteScripts(AboutToExecuteScript)) | 67 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
68 return 0; | 68 return 0; |
69 position = scriptController->eventHandlerPosition(); | 69 position = scriptController.eventHandlerPosition(); |
70 sourceURL = node->document().url().string(); | 70 sourceURL = node->document().url().string(); |
71 } else { | 71 } else { |
72 isolate = v8::Isolate::GetCurrent(); | 72 isolate = v8::Isolate::GetCurrent(); |
73 } | 73 } |
74 | 74 |
75 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(node->isSVGElement()), value, sourceURL, position, node, isolate); | 75 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(node->isSVGElement()), value, sourceURL, position, node, isolate); |
76 } | 76 } |
77 | 77 |
78 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, const
QualifiedName& name, const AtomicString& value) | 78 PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, const
QualifiedName& name, const AtomicString& value) |
79 { | 79 { |
80 if (!frame) | 80 if (!frame) |
81 return 0; | 81 return 0; |
82 | 82 |
83 if (value.isNull()) | 83 if (value.isNull()) |
84 return 0; | 84 return 0; |
85 | 85 |
86 ScriptController* scriptController = frame->script(); | 86 ScriptController& scriptController = frame->script(); |
87 if (!scriptController->canExecuteScripts(AboutToExecuteScript)) | 87 if (!scriptController.canExecuteScripts(AboutToExecuteScript)) |
88 return 0; | 88 return 0; |
89 | 89 |
90 TextPosition position = scriptController->eventHandlerPosition(); | 90 TextPosition position = scriptController.eventHandlerPosition(); |
91 String sourceURL = frame->document()->url().string(); | 91 String sourceURL = frame->document()->url().string(); |
92 | 92 |
93 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(frame->document()->isSVGDocument()), value, sourceURL, position, 0, toIsola
te(frame)); | 93 return V8LazyEventListener::create(name.localName().string(), eventParameter
Name(frame->document()->isSVGDocument()), value, sourceURL, position, 0, toIsola
te(frame)); |
94 } | 94 } |
95 | 95 |
96 String eventListenerHandlerBody(Document* document, EventListener* listener) | 96 String eventListenerHandlerBody(Document* document, EventListener* listener) |
97 { | 97 { |
98 if (listener->type() != EventListener::JSEventListenerType) | 98 if (listener->type() != EventListener::JSEventListenerType) |
99 return ""; | 99 return ""; |
100 | 100 |
(...skipping 23 matching lines...) Expand all Loading... |
124 return ScriptValue(); | 124 return ScriptValue(); |
125 return ScriptValue(function, isolate); | 125 return ScriptValue(function, isolate); |
126 } | 126 } |
127 | 127 |
128 ScriptState* eventListenerHandlerScriptState(Frame* frame, EventListener* listen
er) | 128 ScriptState* eventListenerHandlerScriptState(Frame* frame, EventListener* listen
er) |
129 { | 129 { |
130 if (listener->type() != EventListener::JSEventListenerType) | 130 if (listener->type() != EventListener::JSEventListenerType) |
131 return 0; | 131 return 0; |
132 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); | 132 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); |
133 v8::HandleScope scope(toIsolate(frame)); | 133 v8::HandleScope scope(toIsolate(frame)); |
134 v8::Handle<v8::Context> v8Context = frame->script()->windowShell(v8Listener-
>world())->context(); | 134 v8::Handle<v8::Context> v8Context = frame->script().windowShell(v8Listener->
world())->context(); |
135 return ScriptState::forContext(v8Context); | 135 return ScriptState::forContext(v8Context); |
136 } | 136 } |
137 | 137 |
138 bool eventListenerHandlerLocation(Document* document, EventListener* listener, S
tring& sourceName, String& scriptId, int& lineNumber) | 138 bool eventListenerHandlerLocation(Document* document, EventListener* listener, S
tring& sourceName, String& scriptId, int& lineNumber) |
139 { | 139 { |
140 if (listener->type() != EventListener::JSEventListenerType) | 140 if (listener->type() != EventListener::JSEventListenerType) |
141 return false; | 141 return false; |
142 | 142 |
143 v8::HandleScope scope(toIsolate(document)); | 143 v8::HandleScope scope(toIsolate(document)); |
144 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); | 144 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(
listener); |
145 v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world())
; | 145 v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world())
; |
146 v8::Context::Scope contextScope(context); | 146 v8::Context::Scope contextScope(context); |
147 v8::Handle<v8::Object> object = v8Listener->getListenerObject(document); | 147 v8::Handle<v8::Object> object = v8Listener->getListenerObject(document); |
148 if (object.IsEmpty() || !object->IsFunction()) | 148 if (object.IsEmpty() || !object->IsFunction()) |
149 return false; | 149 return false; |
150 | 150 |
151 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(object); | 151 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(object); |
152 v8::Handle<v8::Value> scriptIdValue = function->GetScriptId(); | 152 v8::Handle<v8::Value> scriptIdValue = function->GetScriptId(); |
153 scriptId = toWebCoreStringWithUndefinedOrNullCheck(scriptIdValue); | 153 scriptId = toWebCoreStringWithUndefinedOrNullCheck(scriptIdValue); |
154 v8::ScriptOrigin origin = function->GetScriptOrigin(); | 154 v8::ScriptOrigin origin = function->GetScriptOrigin(); |
155 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) | 155 if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) |
156 sourceName = toWebCoreString(origin.ResourceName().As<v8::String>()); | 156 sourceName = toWebCoreString(origin.ResourceName().As<v8::String>()); |
157 else | 157 else |
158 sourceName = ""; | 158 sourceName = ""; |
159 lineNumber = function->GetScriptLineNumber(); | 159 lineNumber = function->GetScriptLineNumber(); |
160 return true; | 160 return true; |
161 } | 161 } |
162 | 162 |
163 } // namespace WebCore | 163 } // namespace WebCore |
OLD | NEW |