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

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

Issue 262093006: Oilpan: Make the Node hierarchy RefCountedGarbageCollected instead of TreeShared. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Another build fix. Created 6 years, 7 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) 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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 , m_writeRecursionDepth(0) 472 , m_writeRecursionDepth(0)
473 , m_taskRunner(MainThreadTaskRunner::create(this)) 473 , m_taskRunner(MainThreadTaskRunner::create(this))
474 , m_registrationContext(initializer.registrationContext(this)) 474 , m_registrationContext(initializer.registrationContext(this))
475 , m_elementDataCacheClearTimer(this, &Document::elementDataCacheClearTimerFi red) 475 , m_elementDataCacheClearTimer(this, &Document::elementDataCacheClearTimerFi red)
476 #ifndef NDEBUG 476 #ifndef NDEBUG
477 , m_didDispatchViewportPropertiesChanged(false) 477 , m_didDispatchViewportPropertiesChanged(false)
478 #endif 478 #endif
479 , m_animationClock(AnimationClock::create()) 479 , m_animationClock(AnimationClock::create())
480 , m_timeline(DocumentTimeline::create(this)) 480 , m_timeline(DocumentTimeline::create(this))
481 , m_transitionTimeline(TransitionTimeline::create(this)) 481 , m_transitionTimeline(TransitionTimeline::create(this))
482 , m_templateDocumentHost(0) 482 , m_templateDocumentHost(nullptr)
483 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired) 483 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired)
484 , m_hasViewportUnits(false) 484 , m_hasViewportUnits(false)
485 , m_styleRecalcElementCounter(0) 485 , m_styleRecalcElementCounter(0)
486 { 486 {
487 setClient(this); 487 setClient(this);
488 ScriptWrappable::init(this); 488 ScriptWrappable::init(this);
489 489
490 if (m_frame) { 490 if (m_frame) {
491 ASSERT(m_frame->page()); 491 ASSERT(m_frame->page());
492 provideContextFeaturesToDocumentFrom(*this, *m_frame->page()); 492 provideContextFeaturesToDocumentFrom(*this, *m_frame->page());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 ASSERT(!renderView()); 527 ASSERT(!renderView());
528 ASSERT(m_ranges.isEmpty()); 528 ASSERT(m_ranges.isEmpty());
529 ASSERT(!parentTreeScope()); 529 ASSERT(!parentTreeScope());
530 #if !ENABLE(OILPAN) 530 #if !ENABLE(OILPAN)
531 ASSERT(!hasGuardRefCount()); 531 ASSERT(!hasGuardRefCount());
532 // With Oilpan, either the document outlives the visibility observers 532 // With Oilpan, either the document outlives the visibility observers
533 // or the visibility observers and the document die in the same GC round. 533 // or the visibility observers and the document die in the same GC round.
534 // When they die in the same GC round, the list of visibility observers 534 // When they die in the same GC round, the list of visibility observers
535 // will not be empty on Document destruction. 535 // will not be empty on Document destruction.
536 ASSERT(m_visibilityObservers.isEmpty()); 536 ASSERT(m_visibilityObservers.isEmpty());
537 #endif
538 537
539 if (m_templateDocument) 538 if (m_templateDocument)
540 m_templateDocument->m_templateDocumentHost = 0; // balanced in ensureTem plateDocument(). 539 m_templateDocument->m_templateDocumentHost = nullptr; // balanced in ens ureTemplateDocument().
540 #endif
541 541
542 m_scriptRunner.clear(); 542 m_scriptRunner.clear();
543 543
544 // FIXME: Oilpan: Not removing event listeners here also means that we do
545 // not notify the inspector instrumentation that the event listeners are
546 // gone. The Document and all the nodes in the document are gone, so maybe
547 // that is OK?
548 #if !ENABLE(OILPAN)
544 removeAllEventListenersRecursively(); 549 removeAllEventListenersRecursively();
550 #endif
545 551
546 // Currently we believe that Document can never outlive the parser. 552 // Currently we believe that Document can never outlive the parser.
547 // Although the Document may be replaced synchronously, DocumentParsers 553 // Although the Document may be replaced synchronously, DocumentParsers
548 // generally keep at least one reference to an Element which would in turn 554 // generally keep at least one reference to an Element which would in turn
549 // has a reference to the Document. If you hit this ASSERT, then that 555 // has a reference to the Document. If you hit this ASSERT, then that
550 // assumption is wrong. DocumentParser::detach() should ensure that even 556 // assumption is wrong. DocumentParser::detach() should ensure that even
551 // if the DocumentParser outlives the Document it won't cause badness. 557 // if the DocumentParser outlives the Document it won't cause badness.
552 ASSERT(!m_parser || m_parser->refCount() == 1); 558 ASSERT(!m_parser || m_parser->refCount() == 1);
553 detachParser(); 559 detachParser();
554 560
555 if (this == topDocument()) 561 if (this == topDocument())
556 clearAXObjectCache(); 562 clearAXObjectCache();
557 563
558 #if !ENABLE(OILPAN) 564 #if !ENABLE(OILPAN)
559 if (m_styleSheetList) 565 if (m_styleSheetList)
560 m_styleSheetList->detachFromDocument(); 566 m_styleSheetList->detachFromDocument();
561 #endif 567 #endif
562 568
563 if (m_importsController) { 569 if (m_importsController) {
564 m_importsController->wasDetachedFrom(*this); 570 m_importsController->wasDetachedFrom(*this);
565 m_importsController = 0; 571 m_importsController = 0;
566 } 572 }
567 573
568 m_timeline->detachFromDocument(); 574 m_timeline->detachFromDocument();
569 m_transitionTimeline->detachFromDocument(); 575 m_transitionTimeline->detachFromDocument();
570 576
577 #if !ENABLE(OILPAN)
571 // We need to destroy CSSFontSelector before destroying m_fetcher. 578 // We need to destroy CSSFontSelector before destroying m_fetcher.
572 if (m_styleEngine) 579 if (m_styleEngine)
573 m_styleEngine->detachFromDocument(); 580 m_styleEngine->detachFromDocument();
574 581
575 #if !ENABLE(OILPAN)
576 if (m_elemSheet) 582 if (m_elemSheet)
577 m_elemSheet->clearOwnerNode(); 583 m_elemSheet->clearOwnerNode();
578 #endif 584 #endif
579 585
580 // It's possible for multiple Documents to end up referencing the same Resou rceFetcher (e.g., SVGImages 586 // It's possible for multiple Documents to end up referencing the same Resou rceFetcher (e.g., SVGImages
581 // load the initial empty document and the SVGDocument with the same Documen tLoader). 587 // load the initial empty document and the SVGDocument with the same Documen tLoader).
582 if (m_fetcher->document() == this) 588 if (m_fetcher->document() == this)
583 m_fetcher->setDocument(0); 589 m_fetcher->setDocument(0);
584 m_fetcher.clear(); 590 m_fetcher.clear();
585 591
586 // We must call clearRareData() here since a Document class inherits TreeSco pe 592 // We must call clearRareData() here since a Document class inherits TreeSco pe
587 // as well as Node. See a comment on TreeScope.h for the reason. 593 // as well as Node. See a comment on TreeScope.h for the reason.
588 if (hasRareData()) 594 if (hasRareData())
589 clearRareData(); 595 clearRareData();
590 596
591 ASSERT(!m_listsInvalidatedAtDocument.size()); 597 ASSERT(!m_listsInvalidatedAtDocument.size());
592 598
593 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++) 599 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++)
594 ASSERT(!m_nodeListCounts[i]); 600 ASSERT(!m_nodeListCounts[i]);
595 601
596 setClient(0); 602 setClient(0);
597 603
598 InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter); 604 InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter);
599 } 605 }
600 606
601 void Document::dispose() 607 void Document::dispose()
602 { 608 {
609 #if !ENABLE(OILPAN)
603 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); 610 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
611
604 // We must make sure not to be retaining any of our children through 612 // We must make sure not to be retaining any of our children through
605 // these extra pointers or we will create a reference cycle. 613 // these extra pointers or we will create a reference cycle.
606 m_docType = nullptr; 614 m_docType = nullptr;
607 m_focusedElement = nullptr; 615 m_focusedElement = nullptr;
608 m_hoverNode = nullptr; 616 m_hoverNode = nullptr;
609 m_activeHoverElement = nullptr; 617 m_activeHoverElement = nullptr;
610 m_titleElement = nullptr; 618 m_titleElement = nullptr;
611 m_documentElement = nullptr; 619 m_documentElement = nullptr;
612 m_contextFeatures = ContextFeatures::defaultSwitch(); 620 m_contextFeatures = ContextFeatures::defaultSwitch();
613 m_userActionElements.documentDidRemoveLastRef(); 621 m_userActionElements.documentDidRemoveLastRef();
614 m_associatedFormControls.clear(); 622 m_associatedFormControls.clear();
623 #endif
615 624
616 detachParser(); 625 detachParser();
617 626
618 m_registrationContext.clear(); 627 m_registrationContext.clear();
619 628
620 if (m_importsController) { 629 if (m_importsController) {
621 m_importsController->wasDetachedFrom(*this); 630 m_importsController->wasDetachedFrom(*this);
622 m_importsController = 0; 631 m_importsController = 0;
623 } 632 }
624 633
634 #if !ENABLE(OILPAN)
625 // removeDetachedChildren() doesn't always unregister IDs, 635 // removeDetachedChildren() doesn't always unregister IDs,
626 // so tear down scope information upfront to avoid having stale references i n the map. 636 // so tear down scope information upfront to avoid having stale references i n the map.
627 destroyTreeScopeData(); 637 destroyTreeScopeData();
638
628 removeDetachedChildren(); 639 removeDetachedChildren();
640 #endif
641
629 // removeDetachedChildren() can access FormController. 642 // removeDetachedChildren() can access FormController.
630 m_formController.clear(); 643 m_formController.clear();
631 644
645 #if !ENABLE(OILPAN)
632 m_markers->clear(); 646 m_markers->clear();
633 647
634 m_cssCanvasElements.clear(); 648 m_cssCanvasElements.clear();
649 #endif
635 650
636 // FIXME: consider using ActiveDOMObject. 651 // FIXME: consider using ActiveDOMObject.
637 if (m_scriptedAnimationController) 652 if (m_scriptedAnimationController)
638 m_scriptedAnimationController->clearDocumentPointer(); 653 m_scriptedAnimationController->clearDocumentPointer();
639 m_scriptedAnimationController.clear(); 654 m_scriptedAnimationController.clear();
640 655
641 if (svgExtensions()) 656 if (svgExtensions())
642 accessSVGExtensions().pauseAnimations(); 657 accessSVGExtensions().pauseAnimations();
643 658
644 m_lifecycle.advanceTo(DocumentLifecycle::Disposed); 659 m_lifecycle.advanceTo(DocumentLifecycle::Disposed);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 1370
1356 void Document::setTitle(const String& title) 1371 void Document::setTitle(const String& title)
1357 { 1372 {
1358 // Title set by JavaScript -- overrides any title elements. 1373 // Title set by JavaScript -- overrides any title elements.
1359 m_titleSetExplicitly = true; 1374 m_titleSetExplicitly = true;
1360 if (!isHTMLDocument() && !isXHTMLDocument()) 1375 if (!isHTMLDocument() && !isXHTMLDocument())
1361 m_titleElement = nullptr; 1376 m_titleElement = nullptr;
1362 else if (!m_titleElement) { 1377 else if (!m_titleElement) {
1363 if (HTMLElement* headElement = head()) { 1378 if (HTMLElement* headElement = head()) {
1364 m_titleElement = HTMLTitleElement::create(*this); 1379 m_titleElement = HTMLTitleElement::create(*this);
1365 headElement->appendChild(m_titleElement); 1380 headElement->appendChild(m_titleElement.get());
1366 } 1381 }
1367 } 1382 }
1368 1383
1369 if (isHTMLTitleElement(m_titleElement)) 1384 if (isHTMLTitleElement(m_titleElement))
1370 toHTMLTitleElement(m_titleElement)->setText(title); 1385 toHTMLTitleElement(m_titleElement)->setText(title);
1371 else 1386 else
1372 updateTitle(title); 1387 updateTitle(title);
1373 } 1388 }
1374 1389
1375 void Document::setTitleElement(const String& title, Element* titleElement) 1390 void Document::setTitleElement(const String& title, Element* titleElement)
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 // possible to re-attach. Eventually Document::detach() should be renamed, 2240 // possible to re-attach. Eventually Document::detach() should be renamed,
2226 // or this setting of the frame to 0 could be made explicit in each of the 2241 // or this setting of the frame to 0 could be made explicit in each of the
2227 // callers of Document::detach(). 2242 // callers of Document::detach().
2228 m_frame = 0; 2243 m_frame = 0;
2229 2244
2230 if (m_mediaQueryMatcher) 2245 if (m_mediaQueryMatcher)
2231 m_mediaQueryMatcher->documentDestroyed(); 2246 m_mediaQueryMatcher->documentDestroyed();
2232 2247
2233 lifecycleNotifier().notifyDocumentWasDetached(); 2248 lifecycleNotifier().notifyDocumentWasDetached();
2234 m_lifecycle.advanceTo(DocumentLifecycle::Stopped); 2249 m_lifecycle.advanceTo(DocumentLifecycle::Stopped);
2250 #if ENABLE(OILPAN)
2251 dispose();
haraken 2014/05/06 15:59:42 I do agree with you that Document::dispose() shoul
Mads Ager (chromium) 2014/05/07 12:13:16 Yes, done.
2252 #endif
2235 } 2253 }
2236 2254
2237 void Document::prepareForDestruction() 2255 void Document::prepareForDestruction()
2238 { 2256 {
2239 m_markers->prepareForDestruction(); 2257 m_markers->prepareForDestruction();
2240 disconnectDescendantFrames(); 2258 disconnectDescendantFrames();
2241 2259
2242 // The process of disconnecting descendant frames could have already detache d us. 2260 // The process of disconnecting descendant frames could have already detache d us.
2243 if (!isActive()) 2261 if (!isActive())
2244 return; 2262 return;
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
3527 if (newFocusedElement && (newFocusedElement->document() != this)) 3545 if (newFocusedElement && (newFocusedElement->document() != this))
3528 return true; 3546 return true;
3529 3547
3530 if (NodeChildRemovalTracker::isBeingRemoved(newFocusedElement.get())) 3548 if (NodeChildRemovalTracker::isBeingRemoved(newFocusedElement.get()))
3531 return true; 3549 return true;
3532 3550
3533 if (m_focusedElement == newFocusedElement) 3551 if (m_focusedElement == newFocusedElement)
3534 return true; 3552 return true;
3535 3553
3536 bool focusChangeBlocked = false; 3554 bool focusChangeBlocked = false;
3537 RefPtr<Element> oldFocusedElement = m_focusedElement; 3555 RefPtrWillBeRawPtr<Element> oldFocusedElement = m_focusedElement;
3538 m_focusedElement = nullptr; 3556 m_focusedElement = nullptr;
3539 3557
3540 // Remove focus from the existing focus node (if any) 3558 // Remove focus from the existing focus node (if any)
3541 if (oldFocusedElement) { 3559 if (oldFocusedElement) {
3542 ASSERT(!oldFocusedElement->inDetach()); 3560 ASSERT(!oldFocusedElement->inDetach());
3543 3561
3544 if (oldFocusedElement->active()) 3562 if (oldFocusedElement->active())
3545 oldFocusedElement->setActive(false); 3563 oldFocusedElement->setActive(false);
3546 3564
3547 oldFocusedElement->setFocus(false); 3565 oldFocusedElement->setFocus(false);
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
4868 is2d = true; 4886 is2d = true;
4869 context2d = toCanvasRenderingContext2D(context); 4887 context2d = toCanvasRenderingContext2D(context);
4870 } else if (context->is3d()) { 4888 } else if (context->is3d()) {
4871 is3d = true; 4889 is3d = true;
4872 context3d = toWebGLRenderingContext(context); 4890 context3d = toWebGLRenderingContext(context);
4873 } 4891 }
4874 } 4892 }
4875 4893
4876 HTMLCanvasElement& Document::getCSSCanvasElement(const String& name) 4894 HTMLCanvasElement& Document::getCSSCanvasElement(const String& name)
4877 { 4895 {
4878 RefPtr<HTMLCanvasElement>& element = m_cssCanvasElements.add(name, nullptr). storedValue->value; 4896 RefPtrWillBeMember<HTMLCanvasElement>& element = m_cssCanvasElements.add(nam e, nullptr).storedValue->value;
4879 if (!element) { 4897 if (!element) {
4880 element = HTMLCanvasElement::create(*this); 4898 element = HTMLCanvasElement::create(*this);
4881 element->setAccelerationDisabled(true); 4899 element->setAccelerationDisabled(true);
4882 } 4900 }
4883 return *element; 4901 return *element;
4884 } 4902 }
4885 4903
4886 void Document::initDNSPrefetch() 4904 void Document::initDNSPrefetch()
4887 { 4905 {
4888 Settings* settings = this->settings(); 4906 Settings* settings = this->settings();
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
5653 if (!visitor->isAlive(it->key)) 5671 if (!visitor->isAlive(it->key))
5654 deadNodes.append(it->key); 5672 deadNodes.append(it->key);
5655 } 5673 }
5656 for (unsigned i = 0; i < deadNodes.size(); ++i) 5674 for (unsigned i = 0; i < deadNodes.size(); ++i)
5657 didClearTouchEventHandlers(deadNodes[i]); 5675 didClearTouchEventHandlers(deadNodes[i]);
5658 } 5676 }
5659 } 5677 }
5660 5678
5661 void Document::trace(Visitor* visitor) 5679 void Document::trace(Visitor* visitor)
5662 { 5680 {
5681 visitor->trace(m_docType);
5682 visitor->trace(m_autofocusElement);
5683 visitor->trace(m_focusedElement);
5684 visitor->trace(m_hoverNode);
5685 visitor->trace(m_activeHoverElement);
5686 visitor->trace(m_documentElement);
5687 visitor->trace(m_titleElement);
5688 visitor->trace(m_currentScriptStack);
5689 visitor->trace(m_transformSourceDocument);
5690 visitor->trace(m_cssCanvasElements);
5691 visitor->trace(m_topLayerElements);
5692 visitor->trace(m_elemSheet);
5693 visitor->trace(m_styleEngine);
5663 visitor->trace(m_styleSheetList); 5694 visitor->trace(m_styleSheetList);
5664 visitor->trace(m_mediaQueryMatcher); 5695 visitor->trace(m_mediaQueryMatcher);
5696 visitor->trace(m_associatedFormControls);
5697 visitor->trace(m_templateDocument);
5698 visitor->trace(m_templateDocumentHost);
5665 visitor->trace(m_visibilityObservers); 5699 visitor->trace(m_visibilityObservers);
5666 visitor->trace(m_contextFeatures); 5700 visitor->trace(m_contextFeatures);
5701 visitor->trace(m_userActionElements);
5667 visitor->registerWeakMembers<Document, &Document::clearWeakMembers>(this); 5702 visitor->registerWeakMembers<Document, &Document::clearWeakMembers>(this);
5668 DocumentSupplementable::trace(visitor); 5703 DocumentSupplementable::trace(visitor);
5669 TreeScope::trace(visitor); 5704 TreeScope::trace(visitor);
5670 ContainerNode::trace(visitor); 5705 ContainerNode::trace(visitor);
5671 ExecutionContext::trace(visitor); 5706 ExecutionContext::trace(visitor);
5672 } 5707 }
5673 5708
5674 } // namespace WebCore 5709 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698