Chromium Code Reviews| Index: Source/core/dom/Document.cpp |
| diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
| index 750f73b6455e2990f556896849a4fa594e0ae5ad..c266985e444fd5cd7e42e4af714d0c30b2a5f873 100644 |
| --- a/Source/core/dom/Document.cpp |
| +++ b/Source/core/dom/Document.cpp |
| @@ -480,11 +480,13 @@ Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC |
| provideContextFeaturesToDocumentFrom(*this, *m_frame->page()); |
| m_fetcher = m_frame->loader().documentLoader()->fetcher(); |
| - } |
| - |
| - if (!m_fetcher) |
| + FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this); |
| + } else if (m_importsController) { |
| m_fetcher = FrameFetchContext::createContextAndFetcher(nullptr); |
| - static_cast<FrameFetchContext&>(m_fetcher->context()).setDocument(this); |
| + FrameFetchContext::provideDocumentToContext(m_fetcher->context(), this); |
| + } else { |
| + m_fetcher = ResourceFetcher::create(nullptr); |
| + } |
| // We depend on the url getting immediately set in subframes, but we |
| // also depend on the url NOT getting immediately set in opened windows. |
| @@ -574,13 +576,6 @@ Document::~Document() |
| if (m_elemSheet) |
| m_elemSheet->clearOwnerNode(); |
| - // It's possible for multiple Documents to end up referencing the same ResourceFetcher (e.g., SVGImages |
| - // load the initial empty document and the SVGDocument with the same DocumentLoader). |
| - FrameFetchContext& context = static_cast<FrameFetchContext&>(m_fetcher->context()); |
| - if (context.document() == this) |
| - context.setDocument(nullptr); |
| - m_fetcher.clear(); |
| - |
| // We must call clearRareData() here since a Document class inherits TreeScope |
| // as well as Node. See a comment on TreeScope.h for the reason. |
| if (hasRareData()) |
| @@ -836,6 +831,8 @@ void Document::setImportsController(HTMLImportsController* controller) |
| { |
| ASSERT(!m_importsController || !controller); |
| m_importsController = controller; |
| + if (!m_importsController) |
| + m_fetcher->clearContext(); |
| } |
| HTMLImportLoader* Document::importLoader() const |
| @@ -2140,6 +2137,16 @@ void Document::detach(const AttachContext& context) |
| frameHost()->eventHandlerRegistry().documentDetached(*this); |
| + // If this Document is associated with a live DocumentLoader, the |
| + // DocumentLoader will take care of clearing the FetchContext. Deferring |
| + // to the DocumentLoader when possible also prevents prematurely clearing |
| + // the context in the case where multiple Documents end up associated with |
| + // a single DocumentLoader (e.g., navigating to a javascript: url). |
| + if (!loader()) |
| + m_fetcher->clearContext(); |
| + else if (m_importsController) |
|
haraken
2015/03/27 11:01:33
Why is this 'else if', not 'if'?
Nate Chapin
2015/04/02 20:22:06
It should be if(). I was experimented and forgot t
|
| + HTMLImportsController::removeFrom(*this); |
| + |
| // This is required, as our LocalFrame might delete itself as soon as it detaches |
| // us. However, this violates Node::detach() semantics, as it's never |
| // possible to re-attach. Eventually Document::detach() should be renamed, |