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

Side by Side Diff: Source/web/WebFrame.cpp

Issue 544443002: Detach all subframes before swapping a frame. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove ASSERT in detachChildren, since FrameLoader::commitProvisionalLoad can hit it with ref count… Created 6 years, 3 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 | « no previous file | Source/web/tests/WebFrameTest.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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "public/web/WebFrame.h" 6 #include "public/web/WebFrame.h"
7 7
8 #include "core/frame/RemoteFrame.h" 8 #include "core/frame/RemoteFrame.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "platform/UserGestureIndicator.h" 10 #include "platform/UserGestureIndicator.h"
11 #include "web/OpenedFrameTracker.h" 11 #include "web/OpenedFrameTracker.h"
12 #include "web/WebLocalFrameImpl.h" 12 #include "web/WebLocalFrameImpl.h"
13 #include "web/WebRemoteFrameImpl.h" 13 #include "web/WebRemoteFrameImpl.h"
14 #include <algorithm> 14 #include <algorithm>
15 15
16 namespace blink { 16 namespace blink {
17 17
18 Frame* toCoreFrame(const WebFrame* frame) 18 Frame* toCoreFrame(const WebFrame* frame)
19 { 19 {
20 if (!frame) 20 if (!frame)
21 return 0; 21 return 0;
22 22
23 return frame->isWebLocalFrame() 23 return frame->isWebLocalFrame()
24 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) 24 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame())
25 : toWebRemoteFrameImpl(frame)->frame(); 25 : toWebRemoteFrameImpl(frame)->frame();
26 } 26 }
27 27
28 void WebFrame::swap(WebFrame* frame) 28 bool WebFrame::swap(WebFrame* frame)
29 { 29 {
30 using std::swap; 30 using std::swap;
31 RefPtr<Frame> oldFrame = toCoreFrame(this);
31 32
32 // All child frames must have been detached first. 33 // All child frames must be detached first.
33 ASSERT(!m_firstChild && !m_lastChild); 34 oldFrame->detachChildren();
35
36 // If the frame has been detached during detaching its children, return
eseidel 2014/09/10 18:09:12 When does this happen? Are there JS events which
37 // immediately.
38 // FIXME: There is no unit test for this condition, so one needs to be
39 // written.
40 if (!oldFrame->host())
41 return false;
42
34 // The frame being swapped in should not have a Frame associated 43 // The frame being swapped in should not have a Frame associated
35 // with it yet. 44 // with it yet.
36 ASSERT(!toCoreFrame(frame)); 45 ASSERT(!toCoreFrame(frame));
37 46
38 if (m_parent) { 47 if (m_parent) {
39 if (m_parent->m_firstChild == this) 48 if (m_parent->m_firstChild == this)
40 m_parent->m_firstChild = frame; 49 m_parent->m_firstChild = frame;
41 if (m_parent->m_lastChild == this) 50 if (m_parent->m_lastChild == this)
42 m_parent->m_lastChild = frame; 51 m_parent->m_lastChild = frame;
43 swap(m_parent, frame->m_parent); 52 swap(m_parent, frame->m_parent);
(...skipping 15 matching lines...) Expand all
59 } 68 }
60 if (!m_openedFrameTracker->isEmpty()) { 69 if (!m_openedFrameTracker->isEmpty()) {
61 m_openedFrameTracker->updateOpener(frame); 70 m_openedFrameTracker->updateOpener(frame);
62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 71 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release());
63 } 72 }
64 73
65 // Finally, clone the state of the current Frame into one matching 74 // Finally, clone the state of the current Frame into one matching
66 // the type of the passed in WebFrame. 75 // the type of the passed in WebFrame.
67 // FIXME: This is a bit clunky; this results in pointless decrements and 76 // FIXME: This is a bit clunky; this results in pointless decrements and
68 // increments of connected subframes. 77 // increments of connected subframes.
69 Frame* oldFrame = toCoreFrame(this);
70 FrameOwner* owner = oldFrame->owner(); 78 FrameOwner* owner = oldFrame->owner();
71 oldFrame->disconnectOwnerElement(); 79 oldFrame->disconnectOwnerElement();
72 if (frame->isWebLocalFrame()) { 80 if (frame->isWebLocalFrame()) {
73 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner, oldFrame->tree().name(), nullAtom); 81 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner, oldFrame->tree().name(), nullAtom);
74 } else { 82 } else {
75 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 83 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name());
76 } 84 }
85
86 return true;
77 } 87 }
78 88
79 v8::Handle<v8::Value> WebFrame::executeScriptAndReturnValueForTests(const WebScr iptSource& source) 89 v8::Handle<v8::Value> WebFrame::executeScriptAndReturnValueForTests(const WebScr iptSource& source)
80 { 90 {
81 // FIXME: This fake UserGestureIndicator is required for a bunch of browser 91 // FIXME: This fake UserGestureIndicator is required for a bunch of browser
82 // tests to pass. We should update the tests to simulate input and get rid 92 // tests to pass. We should update the tests to simulate input and get rid
83 // of this. 93 // of this.
84 // http://code.google.com/p/chromium/issues/detail?id=86397 94 // http://code.google.com/p/chromium/issues/detail?id=86397
85 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 95 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
86 return executeScriptAndReturnValue(source); 96 return executeScriptAndReturnValue(source);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 , m_openedFrameTracker(new OpenedFrameTracker) 224 , m_openedFrameTracker(new OpenedFrameTracker)
215 { 225 {
216 } 226 }
217 227
218 WebFrame::~WebFrame() 228 WebFrame::~WebFrame()
219 { 229 {
220 m_openedFrameTracker.reset(0); 230 m_openedFrameTracker.reset(0);
221 } 231 }
222 232
223 } // namespace blink 233 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698