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

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

Issue 1035803002: Remove ResourceFetcher's access to a real FetchContext at frame detach time (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Moved ASSERT(!m_importsController) to #if !ENABLE(OILPAN) block Created 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/fetch/FetchContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired) 474 , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsT imerFired)
475 , m_hasViewportUnits(false) 475 , m_hasViewportUnits(false)
476 , m_styleRecalcElementCounter(0) 476 , m_styleRecalcElementCounter(0)
477 , m_parserSyncPolicy(AllowAsynchronousParsing) 477 , m_parserSyncPolicy(AllowAsynchronousParsing)
478 { 478 {
479 if (m_frame) { 479 if (m_frame) {
480 ASSERT(m_frame->page()); 480 ASSERT(m_frame->page());
481 provideContextFeaturesToDocumentFrom(*this, *m_frame->page()); 481 provideContextFeaturesToDocumentFrom(*this, *m_frame->page());
482 482
483 m_fetcher = m_frame->loader().documentLoader()->fetcher(); 483 m_fetcher = m_frame->loader().documentLoader()->fetcher();
484 FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this);
485 } else if (m_importsController) {
486 m_fetcher = FrameFetchContext::createContextAndFetcher(nullptr);
487 FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this);
488 } else {
489 m_fetcher = ResourceFetcher::create(nullptr);
484 } 490 }
485 491
486 if (!m_fetcher)
487 m_fetcher = FrameFetchContext::createContextAndFetcher(nullptr);
488 static_cast<FrameFetchContext&>(m_fetcher->context()).setDocument(this);
489
490 // We depend on the url getting immediately set in subframes, but we 492 // We depend on the url getting immediately set in subframes, but we
491 // also depend on the url NOT getting immediately set in opened windows. 493 // also depend on the url NOT getting immediately set in opened windows.
492 // See fast/dom/early-frame-url.html 494 // See fast/dom/early-frame-url.html
493 // and fast/dom/location-new-window-no-crash.html, respectively. 495 // and fast/dom/location-new-window-no-crash.html, respectively.
494 // FIXME: Can/should we unify this behavior? 496 // FIXME: Can/should we unify this behavior?
495 if (initializer.shouldSetURL()) 497 if (initializer.shouldSetURL())
496 setURL(initializer.url()); 498 setURL(initializer.url());
497 499
498 initSecurityContext(initializer); 500 initSecurityContext(initializer);
499 initDNSPrefetch(); 501 initDNSPrefetch();
(...skipping 23 matching lines...) Expand all
523 #endif 525 #endif
524 } 526 }
525 527
526 Document::~Document() 528 Document::~Document()
527 { 529 {
528 ASSERT(!layoutView()); 530 ASSERT(!layoutView());
529 ASSERT(!parentTreeScope()); 531 ASSERT(!parentTreeScope());
530 #if !ENABLE(OILPAN) 532 #if !ENABLE(OILPAN)
531 ASSERT(m_ranges.isEmpty()); 533 ASSERT(m_ranges.isEmpty());
532 ASSERT(!hasGuardRefCount()); 534 ASSERT(!hasGuardRefCount());
535 ASSERT(!m_importsController);
533 // With Oilpan, either the document outlives the visibility observers 536 // With Oilpan, either the document outlives the visibility observers
534 // or the visibility observers and the document die in the same GC round. 537 // or the visibility observers and the document die in the same GC round.
535 // When they die in the same GC round, the list of visibility observers 538 // When they die in the same GC round, the list of visibility observers
536 // will not be empty on Document destruction. 539 // will not be empty on Document destruction.
537 ASSERT(m_visibilityObservers.isEmpty()); 540 ASSERT(m_visibilityObservers.isEmpty());
538 541
539 if (m_templateDocument) 542 if (m_templateDocument)
540 m_templateDocument->m_templateDocumentHost = nullptr; // balanced in ens ureTemplateDocument(). 543 m_templateDocument->m_templateDocumentHost = nullptr; // balanced in ens ureTemplateDocument().
541 544
542 m_scriptRunner.clear(); 545 m_scriptRunner.clear();
(...skipping 14 matching lines...) Expand all
557 detachParser(); 560 detachParser();
558 #endif 561 #endif
559 562
560 if (this == &axObjectCacheOwner()) 563 if (this == &axObjectCacheOwner())
561 clearAXObjectCache(); 564 clearAXObjectCache();
562 565
563 #if !ENABLE(OILPAN) 566 #if !ENABLE(OILPAN)
564 if (m_styleSheetList) 567 if (m_styleSheetList)
565 m_styleSheetList->detachFromDocument(); 568 m_styleSheetList->detachFromDocument();
566 569
567 if (m_importsController)
568 HTMLImportsController::removeFrom(*this);
569
570 m_timeline->detachFromDocument(); 570 m_timeline->detachFromDocument();
571 571
572 // We need to destroy CSSFontSelector before destroying m_fetcher. 572 // We need to destroy CSSFontSelector before destroying m_fetcher.
573 m_styleEngine->detachFromDocument(); 573 m_styleEngine->detachFromDocument();
574 574
575 if (m_elemSheet) 575 if (m_elemSheet)
576 m_elemSheet->clearOwnerNode(); 576 m_elemSheet->clearOwnerNode();
577 577
578 // It's possible for multiple Documents to end up referencing the same Resou rceFetcher (e.g., SVGImages
579 // load the initial empty document and the SVGDocument with the same Documen tLoader).
580 FrameFetchContext& context = static_cast<FrameFetchContext&>(m_fetcher->cont ext());
581 if (context.document() == this)
582 context.setDocument(nullptr);
583 m_fetcher.clear();
584
585 // We must call clearRareData() here since a Document class inherits TreeSco pe 578 // We must call clearRareData() here since a Document class inherits TreeSco pe
586 // as well as Node. See a comment on TreeScope.h for the reason. 579 // as well as Node. See a comment on TreeScope.h for the reason.
587 if (hasRareData()) 580 if (hasRareData())
588 clearRareData(); 581 clearRareData();
589 582
590 ASSERT(m_listsInvalidatedAtDocument.isEmpty()); 583 ASSERT(m_listsInvalidatedAtDocument.isEmpty());
591 584
592 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); ++i) 585 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); ++i)
593 ASSERT(!m_nodeListCounts[i]); 586 ASSERT(!m_nodeListCounts[i]);
594 587
(...skipping 19 matching lines...) Expand all
614 m_titleElement = nullptr; 607 m_titleElement = nullptr;
615 m_documentElement = nullptr; 608 m_documentElement = nullptr;
616 m_contextFeatures = ContextFeatures::defaultSwitch(); 609 m_contextFeatures = ContextFeatures::defaultSwitch();
617 m_userActionElements.documentDidRemoveLastRef(); 610 m_userActionElements.documentDidRemoveLastRef();
618 m_associatedFormControls.clear(); 611 m_associatedFormControls.clear();
619 612
620 detachParser(); 613 detachParser();
621 614
622 m_registrationContext.clear(); 615 m_registrationContext.clear();
623 616
624 if (m_importsController)
625 HTMLImportsController::removeFrom(*this);
626
627 // removeDetachedChildren() doesn't always unregister IDs, 617 // removeDetachedChildren() doesn't always unregister IDs,
628 // so tear down scope information upfront to avoid having stale references i n the map. 618 // so tear down scope information upfront to avoid having stale references i n the map.
629 destroyTreeScopeData(); 619 destroyTreeScopeData();
630 620
631 removeDetachedChildren(); 621 removeDetachedChildren();
632 622
633 // removeDetachedChildren() can access FormController. 623 // removeDetachedChildren() can access FormController.
634 m_formController.clear(); 624 m_formController.clear();
635 625
636 m_markers->clear(); 626 m_markers->clear();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 { 815 {
826 if (!m_customElementMicrotaskRunQueue) 816 if (!m_customElementMicrotaskRunQueue)
827 m_customElementMicrotaskRunQueue = CustomElementMicrotaskRunQueue::creat e(); 817 m_customElementMicrotaskRunQueue = CustomElementMicrotaskRunQueue::creat e();
828 return m_customElementMicrotaskRunQueue.get(); 818 return m_customElementMicrotaskRunQueue.get();
829 } 819 }
830 820
831 void Document::setImportsController(HTMLImportsController* controller) 821 void Document::setImportsController(HTMLImportsController* controller)
832 { 822 {
833 ASSERT(!m_importsController || !controller); 823 ASSERT(!m_importsController || !controller);
834 m_importsController = controller; 824 m_importsController = controller;
825 if (!m_importsController)
826 m_fetcher->clearContext();
835 } 827 }
836 828
837 HTMLImportLoader* Document::importLoader() const 829 HTMLImportLoader* Document::importLoader() const
838 { 830 {
839 if (!m_importsController) 831 if (!m_importsController)
840 return 0; 832 return 0;
841 return m_importsController->loaderFor(*this); 833 return m_importsController->loaderFor(*this);
842 } 834 }
843 835
844 bool Document::haveImportsLoaded() const 836 bool Document::haveImportsLoaded() const
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 2121
2130 } 2122 }
2131 2123
2132 m_layoutView = 0; 2124 m_layoutView = 0;
2133 ContainerNode::detach(context); 2125 ContainerNode::detach(context);
2134 2126
2135 styleEngine().didDetach(); 2127 styleEngine().didDetach();
2136 2128
2137 frameHost()->eventHandlerRegistry().documentDetached(*this); 2129 frameHost()->eventHandlerRegistry().documentDetached(*this);
2138 2130
2131 // If this Document is associated with a live DocumentLoader, the
2132 // DocumentLoader will take care of clearing the FetchContext. Deferring
2133 // to the DocumentLoader when possible also prevents prematurely clearing
2134 // the context in the case where multiple Documents end up associated with
2135 // a single DocumentLoader (e.g., navigating to a javascript: url).
2136 if (!loader())
2137 m_fetcher->clearContext();
2138 // If this document is the master for an HTMLImportsController, sever that
2139 // relationship. This ensures that we don't leave import loads in flight,
2140 // thinking they should have access to a valid frame when they don't.
2141 if (m_importsController)
2142 HTMLImportsController::removeFrom(*this);
2143
2139 // This is required, as our LocalFrame might delete itself as soon as it det aches 2144 // This is required, as our LocalFrame might delete itself as soon as it det aches
2140 // us. However, this violates Node::detach() semantics, as it's never 2145 // us. However, this violates Node::detach() semantics, as it's never
2141 // possible to re-attach. Eventually Document::detach() should be renamed, 2146 // possible to re-attach. Eventually Document::detach() should be renamed,
2142 // or this setting of the frame to 0 could be made explicit in each of the 2147 // or this setting of the frame to 0 could be made explicit in each of the
2143 // callers of Document::detach(). 2148 // callers of Document::detach().
2144 m_frame = nullptr; 2149 m_frame = nullptr;
2145 2150
2146 if (m_mediaQueryMatcher) 2151 if (m_mediaQueryMatcher)
2147 m_mediaQueryMatcher->documentDetached(); 2152 m_mediaQueryMatcher->documentDetached();
2148 2153
(...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after
5699 #ifndef NDEBUG 5704 #ifndef NDEBUG
5700 using namespace blink; 5705 using namespace blink;
5701 void showLiveDocumentInstances() 5706 void showLiveDocumentInstances()
5702 { 5707 {
5703 WeakDocumentSet& set = liveDocumentSet(); 5708 WeakDocumentSet& set = liveDocumentSet();
5704 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5709 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5705 for (Document* document : set) 5710 for (Document* document : set)
5706 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5711 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5707 } 5712 }
5708 #endif 5713 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/fetch/FetchContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698