OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 ASSERT((*iter)->scriptExecutionContext() == this); | 279 ASSERT((*iter)->scriptExecutionContext() == this); |
280 (*iter)->close(); | 280 (*iter)->close(); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 void ScriptExecutionContext::setSecurityOrigin(PassRefPtr<SecurityOrigin> securi
tyOrigin) | 284 void ScriptExecutionContext::setSecurityOrigin(PassRefPtr<SecurityOrigin> securi
tyOrigin) |
285 { | 285 { |
286 m_securityOrigin = securityOrigin; | 286 m_securityOrigin = securityOrigin; |
287 } | 287 } |
288 | 288 |
| 289 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, String& sourceURL) |
| 290 { |
| 291 KURL targetURL = completeURL(sourceURL); |
| 292 if (securityOrigin()->canRequest(targetURL)) |
| 293 return false; |
| 294 errorMessage = "Script error."; |
| 295 sourceURL = String(); |
| 296 lineNumber = 0; |
| 297 return true; |
| 298 } |
| 299 |
289 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack) | 300 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack) |
290 { | 301 { |
291 if (m_inDispatchErrorEvent) { | 302 if (m_inDispatchErrorEvent) { |
292 if (!m_pendingExceptions) | 303 if (!m_pendingExceptions) |
293 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); | 304 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); |
294 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, sourceURL, callStack))); | 305 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, sourceURL, callStack))); |
295 return; | 306 return; |
296 } | 307 } |
297 | 308 |
298 // First report the original exception and only then all the nested ones. | 309 // First report the original exception and only then all the nested ones. |
299 if (!dispatchErrorEvent(errorMessage, lineNumber, sourceURL)) | 310 if (!dispatchErrorEvent(errorMessage, lineNumber, sourceURL)) |
300 logExceptionToConsole(errorMessage, lineNumber, sourceURL, callStack); | 311 logExceptionToConsole(errorMessage, lineNumber, sourceURL, callStack); |
301 | 312 |
302 if (!m_pendingExceptions) | 313 if (!m_pendingExceptions) |
303 return; | 314 return; |
304 | 315 |
305 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 316 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
306 PendingException* e = m_pendingExceptions->at(i).get(); | 317 PendingException* e = m_pendingExceptions->at(i).get(); |
307 logExceptionToConsole(e->m_errorMessage, e->m_lineNumber, e->m_sourceURL
, e->m_callStack); | 318 logExceptionToConsole(e->m_errorMessage, e->m_lineNumber, e->m_sourceURL
, e->m_callStack); |
308 } | 319 } |
309 m_pendingExceptions.clear(); | 320 m_pendingExceptions.clear(); |
310 } | 321 } |
311 | 322 |
312 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, const String& sourceURL) | 323 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, const String& sourceURL) |
313 { | 324 { |
314 EventTarget* target = errorEventTarget(); | 325 EventTarget* target = errorEventTarget(); |
315 if (!target) | 326 if (!target) |
316 return false; | 327 return false; |
317 | 328 |
318 String message; | 329 String message = errorMessage; |
319 int line; | 330 int line = lineNumber; |
320 String sourceName; | 331 String sourceName = sourceURL; |
321 KURL targetUrl = completeURL(sourceURL); | 332 sanitizeScriptError(message, line, sourceName); |
322 if (securityOrigin()->canRequest(targetUrl)) { | |
323 message = errorMessage; | |
324 line = lineNumber; | |
325 sourceName = sourceURL; | |
326 } else { | |
327 message = "Script error."; | |
328 sourceName = String(); | |
329 line = 0; | |
330 } | |
331 | 333 |
332 ASSERT(!m_inDispatchErrorEvent); | 334 ASSERT(!m_inDispatchErrorEvent); |
333 m_inDispatchErrorEvent = true; | 335 m_inDispatchErrorEvent = true; |
334 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
); | 336 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
); |
335 target->dispatchEvent(errorEvent); | 337 target->dispatchEvent(errorEvent); |
336 m_inDispatchErrorEvent = false; | 338 m_inDispatchErrorEvent = false; |
337 return errorEvent->defaultPrevented(); | 339 return errorEvent->defaultPrevented(); |
338 } | 340 } |
339 | 341 |
340 void ScriptExecutionContext::addTimeout(int timeoutId, DOMTimer* timer) | 342 void ScriptExecutionContext::addTimeout(int timeoutId, DOMTimer* timer) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if (isWorkerContext()) | 401 if (isWorkerContext()) |
400 return static_cast<WorkerContext*>(this)->script()->globalData(); | 402 return static_cast<WorkerContext*>(this)->script()->globalData(); |
401 #endif | 403 #endif |
402 | 404 |
403 ASSERT_NOT_REACHED(); | 405 ASSERT_NOT_REACHED(); |
404 return 0; | 406 return 0; |
405 } | 407 } |
406 #endif | 408 #endif |
407 | 409 |
408 } // namespace WebCore | 410 } // namespace WebCore |
OLD | NEW |