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

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

Issue 1714063002: Protect the provisional loader from detaching during prepareForCommit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a layout test, fixed bugs with initial fix Created 4 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameLoader.h ('k') | no next file » | 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, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 FrameLoader::FrameLoader(LocalFrame* frame) 161 FrameLoader::FrameLoader(LocalFrame* frame)
162 : m_frame(frame) 162 : m_frame(frame)
163 , m_progressTracker(ProgressTracker::create(frame)) 163 , m_progressTracker(ProgressTracker::create(frame))
164 , m_loadType(FrameLoadTypeStandard) 164 , m_loadType(FrameLoadTypeStandard)
165 , m_inStopAllLoaders(false) 165 , m_inStopAllLoaders(false)
166 , m_checkTimer(this, &FrameLoader::checkTimerFired) 166 , m_checkTimer(this, &FrameLoader::checkTimerFired)
167 , m_didAccessInitialDocument(false) 167 , m_didAccessInitialDocument(false)
168 , m_didAccessInitialDocumentTimer(this, &FrameLoader::didAccessInitialDocume ntTimerFired) 168 , m_didAccessInitialDocumentTimer(this, &FrameLoader::didAccessInitialDocume ntTimerFired)
169 , m_forcedSandboxFlags(SandboxNone) 169 , m_forcedSandboxFlags(SandboxNone)
170 , m_dispatchingDidClearWindowObjectInMainWorld(false) 170 , m_dispatchingDidClearWindowObjectInMainWorld(false)
171 , m_protectProvisionalLoader(false)
171 { 172 {
172 } 173 }
173 174
174 FrameLoader::~FrameLoader() 175 FrameLoader::~FrameLoader()
175 { 176 {
176 // Verify that this FrameLoader has been detached. 177 // Verify that this FrameLoader has been detached.
177 ASSERT(!m_progressTracker); 178 ASSERT(!m_progressTracker);
178 } 179 }
179 180
180 DEFINE_TRACE(FrameLoader) 181 DEFINE_TRACE(FrameLoader)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 m_currentItem->setVisualViewportScrollPoint(m_frame->host()->visualViewport( ).visibleRect().location()); 247 m_currentItem->setVisualViewportScrollPoint(m_frame->host()->visualViewport( ).visibleRect().location());
247 248
248 if (m_frame->isMainFrame()) 249 if (m_frame->isMainFrame())
249 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); 250 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor());
250 251
251 client()->didUpdateCurrentHistoryItem(); 252 client()->didUpdateCurrentHistoryItem();
252 } 253 }
253 254
254 void FrameLoader::dispatchUnloadEvent() 255 void FrameLoader::dispatchUnloadEvent()
255 { 256 {
257 // If the frame is unloading, the provisional loader should no longer be
258 // protected. It will be detached soon.
259 m_protectProvisionalLoader = false;
256 saveScrollState(); 260 saveScrollState();
257 261
258 if (m_frame->document() && !SVGImage::isInSVGImage(m_frame->document())) 262 if (m_frame->document() && !SVGImage::isInSVGImage(m_frame->document()))
259 m_frame->document()->dispatchUnloadEvents(); 263 m_frame->document()->dispatchUnloadEvents();
260 264
261 if (Page* page = m_frame->page()) 265 if (Page* page = m_frame->page())
262 page->undoStack().didUnloadFrame(*m_frame); 266 page->undoStack().didUnloadFrame(*m_frame);
263 } 267 }
264 268
265 void FrameLoader::didExplicitOpen() 269 void FrameLoader::didExplicitOpen()
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); 989 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get());
986 990
987 m_inStopAllLoaders = true; 991 m_inStopAllLoaders = true;
988 992
989 for (RefPtrWillBeRawPtr<Frame> child = m_frame->tree().firstChild(); child; child = child->tree().nextSibling()) { 993 for (RefPtrWillBeRawPtr<Frame> child = m_frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
990 if (child->isLocalFrame()) 994 if (child->isLocalFrame())
991 toLocalFrame(child.get())->loader().stopAllLoaders(); 995 toLocalFrame(child.get())->loader().stopAllLoaders();
992 } 996 }
993 997
994 m_frame->document()->suppressLoadEvent(); 998 m_frame->document()->suppressLoadEvent();
995 if (m_provisionalDocumentLoader) 999 // Don't stop loading the provisional loader if it is being protected (i.e.
1000 // it is about to be committed) See prepareForCommit() for more details.
1001 if (m_provisionalDocumentLoader && !m_protectProvisionalLoader)
996 m_provisionalDocumentLoader->stopLoading(); 1002 m_provisionalDocumentLoader->stopLoading();
997 if (m_documentLoader) 1003 if (m_documentLoader)
998 m_documentLoader->stopLoading(); 1004 m_documentLoader->stopLoading();
999 m_frame->document()->cancelParsing(); 1005 m_frame->document()->cancelParsing();
1000 1006
1001 detachDocumentLoader(m_provisionalDocumentLoader); 1007 if (!m_protectProvisionalLoader)
dcheng 2016/02/22 18:12:07 Would it be slightly more robust to put this check
Charlie Harrison 2016/02/24 17:09:15 I'm not sure. My first attempt is giving me crashe
dcheng 2016/02/24 21:22:59 Hmm, mind posting a stack on here? I'm kind of cur
1008 detachDocumentLoader(m_provisionalDocumentLoader);
1002 1009
1003 m_checkTimer.stop(); 1010 m_checkTimer.stop();
1004 m_frame->navigationScheduler().cancel(); 1011 m_frame->navigationScheduler().cancel();
1005 1012
1006 m_inStopAllLoaders = false; 1013 m_inStopAllLoaders = false;
1007 } 1014 }
1008 1015
1009 void FrameLoader::didAccessInitialDocument() 1016 void FrameLoader::didAccessInitialDocument()
1010 { 1017 {
1011 // We only need to notify the client once, and only for the main frame. 1018 // We only need to notify the client once, and only for the main frame.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 client()->dispatchWillClose(); 1062 client()->dispatchWillClose();
1056 dispatchUnloadEvent(); 1063 dispatchUnloadEvent();
1057 } 1064 }
1058 m_frame->detachChildren(); 1065 m_frame->detachChildren();
1059 // The previous calls to dispatchUnloadEvent() and detachChildren() can 1066 // The previous calls to dispatchUnloadEvent() and detachChildren() can
1060 // execute arbitrary script via things like unload events. If the executed 1067 // execute arbitrary script via things like unload events. If the executed
1061 // script intiates a new load or causes the current frame to be detached, 1068 // script intiates a new load or causes the current frame to be detached,
1062 // we need to abandon the current load. 1069 // we need to abandon the current load.
1063 if (pdl != m_provisionalDocumentLoader) 1070 if (pdl != m_provisionalDocumentLoader)
1064 return false; 1071 return false;
1072 // detachFromFrame() will abort XHRs that haven't completed, which can
1073 // trigger event listeners for 'abort'. These event listeners might call
1074 // stop(), which will in turn detach the provisional document loader.
dcheng 2016/02/22 18:12:07 Nit: window.stop()
Charlie Harrison 2016/02/24 17:09:15 Done.
1075 // At this point, the provisional document loader should not detach, because
1076 // then the FrameLoader would not have any attached DocumentLoaders.
1065 if (m_documentLoader) { 1077 if (m_documentLoader) {
1066 FrameNavigationDisabler navigationDisabler(*m_frame); 1078 FrameNavigationDisabler navigationDisabler(*m_frame);
1079 TemporaryChange<bool> inDetachDocumentLoader(m_protectProvisionalLoader, true);
1067 detachDocumentLoader(m_documentLoader); 1080 detachDocumentLoader(m_documentLoader);
1068 } 1081 }
1069 // detachFromFrame() will abort XHRs that haven't completed, which can 1082 // 'abort' listeners can also detach the frame.
1070 // trigger event listeners for 'abort'. These event listeners might detach
1071 // the frame.
1072 // TODO(dcheng): Investigate if this can be moved above the check that 1083 // TODO(dcheng): Investigate if this can be moved above the check that
dcheng 2016/02/22 18:12:07 Nit: clean up this TODO as well, it doesn't really
Charlie Harrison 2016/02/24 17:09:15 Done.
1073 // m_provisionalDocumentLoader hasn't changed. 1084 // m_provisionalDocumentLoader hasn't changed.
1074 if (!m_frame->client()) 1085 if (!m_frame->client())
1075 return false; 1086 return false;
1087 ASSERT(m_provisionalDocumentLoader == pdl);
1076 // No more events will be dispatched so detach the Document. 1088 // No more events will be dispatched so detach the Document.
1077 // TODO(yoav): Should we also be nullifying domWindow's document (or domWind ow) since the doc is now detached? 1089 // TODO(yoav): Should we also be nullifying domWindow's document (or domWind ow) since the doc is now detached?
1078 if (m_frame->document()) 1090 if (m_frame->document())
1079 m_frame->document()->detach(); 1091 m_frame->document()->detach();
1080 m_documentLoader = m_provisionalDocumentLoader.release(); 1092 m_documentLoader = m_provisionalDocumentLoader.release();
1081 1093
1082 return true; 1094 return true;
1083 } 1095 }
1084 1096
1085 void FrameLoader::commitProvisionalLoad() 1097 void FrameLoader::commitProvisionalLoad()
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 // FIXME: We need a way to propagate insecure requests policy flags to 1573 // FIXME: We need a way to propagate insecure requests policy flags to
1562 // out-of-process frames. For now, we'll always use default behavior. 1574 // out-of-process frames. For now, we'll always use default behavior.
1563 if (!parentFrame->isLocalFrame()) 1575 if (!parentFrame->isLocalFrame())
1564 return nullptr; 1576 return nullptr;
1565 1577
1566 ASSERT(toLocalFrame(parentFrame)->document()); 1578 ASSERT(toLocalFrame(parentFrame)->document());
1567 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; 1579 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ;
1568 } 1580 }
1569 1581
1570 } // namespace blink 1582 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698