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

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

Issue 1295553002: Revert of Better handle reentrancy into DocumentLoader::dataReceived(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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 | « Source/core/loader/DocumentLoader.h ('k') | Source/web/tests/DocumentLoaderTest.cpp » ('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) 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "platform/mhtml/ArchiveResource.h" 65 #include "platform/mhtml/ArchiveResource.h"
66 #include "platform/mhtml/ArchiveResourceCollection.h" 66 #include "platform/mhtml/ArchiveResourceCollection.h"
67 #include "platform/mhtml/MHTMLArchive.h" 67 #include "platform/mhtml/MHTMLArchive.h"
68 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" 68 #include "platform/network/ContentSecurityPolicyResponseHeaders.h"
69 #include "platform/plugins/PluginData.h" 69 #include "platform/plugins/PluginData.h"
70 #include "platform/weborigin/SchemeRegistry.h" 70 #include "platform/weborigin/SchemeRegistry.h"
71 #include "platform/weborigin/SecurityPolicy.h" 71 #include "platform/weborigin/SecurityPolicy.h"
72 #include "public/platform/Platform.h" 72 #include "public/platform/Platform.h"
73 #include "public/platform/WebMimeRegistry.h" 73 #include "public/platform/WebMimeRegistry.h"
74 #include "wtf/Assertions.h" 74 #include "wtf/Assertions.h"
75 #include "wtf/TemporaryChange.h"
76 #include "wtf/text/WTFString.h" 75 #include "wtf/text/WTFString.h"
77 76
78 namespace blink { 77 namespace blink {
79 78
80 static bool isArchiveMIMEType(const String& mimeType) 79 static bool isArchiveMIMEType(const String& mimeType)
81 { 80 {
82 return equalIgnoringCase("multipart/related", mimeType); 81 return equalIgnoringCase("multipart/related", mimeType);
83 } 82 }
84 83
85 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData) 84 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData)
86 : m_frame(frame) 85 : m_frame(frame)
87 , m_fetcher(FrameFetchContext::createContextAndFetcher(this)) 86 , m_fetcher(FrameFetchContext::createContextAndFetcher(this))
88 , m_originalRequest(req) 87 , m_originalRequest(req)
89 , m_substituteData(substituteData) 88 , m_substituteData(substituteData)
90 , m_request(req) 89 , m_request(req)
91 , m_isClientRedirect(false) 90 , m_isClientRedirect(false)
92 , m_replacesCurrentHistoryItem(false) 91 , m_replacesCurrentHistoryItem(false)
93 , m_navigationType(NavigationTypeOther) 92 , m_navigationType(NavigationTypeOther)
94 , m_timeOfLastDataReceived(0.0) 93 , m_timeOfLastDataReceived(0.0)
95 , m_applicationCacheHost(ApplicationCacheHost::create(this)) 94 , m_applicationCacheHost(ApplicationCacheHost::create(this))
96 , m_state(NotStarted) 95 , m_state(NotStarted)
97 , m_inDataReceived(false)
98 , m_dataBuffer(SharedBuffer::create())
99 { 96 {
100 } 97 }
101 98
102 FrameLoader* DocumentLoader::frameLoader() const 99 FrameLoader* DocumentLoader::frameLoader() const
103 { 100 {
104 if (!m_frame) 101 if (!m_frame)
105 return nullptr; 102 return nullptr;
106 return &m_frame->loader(); 103 return &m_frame->loader();
107 } 104 }
108 105
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 547 }
551 548
552 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length) 549 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length)
553 { 550 {
554 ASSERT(data); 551 ASSERT(data);
555 ASSERT(length); 552 ASSERT(length);
556 ASSERT_UNUSED(resource, resource == m_mainResource); 553 ASSERT_UNUSED(resource, resource == m_mainResource);
557 ASSERT(!m_response.isNull()); 554 ASSERT(!m_response.isNull());
558 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); 555 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading());
559 556
560 if (m_inDataReceived) {
561 // If this function is reentered, defer processing of the additional
562 // data to the top-level invocation. Reentrant calls can occur because
563 // of web platform (mis-)features that require running a nested message
564 // loop:
565 // - alert(), confirm(), prompt()
566 // - Detach of plugin elements.
567 // - Synchronous XMLHTTPRequest
568 m_dataBuffer->append(data, length);
569 return;
570 }
571 TemporaryChange<bool> reentrancyProtector(m_inDataReceived, true);
572
573 // Both unloading the old page and parsing the new page may execute JavaScri pt which destroys the datasource 557 // Both unloading the old page and parsing the new page may execute JavaScri pt which destroys the datasource
574 // by starting a new load, so retain temporarily. 558 // by starting a new load, so retain temporarily.
575 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get()); 559 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get());
576 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this); 560 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
577 561
578 processData(data, length);
579
580 // Process data received in reentrant invocations. Note that the
581 // invocations of processData() may queue more data in reentrant
582 // invocations, so iterate until it's empty.
583 const char* segment;
584 unsigned pos = 0;
585 while (unsigned length = m_dataBuffer->getSomeData(segment, pos)) {
586 processData(segment, length);
587 pos += length;
588 }
589 // All data has been consumed, so flush the buffer.
590 m_dataBuffer->clear();
591 }
592
593 void DocumentLoader::processData(const char* data, unsigned length)
594 {
595 m_applicationCacheHost->mainResourceDataReceived(data, length); 562 m_applicationCacheHost->mainResourceDataReceived(data, length);
596 m_timeOfLastDataReceived = monotonicallyIncreasingTime(); 563 m_timeOfLastDataReceived = monotonicallyIncreasingTime();
597 564
598 if (isArchiveMIMEType(response().mimeType())) 565 if (isArchiveMIMEType(response().mimeType()))
599 return; 566 return;
600 commitIfReady(); 567 commitIfReady();
601 if (!frameLoader()) 568 if (!frameLoader())
602 return; 569 return;
603 commitData(data, length); 570 commitData(data, length);
604 571
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 { 821 {
855 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); 822 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing);
856 if (!source.isNull()) 823 if (!source.isNull())
857 m_writer->appendReplacingData(source); 824 m_writer->appendReplacingData(source);
858 endWriting(m_writer.get()); 825 endWriting(m_writer.get());
859 } 826 }
860 827
861 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 828 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
862 829
863 } // namespace blink 830 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/web/tests/DocumentLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698