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