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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 | 188 |
189 void ScriptExecutionContext::closeMessagePorts() { | 189 void ScriptExecutionContext::closeMessagePorts() { |
190 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); | 190 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); |
191 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { | 191 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { |
192 ASSERT((*iter)->scriptExecutionContext() == this); | 192 ASSERT((*iter)->scriptExecutionContext() == this); |
193 (*iter)->close(); | 193 (*iter)->close(); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
| 197 bool ScriptExecutionContext::shouldSanitizeScriptError(const String& sourceURL) |
| 198 { |
| 199 return !securityOrigin()->canRequest(completeURL(sourceURL)); |
| 200 } |
| 201 |
197 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL) | 202 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL) |
198 { | 203 { |
199 KURL targetURL = completeURL(sourceURL); | 204 if (!shouldSanitizeScriptError(sourceURL)) |
200 if (securityOrigin()->canRequest(targetURL)) | |
201 return false; | 205 return false; |
202 errorMessage = "Script error."; | 206 errorMessage = "Script error."; |
203 sourceURL = String(); | 207 sourceURL = String(); |
204 lineNumber = 0; | 208 lineNumber = 0; |
205 columnNumber = 0; | 209 columnNumber = 0; |
206 return true; | 210 return true; |
207 } | 211 } |
208 | 212 |
209 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>
callStack) | 213 void ScriptExecutionContext::reportException(PassRefPtr<ErrorEvent> event, PassR
efPtr<ScriptCallStack> callStack) |
210 { | 214 { |
| 215 RefPtr<ErrorEvent> errorEvent = event; |
211 if (m_inDispatchErrorEvent) { | 216 if (m_inDispatchErrorEvent) { |
212 if (!m_pendingExceptions) | 217 if (!m_pendingExceptions) |
213 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); | 218 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); |
214 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, columnNumber, sourceURL, callStack))); | 219 m_pendingExceptions->append(adoptPtr(new PendingException(errorEvent->me
ssage(), errorEvent->lineno(), errorEvent->colno(), errorEvent->filename(), call
Stack))); |
215 return; | 220 return; |
216 } | 221 } |
217 | 222 |
218 // First report the original exception and only then all the nested ones. | 223 // First report the original exception and only then all the nested ones. |
219 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL)) | 224 if (!dispatchErrorEvent(errorEvent)) |
220 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber,
callStack); | 225 logExceptionToConsole(errorEvent->message(), errorEvent->filename(), err
orEvent->lineno(), errorEvent->colno(), callStack); |
221 | 226 |
222 if (!m_pendingExceptions) | 227 if (!m_pendingExceptions) |
223 return; | 228 return; |
224 | 229 |
225 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 230 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
226 PendingException* e = m_pendingExceptions->at(i).get(); | 231 PendingException* e = m_pendingExceptions->at(i).get(); |
227 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); | 232 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); |
228 } | 233 } |
229 m_pendingExceptions.clear(); | 234 m_pendingExceptions.clear(); |
230 } | 235 } |
231 | 236 |
232 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) | 237 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) |
233 { | 238 { |
234 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); | 239 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); |
235 } | 240 } |
236 | 241 |
237 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, int columnNumber, const String& sourceURL) | 242 bool ScriptExecutionContext::dispatchErrorEvent(PassRefPtr<ErrorEvent> event) |
238 { | 243 { |
239 EventTarget* target = errorEventTarget(); | 244 EventTarget* target = errorEventTarget(); |
240 if (!target) | 245 if (!target) |
241 return false; | 246 return false; |
242 | 247 |
243 String message = errorMessage; | 248 RefPtr<ErrorEvent> errorEvent = event; |
244 int line = lineNumber; | 249 if (shouldSanitizeScriptError(errorEvent->filename())) |
245 int column = columnNumber; | 250 errorEvent = ErrorEvent::createSanitizedError(); |
246 String sourceName = sourceURL; | |
247 sanitizeScriptError(message, line, column, sourceName); | |
248 | 251 |
249 ASSERT(!m_inDispatchErrorEvent); | 252 ASSERT(!m_inDispatchErrorEvent); |
250 m_inDispatchErrorEvent = true; | 253 m_inDispatchErrorEvent = true; |
251 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
, column); | |
252 target->dispatchEvent(errorEvent); | 254 target->dispatchEvent(errorEvent); |
253 m_inDispatchErrorEvent = false; | 255 m_inDispatchErrorEvent = false; |
254 return errorEvent->defaultPrevented(); | 256 return errorEvent->defaultPrevented(); |
255 } | 257 } |
256 | 258 |
257 int ScriptExecutionContext::circularSequentialID() | 259 int ScriptExecutionContext::circularSequentialID() |
258 { | 260 { |
259 ++m_circularSequentialID; | 261 ++m_circularSequentialID; |
260 if (m_circularSequentialID <= 0) | 262 if (m_circularSequentialID <= 0) |
261 m_circularSequentialID = 1; | 263 m_circularSequentialID = 1; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ScriptExecutionContext::Task::~Task() | 319 ScriptExecutionContext::Task::~Task() |
318 { | 320 { |
319 } | 321 } |
320 | 322 |
321 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) | 323 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) |
322 { | 324 { |
323 m_databaseContext = databaseContext; | 325 m_databaseContext = databaseContext; |
324 } | 326 } |
325 | 327 |
326 } // namespace WebCore | 328 } // namespace WebCore |
OLD | NEW |