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

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

Issue 1685003002: Plumb the correct owner document through DocumentInit::m_owner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "wtf/TemporaryChange.h" 75 #include "wtf/TemporaryChange.h"
76 #include "wtf/text/WTFString.h" 76 #include "wtf/text/WTFString.h"
77 77
78 namespace blink { 78 namespace blink {
79 79
80 static bool isArchiveMIMEType(const String& mimeType) 80 static bool isArchiveMIMEType(const String& mimeType)
81 { 81 {
82 return equalIgnoringCase("multipart/related", mimeType); 82 return equalIgnoringCase("multipart/related", mimeType);
83 } 83 }
84 84
85 static bool shouldInheritSecurityOriginFromOwner(const KURL& url)
86 {
87 // https://html.spec.whatwg.org/multipage/browsers.html#origin
88 //
89 // If a Document is the initial "about:blank" document
90 // The origin and effective script origin of the Document are those it
91 // was assigned when its browsing context was created.
92 //
93 // Note: We generalize this to all "blank" URLs and invalid URLs because we
94 // treat all of these URLs as about:blank.
95 return url.isEmpty() || url.protocolIsAbout();
96 }
97
85 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData) 98 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData)
86 : m_frame(frame) 99 : m_frame(frame)
87 , m_fetcher(FrameFetchContext::createContextAndFetcher(this)) 100 , m_fetcher(FrameFetchContext::createContextAndFetcher(this))
88 , m_originalRequest(req) 101 , m_originalRequest(req)
89 , m_substituteData(substituteData) 102 , m_substituteData(substituteData)
90 , m_request(req) 103 , m_request(req)
91 , m_isClientRedirect(false) 104 , m_isClientRedirect(false)
92 , m_replacesCurrentHistoryItem(false) 105 , m_replacesCurrentHistoryItem(false)
93 , m_navigationType(NavigationTypeOther) 106 , m_navigationType(NavigationTypeOther)
94 , m_documentLoadTiming(*this) 107 , m_documentLoadTiming(*this)
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 464
452 void DocumentLoader::ensureWriter(const AtomicString& mimeType, const KURL& over ridingURL) 465 void DocumentLoader::ensureWriter(const AtomicString& mimeType, const KURL& over ridingURL)
453 { 466 {
454 if (m_writer) 467 if (m_writer)
455 return; 468 return;
456 469
457 const AtomicString& encoding = m_frame->host()->overrideEncoding().isNull() ? response().textEncodingName() : m_frame->host()->overrideEncoding(); 470 const AtomicString& encoding = m_frame->host()->overrideEncoding().isNull() ? response().textEncodingName() : m_frame->host()->overrideEncoding();
458 471
459 // Prepare a DocumentInit before clearing the frame, because it may need to 472 // Prepare a DocumentInit before clearing the frame, because it may need to
460 // inherit an aliased security context. 473 // inherit an aliased security context.
461 DocumentInit init(url(), m_frame); 474 Document* owner = nullptr;
475 // TODO(dcheng): This differs from the behavior of both IE and Firefox: the
476 // origin is inherited from the document that loaded the URL.
477 if (shouldInheritSecurityOriginFromOwner(url())) {
478 Frame* ownerFrame = m_frame->tree().parent();
479 if (!ownerFrame)
480 ownerFrame = m_frame->loader().opener();
481 if (ownerFrame && ownerFrame->isLocalFrame())
482 owner = toLocalFrame(ownerFrame)->document();
483 }
484 DocumentInit init(owner, url(), m_frame);
462 init.withNewRegistrationContext(); 485 init.withNewRegistrationContext();
463 m_frame->loader().clear(); 486 m_frame->loader().clear();
464 ASSERT(m_frame->page()); 487 ASSERT(m_frame->page());
465 488
466 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; 489 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing;
467 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || !Document::threadedParsingEnabledForTesting()) 490 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || !Document::threadedParsingEnabledForTesting())
468 parsingPolicy = ForceSynchronousParsing; 491 parsingPolicy = ForceSynchronousParsing;
469 492
470 m_writer = createWriterFor(0, init, mimeType, encoding, false, parsingPolicy ); 493 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy);
471 m_writer->setDocumentWasLoadedAsPartOfNavigation(); 494 m_writer->setDocumentWasLoadedAsPartOfNavigation();
472 495
473 // This should be set before receivedFirstData(). 496 // This should be set before receivedFirstData().
474 if (!overridingURL.isEmpty()) 497 if (!overridingURL.isEmpty())
475 m_frame->document()->setBaseURLOverride(overridingURL); 498 m_frame->document()->setBaseURLOverride(overridingURL);
476 499
477 // Call receivedFirstData() exactly once per load. 500 // Call receivedFirstData() exactly once per load.
478 frameLoader()->receivedFirstData(); 501 frameLoader()->receivedFirstData();
479 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField(HTTPN ames::Refresh), Document::HttpRefreshFromHeader); 502 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField(HTTPN ames::Refresh), Document::HttpRefreshFromHeader);
480 } 503 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 m_fetcher->acceptDataFromThreadedReceiver(mainResourceIdentifier(), data, da taLength, encodedDataLength); 748 m_fetcher->acceptDataFromThreadedReceiver(mainResourceIdentifier(), data, da taLength, encodedDataLength);
726 } 749 }
727 750
728 void DocumentLoader::endWriting(DocumentWriter* writer) 751 void DocumentLoader::endWriting(DocumentWriter* writer)
729 { 752 {
730 ASSERT_UNUSED(writer, m_writer == writer); 753 ASSERT_UNUSED(writer, m_writer == writer);
731 m_writer->end(); 754 m_writer->end();
732 m_writer.clear(); 755 m_writer.clear();
733 } 756 }
734 757
735 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(const Doc ument* ownerDocument, const DocumentInit& init, const AtomicString& mimeType, co nst AtomicString& encoding, bool dispatch, ParserSynchronizationPolicy parsingPo licy) 758 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(const Doc umentInit& init, const AtomicString& mimeType, const AtomicString& encoding, boo l dispatch, ParserSynchronizationPolicy parsingPolicy)
736 { 759 {
737 LocalFrame* frame = init.frame(); 760 LocalFrame* frame = init.frame();
738 761
739 ASSERT(!frame->document() || !frame->document()->isActive()); 762 ASSERT(!frame->document() || !frame->document()->isActive());
740 ASSERT(frame->tree().childCount() == 0); 763 ASSERT(frame->tree().childCount() == 0);
741 764
742 if (!init.shouldReuseDefaultView()) 765 if (!init.shouldReuseDefaultView())
743 frame->setDOMWindow(LocalDOMWindow::create(*frame)); 766 frame->setDOMWindow(LocalDOMWindow::create(*frame));
744 767
745 RefPtrWillBeRawPtr<Document> document = frame->localDOMWindow()->installNewD ocument(mimeType, init); 768 RefPtrWillBeRawPtr<Document> document = frame->localDOMWindow()->installNewD ocument(mimeType, init);
jochen (gone - plz use gerrit) 2016/02/29 16:37:23 I wonder whether we should RELEASE_ASSERT that we
dcheng 2016/02/29 17:49:23 It's kind of expected that this will normally chan
746 if (ownerDocument) {
747 document->setCookieURL(ownerDocument->cookieURL());
748 document->updateSecurityOrigin(ownerDocument->securityOrigin());
749 }
750 769
751 frame->loader().didBeginDocument(dispatch); 770 frame->loader().didBeginDocument(dispatch);
752 771
753 return DocumentWriter::create(document.get(), parsingPolicy, mimeType, encod ing); 772 return DocumentWriter::create(document.get(), parsingPolicy, mimeType, encod ing);
754 } 773 }
755 774
756 const AtomicString& DocumentLoader::mimeType() const 775 const AtomicString& DocumentLoader::mimeType() const
757 { 776 {
758 if (m_writer) 777 if (m_writer)
759 return m_writer->mimeType(); 778 return m_writer->mimeType();
760 return m_response.mimeType(); 779 return m_response.mimeType();
761 } 780 }
762 781
763 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L() 782 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L()
764 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source, Document* ownerDocument) 783 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source)
765 { 784 {
766 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); 785 m_writer = createWriterFor(init, mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true, ForceSynchronousParsing);
767 if (!source.isNull()) 786 if (!source.isNull())
768 m_writer->appendReplacingData(source); 787 m_writer->appendReplacingData(source);
769 endWriting(m_writer.get()); 788 endWriting(m_writer.get());
770 } 789 }
771 790
772 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 791 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
773 792
774 } // namespace blink 793 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698