| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/dom/ExecutionContext.h" | 29 #include "core/dom/ExecutionContext.h" |
| 30 | 30 |
| 31 #include "core/dom/AddConsoleMessageTask.h" | 31 #include "core/dom/AddConsoleMessageTask.h" |
| 32 #include "core/dom/ContextLifecycleNotifier.h" | 32 #include "core/dom/ContextLifecycleNotifier.h" |
| 33 #include "core/dom/ExecutionContextTask.h" | 33 #include "core/dom/ExecutionContextTask.h" |
| 34 #include "core/events/ErrorEvent.h" | 34 #include "core/events/ErrorEvent.h" |
| 35 #include "core/events/EventTarget.h" | 35 #include "core/events/EventTarget.h" |
| 36 #include "core/html/PublicURLManager.h" | 36 #include "core/html/PublicURLManager.h" |
| 37 #include "core/inspector/ConsoleMessage.h" |
| 37 #include "core/inspector/InspectorInstrumentation.h" | 38 #include "core/inspector/InspectorInstrumentation.h" |
| 38 #include "core/inspector/ScriptCallStack.h" | 39 #include "core/inspector/ScriptCallStack.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" |
| 41 #include "wtf/MainThread.h" | 42 #include "wtf/MainThread.h" |
| 42 | 43 |
| 43 namespace WebCore { | 44 namespace WebCore { |
| 44 | 45 |
| 45 class ExecutionContext::PendingException : public NoBaseWillBeGarbageCollectedFi
nalized<ExecutionContext::PendingException> { | 46 class ExecutionContext::PendingException : public NoBaseWillBeGarbageCollectedFi
nalized<ExecutionContext::PendingException> { |
| 46 WTF_MAKE_NONCOPYABLE(PendingException); | 47 WTF_MAKE_NONCOPYABLE(PendingException); |
| 47 public: | 48 public: |
| 48 PendingException(const String& errorMessage, int lineNumber, int columnNumbe
r, const String& sourceURL, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) | 49 PendingException(PassRefPtrWillBeRawPtr<ConsoleMessage> consoleError) |
| 49 : m_errorMessage(errorMessage) | 50 : m_consoleError(consoleError) |
| 50 , m_lineNumber(lineNumber) | |
| 51 , m_columnNumber(columnNumber) | |
| 52 , m_sourceURL(sourceURL) | |
| 53 , m_callStack(callStack) | |
| 54 { | 51 { |
| 55 } | 52 } |
| 56 void trace(Visitor* visitor) | 53 void trace(Visitor* visitor) |
| 57 { | 54 { |
| 58 visitor->trace(m_callStack); | 55 visitor->trace(m_consoleError); |
| 59 } | 56 } |
| 60 String m_errorMessage; | 57 RefPtrWillBeMember<ConsoleMessage> m_consoleError; |
| 61 int m_lineNumber; | |
| 62 int m_columnNumber; | |
| 63 String m_sourceURL; | |
| 64 RefPtrWillBeMember<ScriptCallStack> m_callStack; | |
| 65 }; | 58 }; |
| 66 | 59 |
| 67 ExecutionContext::ExecutionContext() | 60 ExecutionContext::ExecutionContext() |
| 68 : m_client(0) | 61 : m_client(0) |
| 69 , m_sandboxFlags(SandboxNone) | 62 , m_sandboxFlags(SandboxNone) |
| 70 , m_circularSequentialID(0) | 63 , m_circularSequentialID(0) |
| 71 , m_inDispatchErrorEvent(false) | 64 , m_inDispatchErrorEvent(false) |
| 72 , m_activeDOMObjectsAreSuspended(false) | 65 , m_activeDOMObjectsAreSuspended(false) |
| 73 , m_activeDOMObjectsAreStopped(false) | 66 , m_activeDOMObjectsAreStopped(false) |
| 74 { | 67 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // Ensure all ActiveDOMObjects are suspended also newly created ones. | 119 // Ensure all ActiveDOMObjects are suspended also newly created ones. |
| 127 if (m_activeDOMObjectsAreSuspended) | 120 if (m_activeDOMObjectsAreSuspended) |
| 128 object->suspend(); | 121 object->suspend(); |
| 129 } | 122 } |
| 130 | 123 |
| 131 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) | 124 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) |
| 132 { | 125 { |
| 133 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); | 126 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); |
| 134 } | 127 } |
| 135 | 128 |
| 136 void ExecutionContext::reportException(PassRefPtrWillBeRawPtr<ErrorEvent> event,
PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, AccessControlStatus corsStat
us) | 129 void ExecutionContext::reportException(PassRefPtrWillBeRawPtr<ErrorEvent> event,
PassRefPtrWillBeRawPtr<ConsoleMessage> consoleError) |
| 137 { | 130 { |
| 138 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; | 131 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; |
| 132 RefPtrWillBeRawPtr<ConsoleMessage> errorDetails = consoleError; |
| 133 |
| 139 if (m_inDispatchErrorEvent) { | 134 if (m_inDispatchErrorEvent) { |
| 140 if (!m_pendingExceptions) | 135 if (!m_pendingExceptions) |
| 141 m_pendingExceptions = adoptPtrWillBeNoop(new WillBeHeapVector<OwnPtr
WillBeMember<PendingException> >()); | 136 m_pendingExceptions = adoptPtrWillBeNoop(new WillBeHeapVector<OwnPtr
WillBeMember<PendingException> >()); |
| 142 m_pendingExceptions->append(adoptPtrWillBeNoop(new PendingException(erro
rEvent->messageForConsole(), errorEvent->lineno(), errorEvent->colno(), errorEve
nt->filename(), callStack))); | 137 m_pendingExceptions->append(adoptPtrWillBeNoop(new PendingException(erro
rDetails.release()))); |
| 143 return; | 138 return; |
| 144 } | 139 } |
| 145 | 140 |
| 141 AccessControlStatus corsStatus = errorDetails->corsStatus(); |
| 146 // First report the original exception and only then all the nested ones. | 142 // First report the original exception and only then all the nested ones. |
| 147 if (!dispatchErrorEvent(errorEvent, corsStatus) && m_client) | 143 if (!dispatchErrorEvent(errorEvent, corsStatus) && m_client /* redundancy ch
eck */) { |
| 148 m_client->logExceptionToConsole(errorEvent->messageForConsole(), errorEv
ent->filename(), errorEvent->lineno(), errorEvent->colno(), callStack); | 144 errorDetails->setMessage(errorEvent->messageForConsole()); |
| 145 errorDetails->setURL(errorEvent->filename()); |
| 146 m_client->logExceptionToConsole(errorDetails.release()); |
| 147 } |
| 149 | 148 |
| 150 if (!m_pendingExceptions) | 149 if (!m_pendingExceptions) |
| 151 return; | 150 return; |
| 152 | 151 |
| 153 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 152 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
| 154 PendingException* e = m_pendingExceptions->at(i).get(); | 153 PendingException* e = m_pendingExceptions->at(i).get(); |
| 155 if (m_client) | 154 if (m_client) |
| 156 m_client->logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e
->m_lineNumber, e->m_columnNumber, e->m_callStack); | 155 m_client->logExceptionToConsole(e->m_consoleError); |
| 157 } | 156 } |
| 158 m_pendingExceptions.clear(); | 157 m_pendingExceptions.clear(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 void ExecutionContext::addConsoleMessage(MessageSource source, MessageLevel leve
l, const String& message, const String& sourceURL, unsigned lineNumber) | 160 void ExecutionContext::addConsoleMessage(MessageSource source, MessageLevel leve
l, const String& message, const String& sourceURL, unsigned lineNumber) |
| 162 { | 161 { |
| 163 if (!m_client) | 162 if (!m_client) |
| 164 return; | 163 return; |
| 165 m_client->addMessage(source, level, message, sourceURL, lineNumber, 0); | 164 m_client->addMessage(ConsoleMessage::create(source, level, message, sourceUR
L, lineNumber, 0, nullptr, nullptr, 0, NotSharableCrossOrigin)); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void ExecutionContext::addConsoleMessage(MessageSource source, MessageLevel leve
l, const String& message, ScriptState* scriptState) | 167 void ExecutionContext::addConsoleMessage(MessageSource source, MessageLevel leve
l, const String& message, ScriptState* scriptState) |
| 169 { | 168 { |
| 170 if (!m_client) | 169 if (!m_client) |
| 171 return; | 170 return; |
| 172 m_client->addMessage(source, level, message, String(), 0, scriptState); | 171 m_client->addMessage(ConsoleMessage::create(source, level, message, String()
, 0, 0, nullptr, scriptState, 0, NotSharableCrossOrigin)); |
| 173 } | 172 } |
| 174 | 173 |
| 175 bool ExecutionContext::dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent> eve
nt, AccessControlStatus corsStatus) | 174 bool ExecutionContext::dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent> eve
nt, AccessControlStatus corsStatus) |
| 176 { | 175 { |
| 177 if (!m_client) | 176 if (!m_client) |
| 178 return false; | 177 return false; |
| 179 EventTarget* target = m_client->errorEventTarget(); | 178 EventTarget* target = m_client->errorEventTarget(); |
| 180 if (!target) | 179 if (!target) |
| 181 return false; | 180 return false; |
| 182 | 181 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 331 |
| 333 void ExecutionContext::trace(Visitor* visitor) | 332 void ExecutionContext::trace(Visitor* visitor) |
| 334 { | 333 { |
| 335 #if ENABLE(OILPAN) | 334 #if ENABLE(OILPAN) |
| 336 visitor->trace(m_pendingExceptions); | 335 visitor->trace(m_pendingExceptions); |
| 337 #endif | 336 #endif |
| 338 Supplementable<WebCore::ExecutionContext>::trace(visitor); | 337 Supplementable<WebCore::ExecutionContext>::trace(visitor); |
| 339 } | 338 } |
| 340 | 339 |
| 341 } // namespace WebCore | 340 } // namespace WebCore |
| OLD | NEW |