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