Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: Source/core/dom/ScriptExecutionContext.cpp

Issue 19596004: Allow sites to enable 'window.onerror' handlers for cross-domain scripts. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rework. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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::sanitizeScriptError(String& errorMessage, int& line Number, int& columnNumber, String& sourceURL) 197 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line Number, int& columnNumber, String& sourceURL, ScriptAccessControlCheckStatus cor sStatus)
198 { 198 {
199 KURL targetURL = completeURL(sourceURL); 199 if (corsStatus == ScriptIsSharedCrossOrigin || securityOrigin()->canRequest( completeURL(sourceURL)))
200 if (securityOrigin()->canRequest(targetURL))
201 return false; 200 return false;
201
202 errorMessage = "Script error."; 202 errorMessage = "Script error.";
203 sourceURL = String(); 203 sourceURL = String();
204 lineNumber = 0; 204 lineNumber = 0;
205 columnNumber = 0; 205 columnNumber = 0;
206 return true; 206 return true;
207 } 207 }
208 208
209 void ScriptExecutionContext::reportException(const String& errorMessage, int lin eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack) 209 void ScriptExecutionContext::reportException(const String& errorMessage, int lin eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack, ScriptAccessControlCheckStatus corsStatus)
210 { 210 {
211 if (m_inDispatchErrorEvent) { 211 if (m_inDispatchErrorEvent) {
212 if (!m_pendingExceptions) 212 if (!m_pendingExceptions)
213 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> > ()); 213 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> > ());
214 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage, lineNumber, columnNumber, sourceURL, callStack))); 214 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage, lineNumber, columnNumber, sourceURL, callStack)));
215 return; 215 return;
216 } 216 }
217 217
218 // First report the original exception and only then all the nested ones. 218 // First report the original exception and only then all the nested ones.
219 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL)) 219 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, c orsStatus))
220 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber, callStack); 220 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber, callStack);
221 221
222 if (!m_pendingExceptions) 222 if (!m_pendingExceptions)
223 return; 223 return;
224 224
225 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { 225 for (size_t i = 0; i < m_pendingExceptions->size(); i++) {
226 PendingException* e = m_pendingExceptions->at(i).get(); 226 PendingException* e = m_pendingExceptions->at(i).get();
227 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber , e->m_columnNumber, e->m_callStack); 227 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber , e->m_columnNumber, e->m_callStack);
228 } 228 }
229 m_pendingExceptions.clear(); 229 m_pendingExceptions.clear();
230 } 230 }
231 231
232 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc riptState* state, unsigned long requestIdentifier) 232 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc riptState* state, unsigned long requestIdentifier)
233 { 233 {
234 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI dentifier); 234 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI dentifier);
235 } 235 }
236 236
237 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) 237 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, ScriptAccessControlCheckS tatus corsStatus)
238 { 238 {
239 EventTarget* target = errorEventTarget(); 239 EventTarget* target = errorEventTarget();
240 if (!target) 240 if (!target)
241 return false; 241 return false;
242 242
243 String message = errorMessage; 243 String message = errorMessage;
244 int line = lineNumber; 244 int line = lineNumber;
245 int column = columnNumber; 245 int column = columnNumber;
246 String sourceName = sourceURL; 246 String sourceName = sourceURL;
247 sanitizeScriptError(message, line, column, sourceName); 247 sanitizeScriptError(message, line, column, sourceName, corsStatus);
abarth-chromium 2013/08/05 22:31:45 This sort of function is crying out for a struct p
Mike West 2013/08/06 06:53:07 Sure, I can do that.
Mike West 2013/08/06 07:54:03 As it turns out, we can remove this method entirel
248 248
249 ASSERT(!m_inDispatchErrorEvent); 249 ASSERT(!m_inDispatchErrorEvent);
250 m_inDispatchErrorEvent = true; 250 m_inDispatchErrorEvent = true;
251 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line , column); 251 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line , column);
252 target->dispatchEvent(errorEvent); 252 target->dispatchEvent(errorEvent);
253 m_inDispatchErrorEvent = false; 253 m_inDispatchErrorEvent = false;
254 return errorEvent->defaultPrevented(); 254 return errorEvent->defaultPrevented();
255 } 255 }
256 256
257 int ScriptExecutionContext::circularSequentialID() 257 int ScriptExecutionContext::circularSequentialID()
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ScriptExecutionContext::Task::~Task() 317 ScriptExecutionContext::Task::~Task()
318 { 318 {
319 } 319 }
320 320
321 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext ) 321 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext )
322 { 322 {
323 m_databaseContext = databaseContext; 323 m_databaseContext = databaseContext;
324 } 324 }
325 325
326 } // namespace WebCore 326 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698