OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2012 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/dom/ScriptExecutionContext.h" | 29 #include "core/dom/ScriptExecutionContext.h" |
30 | 30 |
| 31 #include "bindings/v8/SerializedScriptValue.h" |
31 #include "core/dom/ContextLifecycleNotifier.h" | 32 #include "core/dom/ContextLifecycleNotifier.h" |
32 #include "core/dom/ErrorEvent.h" | 33 #include "core/dom/ErrorEvent.h" |
33 #include "core/dom/EventTarget.h" | 34 #include "core/dom/EventTarget.h" |
34 #include "core/dom/MessagePort.h" | 35 #include "core/dom/MessagePort.h" |
35 #include "core/html/PublicURLManager.h" | 36 #include "core/html/PublicURLManager.h" |
36 #include "core/inspector/InspectorInstrumentation.h" | 37 #include "core/inspector/InspectorInstrumentation.h" |
37 #include "core/inspector/ScriptCallStack.h" | 38 #include "core/inspector/ScriptCallStack.h" |
38 #include "core/page/DOMTimer.h" | 39 #include "core/page/DOMTimer.h" |
39 #include "core/workers/WorkerGlobalScope.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
40 #include "core/workers/WorkerThread.h" | 41 #include "core/workers/WorkerThread.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 188 } |
188 | 189 |
189 void ScriptExecutionContext::closeMessagePorts() { | 190 void ScriptExecutionContext::closeMessagePorts() { |
190 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); | 191 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); |
191 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { | 192 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { |
192 ASSERT((*iter)->scriptExecutionContext() == this); | 193 ASSERT((*iter)->scriptExecutionContext() == this); |
193 (*iter)->close(); | 194 (*iter)->close(); |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
| 198 bool ScriptExecutionContext::shouldSanitizeScriptError(const String& sourceURL) |
| 199 { |
| 200 return !securityOrigin()->canRequest(completeURL(sourceURL)); |
| 201 } |
| 202 |
197 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL) | 203 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL) |
198 { | 204 { |
199 KURL targetURL = completeURL(sourceURL); | 205 if (!shouldSanitizeScriptError(sourceURL)) |
200 if (securityOrigin()->canRequest(targetURL)) | |
201 return false; | 206 return false; |
202 errorMessage = "Script error."; | 207 errorMessage = "Script error."; |
203 sourceURL = String(); | 208 sourceURL = String(); |
204 lineNumber = 0; | 209 lineNumber = 0; |
205 columnNumber = 0; | 210 columnNumber = 0; |
206 return true; | 211 return true; |
207 } | 212 } |
208 | 213 |
209 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>
callStack) | 214 void ScriptExecutionContext::reportException(PassRefPtr<ErrorEvent> event, PassR
efPtr<ScriptCallStack> callStack) |
210 { | 215 { |
| 216 RefPtr<ErrorEvent> errorEvent = event; |
211 if (m_inDispatchErrorEvent) { | 217 if (m_inDispatchErrorEvent) { |
212 if (!m_pendingExceptions) | 218 if (!m_pendingExceptions) |
213 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); | 219 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); |
214 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, columnNumber, sourceURL, callStack))); | 220 m_pendingExceptions->append(adoptPtr(new PendingException(errorEvent->me
ssage(), errorEvent->lineno(), errorEvent->colno(), errorEvent->filename(), call
Stack))); |
215 return; | 221 return; |
216 } | 222 } |
217 | 223 |
218 // First report the original exception and only then all the nested ones. | 224 // First report the original exception and only then all the nested ones. |
219 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL)) | 225 if (!dispatchErrorEvent(errorEvent)) |
220 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber,
callStack); | 226 logExceptionToConsole(errorEvent->message(), errorEvent->filename(), err
orEvent->lineno(), errorEvent->colno(), callStack); |
221 | 227 |
222 if (!m_pendingExceptions) | 228 if (!m_pendingExceptions) |
223 return; | 229 return; |
224 | 230 |
225 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 231 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
226 PendingException* e = m_pendingExceptions->at(i).get(); | 232 PendingException* e = m_pendingExceptions->at(i).get(); |
227 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); | 233 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); |
228 } | 234 } |
229 m_pendingExceptions.clear(); | 235 m_pendingExceptions.clear(); |
230 } | 236 } |
231 | 237 |
232 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) | 238 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) |
233 { | 239 { |
234 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); | 240 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); |
235 } | 241 } |
236 | 242 |
237 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, int columnNumber, const String& sourceURL) | 243 bool ScriptExecutionContext::dispatchErrorEvent(PassRefPtr<ErrorEvent> event) |
238 { | 244 { |
239 EventTarget* target = errorEventTarget(); | 245 EventTarget* target = errorEventTarget(); |
240 if (!target) | 246 if (!target) |
241 return false; | 247 return false; |
242 | 248 |
243 String message = errorMessage; | 249 RefPtr<ErrorEvent> errorEvent = event; |
244 int line = lineNumber; | 250 if (shouldSanitizeScriptError(errorEvent->filename())) |
245 int column = columnNumber; | 251 errorEvent = ErrorEvent::createSanitizedError(); |
246 String sourceName = sourceURL; | |
247 sanitizeScriptError(message, line, column, sourceName); | |
248 | 252 |
249 ASSERT(!m_inDispatchErrorEvent); | 253 ASSERT(!m_inDispatchErrorEvent); |
250 m_inDispatchErrorEvent = true; | 254 m_inDispatchErrorEvent = true; |
251 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
, column); | |
252 target->dispatchEvent(errorEvent); | 255 target->dispatchEvent(errorEvent); |
253 m_inDispatchErrorEvent = false; | 256 m_inDispatchErrorEvent = false; |
254 return errorEvent->defaultPrevented(); | 257 return errorEvent->defaultPrevented(); |
255 } | 258 } |
256 | 259 |
257 int ScriptExecutionContext::circularSequentialID() | 260 int ScriptExecutionContext::circularSequentialID() |
258 { | 261 { |
259 ++m_circularSequentialID; | 262 ++m_circularSequentialID; |
260 if (m_circularSequentialID <= 0) | 263 if (m_circularSequentialID <= 0) |
261 m_circularSequentialID = 1; | 264 m_circularSequentialID = 1; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ScriptExecutionContext::Task::~Task() | 320 ScriptExecutionContext::Task::~Task() |
318 { | 321 { |
319 } | 322 } |
320 | 323 |
321 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) | 324 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) |
322 { | 325 { |
323 m_databaseContext = databaseContext; | 326 m_databaseContext = databaseContext; |
324 } | 327 } |
325 | 328 |
326 } // namespace WebCore | 329 } // namespace WebCore |
OLD | NEW |