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

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

Issue 725593004: Prevent the load event from firing inside DOMContentLoaded (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month 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) 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 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 , m_compatibilityModeLocked(false) 456 , m_compatibilityModeLocked(false)
457 , m_executeScriptsWaitingForResourcesTimer(this, &Document::executeScriptsWa itingForResourcesTimerFired) 457 , m_executeScriptsWaitingForResourcesTimer(this, &Document::executeScriptsWa itingForResourcesTimerFired)
458 , m_hasAutofocused(false) 458 , m_hasAutofocused(false)
459 , m_clearFocusedElementTimer(this, &Document::clearFocusedElementTimerFired) 459 , m_clearFocusedElementTimer(this, &Document::clearFocusedElementTimerFired)
460 , m_domTreeVersion(++s_globalTreeVersion) 460 , m_domTreeVersion(++s_globalTreeVersion)
461 , m_listenerTypes(0) 461 , m_listenerTypes(0)
462 , m_mutationObserverTypes(0) 462 , m_mutationObserverTypes(0)
463 , m_visitedLinkState(VisitedLinkState::create(*this)) 463 , m_visitedLinkState(VisitedLinkState::create(*this))
464 , m_visuallyOrdered(false) 464 , m_visuallyOrdered(false)
465 , m_readyState(Complete) 465 , m_readyState(Complete)
466 , m_isParsing(false) 466 , m_parsingState(Done)
467 , m_gotoAnchorNeededAfterStylesheetsLoad(false) 467 , m_gotoAnchorNeededAfterStylesheetsLoad(false)
468 , m_containsValidityStyleRules(false) 468 , m_containsValidityStyleRules(false)
469 , m_updateFocusAppearanceRestoresSelection(false) 469 , m_updateFocusAppearanceRestoresSelection(false)
470 , m_containsPlugins(false) 470 , m_containsPlugins(false)
471 , m_ignoreDestructiveWriteCount(0) 471 , m_ignoreDestructiveWriteCount(0)
472 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController)) 472 , m_markers(adoptPtrWillBeNoop(new DocumentMarkerController))
473 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red) 473 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFi red)
474 , m_cssTarget(nullptr) 474 , m_cssTarget(nullptr)
475 , m_loadEventProgress(LoadEventNotRun) 475 , m_loadEventProgress(LoadEventNotRun)
476 , m_startTime(currentTime()) 476 , m_startTime(currentTime())
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 PassRefPtrWillBeRawPtr<DocumentParser> Document::implicitOpen() 2369 PassRefPtrWillBeRawPtr<DocumentParser> Document::implicitOpen()
2370 { 2370 {
2371 cancelParsing(); 2371 cancelParsing();
2372 2372
2373 removeChildren(); 2373 removeChildren();
2374 ASSERT(!m_focusedElement); 2374 ASSERT(!m_focusedElement);
2375 2375
2376 setCompatibilityMode(NoQuirksMode); 2376 setCompatibilityMode(NoQuirksMode);
2377 2377
2378 m_parser = createParser(); 2378 m_parser = createParser();
2379 setParsing(true); 2379 setParsingState(Parsing);
2380 setReadyState(Loading); 2380 setReadyState(Loading);
2381 2381
2382 return m_parser; 2382 return m_parser;
2383 } 2383 }
2384 2384
2385 HTMLElement* Document::body() const 2385 HTMLElement* Document::body() const
2386 { 2386 {
2387 if (!documentElement()) 2387 if (!documentElement())
2388 return 0; 2388 return 0;
2389 2389
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 { 2663 {
2664 if (m_loadEventProgress == BeforeUnloadEventInProgress) 2664 if (m_loadEventProgress == BeforeUnloadEventInProgress)
2665 return BeforeUnloadDismissal; 2665 return BeforeUnloadDismissal;
2666 if (m_loadEventProgress == PageHideInProgress) 2666 if (m_loadEventProgress == PageHideInProgress)
2667 return PageHideDismissal; 2667 return PageHideDismissal;
2668 if (m_loadEventProgress == UnloadEventInProgress) 2668 if (m_loadEventProgress == UnloadEventInProgress)
2669 return UnloadDismissal; 2669 return UnloadDismissal;
2670 return NoDismissal; 2670 return NoDismissal;
2671 } 2671 }
2672 2672
2673 void Document::setParsing(bool b) 2673 void Document::setParsingState(ParsingState parsingState)
2674 { 2674 {
2675 m_isParsing = b; 2675 m_parsingState = parsingState;
2676 2676
2677 if (m_isParsing && !m_elementDataCache) 2677 if (m_parsingState == Parsing && !m_elementDataCache)
sof 2014/11/14 21:34:02 Use parsing() instead?
Nate Chapin 2014/11/14 22:05:24 Done.
2678 m_elementDataCache = ElementDataCache::create(); 2678 m_elementDataCache = ElementDataCache::create();
2679 } 2679 }
2680 2680
2681 bool Document::shouldScheduleLayout() const 2681 bool Document::shouldScheduleLayout() const
2682 { 2682 {
2683 // This function will only be called when FrameView thinks a layout is neede d. 2683 // This function will only be called when FrameView thinks a layout is neede d.
2684 // This enforces a couple extra rules. 2684 // This enforces a couple extra rules.
2685 // 2685 //
2686 // (a) Only schedule a layout once the stylesheets are loaded. 2686 // (a) Only schedule a layout once the stylesheets are loaded.
2687 // (b) Only schedule layout once we have a body element. 2687 // (b) Only schedule layout once we have a body element.
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
4423 4423
4424 void Document::applyXSLTransform(ProcessingInstruction* pi) 4424 void Document::applyXSLTransform(ProcessingInstruction* pi)
4425 { 4425 {
4426 ASSERT(!pi->isLoading()); 4426 ASSERT(!pi->isLoading());
4427 UseCounter::count(*this, UseCounter::XSLProcessingInstruction); 4427 UseCounter::count(*this, UseCounter::XSLProcessingInstruction);
4428 RefPtrWillBeRawPtr<XSLTProcessor> processor = XSLTProcessor::create(*this); 4428 RefPtrWillBeRawPtr<XSLTProcessor> processor = XSLTProcessor::create(*this);
4429 processor->setXSLStyleSheet(toXSLStyleSheet(pi->sheet())); 4429 processor->setXSLStyleSheet(toXSLStyleSheet(pi->sheet()));
4430 String resultMIMEType; 4430 String resultMIMEType;
4431 String newSource; 4431 String newSource;
4432 String resultEncoding; 4432 String resultEncoding;
4433 setParsing(true); 4433 setParsingState(Parsing);
4434 if (!processor->transformToString(this, resultMIMEType, newSource, resultEnc oding)) { 4434 if (!processor->transformToString(this, resultMIMEType, newSource, resultEnc oding)) {
4435 setParsing(false); 4435 setParsingState(Done);
4436 return; 4436 return;
4437 } 4437 }
4438 // FIXME: If the transform failed we should probably report an error (like M ozilla does). 4438 // FIXME: If the transform failed we should probably report an error (like M ozilla does).
4439 LocalFrame* ownerFrame = frame(); 4439 LocalFrame* ownerFrame = frame();
4440 processor->createDocumentFromSource(newSource, resultEncoding, resultMIMETyp e, this, ownerFrame); 4440 processor->createDocumentFromSource(newSource, resultEncoding, resultMIMETyp e, this, ownerFrame);
4441 InspectorInstrumentation::frameDocumentUpdated(ownerFrame); 4441 InspectorInstrumentation::frameDocumentUpdated(ownerFrame);
4442 setParsing(false); 4442 setParsingState(Done);
4443 } 4443 }
4444 4444
4445 void Document::setTransformSource(PassOwnPtr<TransformSource> source) 4445 void Document::setTransformSource(PassOwnPtr<TransformSource> source)
4446 { 4446 {
4447 m_transformSource = source; 4447 m_transformSource = source;
4448 } 4448 }
4449 4449
4450 void Document::setDesignMode(InheritedBool value) 4450 void Document::setDesignMode(InheritedBool value)
4451 { 4451 {
4452 m_designMode = value; 4452 m_designMode = value;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4617 4617
4618 PassRefPtrWillBeRawPtr<DocumentNameCollection> Document::documentNamedItems(cons t AtomicString& name) 4618 PassRefPtrWillBeRawPtr<DocumentNameCollection> Document::documentNamedItems(cons t AtomicString& name)
4619 { 4619 {
4620 return ensureCachedCollection<DocumentNameCollection>(DocumentNamedItems, na me); 4620 return ensureCachedCollection<DocumentNameCollection>(DocumentNamedItems, na me);
4621 } 4621 }
4622 4622
4623 void Document::finishedParsing() 4623 void Document::finishedParsing()
4624 { 4624 {
4625 ASSERT(!scriptableDocumentParser() || !m_parser->isParsing()); 4625 ASSERT(!scriptableDocumentParser() || !m_parser->isParsing());
4626 ASSERT(!scriptableDocumentParser() || m_readyState != Loading); 4626 ASSERT(!scriptableDocumentParser() || m_readyState != Loading);
4627 setParsing(false); 4627 setParsingState(InDOMContentLoaded);
4628 if (!m_documentTiming.domContentLoadedEventStart) 4628 if (!m_documentTiming.domContentLoadedEventStart)
4629 m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTim e(); 4629 m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTim e();
4630 dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded)); 4630 dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded));
4631 if (!m_documentTiming.domContentLoadedEventEnd) 4631 if (!m_documentTiming.domContentLoadedEventEnd)
4632 m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime( ); 4632 m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime( );
4633 setParsingState(Done);
4633 4634
4634 // The loader's finishedParsing() method may invoke script that causes this object to 4635 // The loader's finishedParsing() method may invoke script that causes this object to
4635 // be dereferenced (when this document is in an iframe and the onload causes the iframe's src to change). 4636 // be dereferenced (when this document is in an iframe and the onload causes the iframe's src to change).
4636 // Keep it alive until we are done. 4637 // Keep it alive until we are done.
4637 RefPtrWillBeRawPtr<Document> protect(this); 4638 RefPtrWillBeRawPtr<Document> protect(this);
4638 4639
4639 if (RefPtrWillBeRawPtr<LocalFrame> frame = this->frame()) { 4640 if (RefPtrWillBeRawPtr<LocalFrame> frame = this->frame()) {
4640 // Don't update the render tree if we haven't requested the main resourc e yet to avoid 4641 // Don't update the render tree if we haven't requested the main resourc e yet to avoid
4641 // adding extra latency. Note that the first render tree update can be e xpensive since it 4642 // adding extra latency. Note that the first render tree update can be e xpensive since it
4642 // triggers the parsing of the default stylesheets which are compiled-in . 4643 // triggers the parsing of the default stylesheets which are compiled-in .
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
5848 #ifndef NDEBUG 5849 #ifndef NDEBUG
5849 using namespace blink; 5850 using namespace blink;
5850 void showLiveDocumentInstances() 5851 void showLiveDocumentInstances()
5851 { 5852 {
5852 WeakDocumentSet& set = liveDocumentSet(); 5853 WeakDocumentSet& set = liveDocumentSet();
5853 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5854 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5854 for (Document* document : set) 5855 for (Document* document : set)
5855 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5856 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5856 } 5857 }
5857 #endif 5858 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698