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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 1854423002: ASSERT -> {DCHECK|DCHECK_XX}, ENABLE(ASSERT) -> DCHECK_IS_ON() in dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark svg/as-image/svg-nested.html crash on win Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 , m_isExternalScript(false) 64 , m_isExternalScript(false)
65 , m_alreadyStarted(alreadyStarted) 65 , m_alreadyStarted(alreadyStarted)
66 , m_haveFiredLoad(false) 66 , m_haveFiredLoad(false)
67 , m_willBeParserExecuted(false) 67 , m_willBeParserExecuted(false)
68 , m_readyToBeParserExecuted(false) 68 , m_readyToBeParserExecuted(false)
69 , m_willExecuteInOrder(false) 69 , m_willExecuteInOrder(false)
70 , m_willExecuteWhenDocumentFinishedParsing(false) 70 , m_willExecuteWhenDocumentFinishedParsing(false)
71 , m_forceAsync(!parserInserted) 71 , m_forceAsync(!parserInserted)
72 , m_createdDuringDocumentWrite(createdDuringDocumentWrite) 72 , m_createdDuringDocumentWrite(createdDuringDocumentWrite)
73 { 73 {
74 ASSERT(m_element); 74 DCHECK(m_element);
75 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) 75 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite())
76 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); 76 m_startLineNumber = element->document().scriptableDocumentParser()->line Number();
77 } 77 }
78 78
79 ScriptLoader::~ScriptLoader() 79 ScriptLoader::~ScriptLoader()
80 { 80 {
81 } 81 }
82 82
83 DEFINE_TRACE(ScriptLoader) 83 DEFINE_TRACE(ScriptLoader)
84 { 84 {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 dispatchErrorEvent(); 277 dispatchErrorEvent();
278 return false; 278 return false;
279 } 279 }
280 } 280 }
281 281
282 return true; 282 return true;
283 } 283 }
284 284
285 bool ScriptLoader::fetchScript(const String& sourceUrl, FetchRequest::DeferOptio n defer) 285 bool ScriptLoader::fetchScript(const String& sourceUrl, FetchRequest::DeferOptio n defer)
286 { 286 {
287 ASSERT(m_element); 287 DCHECK(m_element);
288 288
289 RawPtr<Document> elementDocument(m_element->document()); 289 RawPtr<Document> elementDocument(m_element->document());
290 if (!m_element->inShadowIncludingDocument() || m_element->document() != elem entDocument) 290 if (!m_element->inShadowIncludingDocument() || m_element->document() != elem entDocument)
291 return false; 291 return false;
292 292
293 ASSERT(!m_resource); 293 DCHECK(!m_resource);
294 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) { 294 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
295 FetchRequest request(ResourceRequest(elementDocument->completeURL(source Url)), m_element->localName()); 295 FetchRequest request(ResourceRequest(elementDocument->completeURL(source Url)), m_element->localName());
296 296
297 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(m_elem ent->fastGetAttribute(HTMLNames::crossoriginAttr)); 297 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(m_elem ent->fastGetAttribute(HTMLNames::crossoriginAttr));
298 if (crossOrigin != CrossOriginAttributeNotSet) 298 if (crossOrigin != CrossOriginAttributeNotSet)
299 request.setCrossOriginAccessControl(elementDocument->getSecurityOrig in(), crossOrigin); 299 request.setCrossOriginAccessControl(elementDocument->getSecurityOrig in(), crossOrigin);
300 request.setCharset(scriptCharset()); 300 request.setCharset(scriptCharset());
301 301
302 // Skip fetch-related CSP checks if the script element has a valid nonce , or if dynamically 302 // Skip fetch-related CSP checks if the script element has a valid nonce , or if dynamically
303 // injected script is whitelisted and this script is not parser-inserted . 303 // injected script is whitelisted and this script is not parser-inserted .
(...skipping 24 matching lines...) Expand all
328 328
329 if (m_resource) 329 if (m_resource)
330 return true; 330 return true;
331 331
332 dispatchErrorEvent(); 332 dispatchErrorEvent();
333 return false; 333 return false;
334 } 334 }
335 335
336 bool isHTMLScriptLoader(Element* element) 336 bool isHTMLScriptLoader(Element* element)
337 { 337 {
338 ASSERT(element); 338 DCHECK(element);
339 return isHTMLScriptElement(*element); 339 return isHTMLScriptElement(*element);
340 } 340 }
341 341
342 bool isSVGScriptLoader(Element* element) 342 bool isSVGScriptLoader(Element* element)
343 { 343 {
344 ASSERT(element); 344 DCHECK(element);
345 return isSVGScriptElement(*element); 345 return isSVGScriptElement(*element);
346 } 346 }
347 347
348 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype) 348 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype)
349 { 349 {
350 bool text = mimetype.lower().startsWith("text/"); 350 bool text = mimetype.lower().startsWith("text/");
351 bool application = mimetype.lower().startsWith("application/"); 351 bool application = mimetype.lower().startsWith("application/");
352 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5))); 352 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5)));
353 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url()); 353 bool sameOrigin = m_element->document().getSecurityOrigin()->canRequest(m_re source->url());
354 if (expectedJs) { 354 if (expectedJs) {
355 return; 355 return;
356 } 356 }
357 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript); 357 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOriginTex tScript : application ? UseCounter::SameOriginApplicationScript : UseCounter::Sa meOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : application ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScript);
358 UseCounter::count(frame, feature); 358 UseCounter::count(frame, feature);
359 } 359 }
360 360
361 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime) 361 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime)
362 { 362 {
363 ASSERT(m_alreadyStarted); 363 DCHECK(m_alreadyStarted);
364 364
365 if (sourceCode.isEmpty()) 365 if (sourceCode.isEmpty())
366 return true; 366 return true;
367 367
368 RawPtr<Document> elementDocument(m_element->document()); 368 RawPtr<Document> elementDocument(m_element->document());
369 RawPtr<Document> contextDocument = elementDocument->contextDocument().get(); 369 RawPtr<Document> contextDocument = elementDocument->contextDocument().get();
370 if (!contextDocument) 370 if (!contextDocument)
371 return true; 371 return true;
372 372
373 LocalFrame* frame = contextDocument->frame(); 373 LocalFrame* frame = contextDocument->frame();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 427
428 if (isHTMLScriptLoader(m_element)) 428 if (isHTMLScriptLoader(m_element))
429 contextDocument->pushCurrentScript(toHTMLScriptElement(m_element)); 429 contextDocument->pushCurrentScript(toHTMLScriptElement(m_element));
430 430
431 // Create a script from the script element node, using the script 431 // Create a script from the script element node, using the script
432 // block's source and the script block's type. 432 // block's source and the script block's type.
433 // Note: This is where the script is compiled and actually executed. 433 // Note: This is where the script is compiled and actually executed.
434 frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus, co mpilationFinishTime); 434 frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus, co mpilationFinishTime);
435 435
436 if (isHTMLScriptLoader(m_element)) { 436 if (isHTMLScriptLoader(m_element)) {
437 ASSERT(contextDocument->currentScript() == m_element); 437 DCHECK(contextDocument->currentScript() == m_element);
438 contextDocument->popCurrentScript(); 438 contextDocument->popCurrentScript();
439 } 439 }
440 440
441 return true; 441 return true;
442 } 442 }
443 443
444 void ScriptLoader::execute() 444 void ScriptLoader::execute()
445 { 445 {
446 ASSERT(!m_willBeParserExecuted); 446 DCHECK(!m_willBeParserExecuted);
447 ASSERT(m_pendingScript->resource()); 447 DCHECK(m_pendingScript->resource());
448 bool errorOccurred = false; 448 bool errorOccurred = false;
449 ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred); 449 ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred);
450 RawPtr<Element> element = m_pendingScript->releaseElementAndClear(); 450 RawPtr<Element> element = m_pendingScript->releaseElementAndClear();
451 ALLOW_UNUSED_LOCAL(element); 451 ALLOW_UNUSED_LOCAL(element);
452 if (errorOccurred) { 452 if (errorOccurred) {
453 dispatchErrorEvent(); 453 dispatchErrorEvent();
454 } else if (!m_resource->wasCanceled()) { 454 } else if (!m_resource->wasCanceled()) {
455 if (executeScript(source)) 455 if (executeScript(source))
456 dispatchLoadEvent(); 456 dispatchLoadEvent();
457 else 457 else
458 dispatchErrorEvent(); 458 dispatchErrorEvent();
459 } 459 }
460 m_resource = nullptr; 460 m_resource = nullptr;
461 } 461 }
462 462
463 void ScriptLoader::notifyFinished(Resource* resource) 463 void ScriptLoader::notifyFinished(Resource* resource)
464 { 464 {
465 ASSERT(!m_willBeParserExecuted); 465 DCHECK(!m_willBeParserExecuted);
466 466
467 RawPtr<Document> elementDocument(m_element->document()); 467 RawPtr<Document> elementDocument(m_element->document());
468 RawPtr<Document> contextDocument = elementDocument->contextDocument().get(); 468 RawPtr<Document> contextDocument = elementDocument->contextDocument().get();
469 if (!contextDocument) 469 if (!contextDocument)
470 return; 470 return;
471 471
472 ASSERT_UNUSED(resource, resource == m_resource); 472 ASSERT_UNUSED(resource, resource == m_resource);
473 473
474 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner:: IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION; 474 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner:: IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION;
475 if (m_resource->errorOccurred()) { 475 if (m_resource->errorOccurred()) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if (isHTMLScriptLoader(element)) 523 if (isHTMLScriptLoader(element))
524 return toHTMLScriptElement(element)->loader(); 524 return toHTMLScriptElement(element)->loader();
525 525
526 if (isSVGScriptLoader(element)) 526 if (isSVGScriptLoader(element))
527 return toSVGScriptElement(element)->loader(); 527 return toSVGScriptElement(element)->loader();
528 528
529 return 0; 529 return 0;
530 } 530 }
531 531
532 } // namespace blink 532 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/RemoteSecurityContext.cpp ('k') | third_party/WebKit/Source/core/dom/ScriptRunner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698