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

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentLoader.cpp

Issue 1910153002: Reland of DocumentLoader should commit the load before creating a DocumentWriter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 444 }
445 DocumentInit init(owner, url(), m_frame); 445 DocumentInit init(owner, url(), m_frame);
446 init.withNewRegistrationContext(); 446 init.withNewRegistrationContext();
447 m_frame->loader().clear(); 447 m_frame->loader().clear();
448 ASSERT(m_frame->page()); 448 ASSERT(m_frame->page());
449 449
450 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; 450 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing;
451 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || !Document::threadedParsingEnabledForTesting()) 451 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || !Document::threadedParsingEnabledForTesting())
452 parsingPolicy = ForceSynchronousParsing; 452 parsingPolicy = ForceSynchronousParsing;
453 453
454 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy); 454 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy, o verridingURL);
455 m_writer->setDocumentWasLoadedAsPartOfNavigation(); 455 m_writer->setDocumentWasLoadedAsPartOfNavigation();
456
457 // This should be set before receivedFirstData().
458 if (!overridingURL.isEmpty())
459 m_frame->document()->setBaseURLOverride(overridingURL);
460
461 // Call receivedFirstData() exactly once per load.
462 frameLoader()->receivedFirstData();
463 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField(HTTPN ames::Refresh), Document::HttpRefreshFromHeader); 456 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField(HTTPN ames::Refresh), Document::HttpRefreshFromHeader);
464 } 457 }
465 458
466 void DocumentLoader::commitData(const char* bytes, size_t length) 459 void DocumentLoader::commitData(const char* bytes, size_t length)
467 { 460 {
468 ASSERT(m_state < MainResourceDone); 461 ASSERT(m_state < MainResourceDone);
469 ensureWriter(m_response.mimeType()); 462 ensureWriter(m_response.mimeType());
470 463
471 // This can happen if document.close() is called by an event handler while 464 // This can happen if document.close() is called by an event handler while
472 // there's still pending incoming data. 465 // there's still pending incoming data.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 m_mainResource->addClient(this); 646 m_mainResource->addClient(this);
654 } 647 }
655 648
656 void DocumentLoader::endWriting(DocumentWriter* writer) 649 void DocumentLoader::endWriting(DocumentWriter* writer)
657 { 650 {
658 ASSERT_UNUSED(writer, m_writer == writer); 651 ASSERT_UNUSED(writer, m_writer == writer);
659 m_writer->end(); 652 m_writer->end();
660 m_writer.clear(); 653 m_writer.clear();
661 } 654 }
662 655
663 DocumentWriter* DocumentLoader::createWriterFor(const DocumentInit& init, const AtomicString& mimeType, const AtomicString& encoding, bool dispatch, ParserSynch ronizationPolicy parsingPolicy) 656 DocumentWriter* DocumentLoader::createWriterFor(const DocumentInit& init, const AtomicString& mimeType, const AtomicString& encoding, bool dispatchWindowObjectA vailable, ParserSynchronizationPolicy parsingPolicy, const KURL& overridingURL)
664 { 657 {
665 LocalFrame* frame = init.frame(); 658 LocalFrame* frame = init.frame();
666 659
667 ASSERT(!frame->document() || !frame->document()->isActive()); 660 ASSERT(!frame->document() || !frame->document()->isActive());
668 ASSERT(frame->tree().childCount() == 0); 661 ASSERT(frame->tree().childCount() == 0);
669 662
670 if (!init.shouldReuseDefaultView()) 663 if (!init.shouldReuseDefaultView())
671 frame->setDOMWindow(LocalDOMWindow::create(*frame)); 664 frame->setDOMWindow(LocalDOMWindow::create(*frame));
672 665
673 Document* document = frame->localDOMWindow()->installNewDocument(mimeType, i nit); 666 Document* document = frame->localDOMWindow()->installNewDocument(mimeType, i nit);
674 667
675 frame->loader().didBeginDocument(dispatch); 668 // This should be set before receivedFirstData().
669 if (!overridingURL.isEmpty())
670 frame->document()->setBaseURLOverride(overridingURL);
671
672 frame->loader().didInstallNewDocument(dispatchWindowObjectAvailable);
673
674 // This must be called before DocumentWriter is created, otherwise HTML pars er
675 // will use stale values from HTMLParserOption.
676 if (!dispatchWindowObjectAvailable)
677 frame->loader().receivedFirstData();
678
679 frame->loader().didBeginDocument();
676 680
677 return DocumentWriter::create(document, parsingPolicy, mimeType, encoding); 681 return DocumentWriter::create(document, parsingPolicy, mimeType, encoding);
678 } 682 }
679 683
680 const AtomicString& DocumentLoader::mimeType() const 684 const AtomicString& DocumentLoader::mimeType() const
681 { 685 {
682 if (m_writer) 686 if (m_writer)
683 return m_writer->mimeType(); 687 return m_writer->mimeType();
684 return m_response.mimeType(); 688 return m_response.mimeType();
685 } 689 }
686 690
687 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L() 691 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L()
688 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source) 692 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source)
689 { 693 {
690 m_writer = createWriterFor(init, mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true, ForceSynchronousParsing); 694 m_writer = createWriterFor(init, mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true, ForceSynchronousParsing);
691 if (!source.isNull()) 695 if (!source.isNull())
692 m_writer->appendReplacingData(source); 696 m_writer->appendReplacingData(source);
693 endWriting(m_writer.get()); 697 endWriting(m_writer.get());
694 } 698 }
695 699
696 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 700 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
697 701
698 } // namespace blink 702 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentLoader.h ('k') | third_party/WebKit/Source/core/loader/FrameLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698