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

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: Fixes based on Ken's review and Daniel's comments. 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
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
37 // immediately.
38 if (!oldFrame->host())
39 return false;
40
34 // The frame being swapped in should not have a Frame associated 41 // The frame being swapped in should not have a Frame associated
35 // with it yet. 42 // with it yet.
36 ASSERT(!toCoreFrame(frame)); 43 ASSERT(!toCoreFrame(frame));
37 44
38 if (m_parent) { 45 if (m_parent) {
39 if (m_parent->m_firstChild == this) 46 if (m_parent->m_firstChild == this)
40 m_parent->m_firstChild = frame; 47 m_parent->m_firstChild = frame;
41 if (m_parent->m_lastChild == this) 48 if (m_parent->m_lastChild == this)
42 m_parent->m_lastChild = frame; 49 m_parent->m_lastChild = frame;
43 swap(m_parent, frame->m_parent); 50 swap(m_parent, frame->m_parent);
(...skipping 15 matching lines...) Expand all
59 } 66 }
60 if (!m_openedFrameTracker->isEmpty()) { 67 if (!m_openedFrameTracker->isEmpty()) {
61 m_openedFrameTracker->updateOpener(frame); 68 m_openedFrameTracker->updateOpener(frame);
62 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 69 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release());
63 } 70 }
64 71
65 // Finally, clone the state of the current Frame into one matching 72 // Finally, clone the state of the current Frame into one matching
66 // the type of the passed in WebFrame. 73 // the type of the passed in WebFrame.
67 // FIXME: This is a bit clunky; this results in pointless decrements and 74 // FIXME: This is a bit clunky; this results in pointless decrements and
68 // increments of connected subframes. 75 // increments of connected subframes.
69 Frame* oldFrame = toCoreFrame(this);
70 FrameOwner* owner = oldFrame->owner(); 76 FrameOwner* owner = oldFrame->owner();
71 oldFrame->disconnectOwnerElement(); 77 oldFrame->disconnectOwnerElement();
72 if (frame->isWebLocalFrame()) { 78 if (frame->isWebLocalFrame()) {
73 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner, oldFrame->tree().name(), nullAtom); 79 toWebLocalFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner, oldFrame->tree().name(), nullAtom);
74 } else { 80 } else {
75 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 81 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name());
76 } 82 }
83
84 return true;
77 } 85 }
78 86
79 v8::Handle<v8::Value> WebFrame::executeScriptAndReturnValueForTests(const WebScr iptSource& source) 87 v8::Handle<v8::Value> WebFrame::executeScriptAndReturnValueForTests(const WebScr iptSource& source)
80 { 88 {
81 // FIXME: This fake UserGestureIndicator is required for a bunch of browser 89 // 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 90 // tests to pass. We should update the tests to simulate input and get rid
83 // of this. 91 // of this.
84 // http://code.google.com/p/chromium/issues/detail?id=86397 92 // http://code.google.com/p/chromium/issues/detail?id=86397
85 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 93 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
86 return executeScriptAndReturnValue(source); 94 return executeScriptAndReturnValue(source);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 , m_openedFrameTracker(new OpenedFrameTracker) 222 , m_openedFrameTracker(new OpenedFrameTracker)
215 { 223 {
216 } 224 }
217 225
218 WebFrame::~WebFrame() 226 WebFrame::~WebFrame()
219 { 227 {
220 m_openedFrameTracker.reset(0); 228 m_openedFrameTracker.reset(0);
221 } 229 }
222 230
223 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698