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

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

Issue 1041473002: Detach old frame on WebFrame::swap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
« no previous file with comments | « Source/core/frame/Frame.cpp ('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 // 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 "bindings/core/v8/WindowProxyManager.h" 8 #include "bindings/core/v8/WindowProxyManager.h"
9 #include "core/frame/FrameHost.h" 9 #include "core/frame/FrameHost.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 17 matching lines...) Expand all
28 if (!frame) 28 if (!frame)
29 return 0; 29 return 0;
30 30
31 return frame->isWebLocalFrame() 31 return frame->isWebLocalFrame()
32 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) 32 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame())
33 : toWebRemoteFrameImpl(frame)->frame(); 33 : toWebRemoteFrameImpl(frame)->frame();
34 } 34 }
35 35
36 bool WebFrame::swap(WebFrame* frame) 36 bool WebFrame::swap(WebFrame* frame)
37 { 37 {
38 using std::swap;
39 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this); 38 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this);
40 39
41 // All child frames must be detached first. 40 if (isWebLocalFrame())
dcheng 2015/03/27 04:08:47 I think you can get the unload() behavior you want
lfg 2015/03/27 04:57:52 Interesting, I'll try that.
42 oldFrame->detachChildren(); 41 dispatchUnloadEvent();
43 42
44 // If the frame has been detached during detaching its children, return 43 // If the frame has been detached during detaching its children, return
45 // immediately. 44 // immediately.
46 // FIXME: There is no unit test for this condition, so one needs to be 45 // FIXME: There is no unit test for this condition, so one needs to be
47 // written. 46 // written.
48 if (!oldFrame->host()) 47 if (!oldFrame->host())
49 return false; 48 return false;
50 49
51 if (m_parent) { 50 FrameOwner* owner = oldFrame->owner();
52 if (m_parent->m_firstChild == this) 51 const AtomicString name = oldFrame->tree().name();
53 m_parent->m_firstChild = frame; 52 FrameHost* host = oldFrame->host();
54 if (m_parent->m_lastChild == this) 53 WebFrame* parent = m_parent;
55 m_parent->m_lastChild = frame; 54 WebFrame* parentOldFirstChild = parent ? parent->m_firstChild : nullptr;
56 // FIXME: This is due to the fact that the |frame| may be a provisional 55 WebFrame* parentOldLastChild = parent ? parent->m_lastChild : nullptr;
57 // local frame, because we don't know if the navigation will result in 56 WebFrame* previousSibling = m_previousSibling;
58 // an actual page or something else, like a download. The PlzNavigate 57 WebFrame* nextSibling = m_nextSibling;
59 // project will remove the need for provisional local frames. 58 WebFrame* opener = m_opener;
60 frame->m_parent = m_parent; 59 WebPrivateOwnPtr<OpenedFrameTracker> openedFrameTracker;
61 m_parent = nullptr; 60 openedFrameTracker.reset(m_openedFrameTracker.release());
61
62 oldFrame->prepareSwapFrom(oldFrame.get());
63
64 oldFrame->detach();
65 // Object is invalid beyond this point.
dcheng 2015/03/27 04:08:47 I don't think this comment is completely accurate-
lfg 2015/03/27 04:57:52 The WebFrame is gone (i.e. the object pointed by t
66
67 if (parent) {
68 if (parentOldFirstChild == this)
69 parent->m_firstChild = frame;
70 if (parentOldLastChild == this)
71 parent->m_lastChild = frame;
72 frame->m_parent = parent;
62 } 73 }
63 74
64 if (m_previousSibling) { 75 if (previousSibling) {
65 m_previousSibling->m_nextSibling = frame; 76 previousSibling->m_nextSibling = frame;
66 swap(m_previousSibling, frame->m_previousSibling); 77 frame->m_previousSibling = previousSibling;
67 } 78 }
68 if (m_nextSibling) { 79 if (nextSibling) {
69 m_nextSibling->m_previousSibling = frame; 80 nextSibling->m_previousSibling = frame;
70 swap(m_nextSibling, frame->m_nextSibling); 81 frame->m_nextSibling = nextSibling;
71 } 82 }
72 83
73 if (m_opener) { 84 if (opener) {
74 m_opener->m_openedFrameTracker->remove(this); 85 opener->m_openedFrameTracker->remove(this);
75 m_opener->m_openedFrameTracker->add(frame); 86 opener->m_openedFrameTracker->add(frame);
76 swap(m_opener, frame->m_opener); 87 frame->m_opener = opener;
77 } 88 }
78 if (!m_openedFrameTracker->isEmpty()) { 89 if (!openedFrameTracker->isEmpty()) {
79 m_openedFrameTracker->updateOpener(frame); 90 openedFrameTracker->updateOpener(frame);
80 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 91 frame->m_openedFrameTracker.reset(openedFrameTracker.release());
81 } 92 }
82 93
83 // Finally, clone the state of the current Frame into one matching 94 // Finally, clone the state of the current Frame into one matching
84 // the type of the passed in WebFrame. 95 // the type of the passed in WebFrame.
85 // FIXME: This is a bit clunky; this results in pointless decrements and 96 // FIXME: This is a bit clunky; this results in pointless decrements and
86 // increments of connected subframes. 97 // increments of connected subframes.
87 FrameOwner* owner = oldFrame->owner();
88 oldFrame->disconnectOwnerElement();
89 if (frame->isWebLocalFrame()) { 98 if (frame->isWebLocalFrame()) {
90 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame(); 99 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame();
91 ASSERT(owner == localFrame.owner()); 100 ASSERT(owner == localFrame.owner());
92 if (owner) { 101 if (owner) {
93 if (owner->isLocal()) { 102 if (owner->isLocal()) {
94 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); 103 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner);
95 ownerElement->setContentFrame(localFrame); 104 ownerElement->setContentFrame(localFrame);
96 ownerElement->setWidget(localFrame.view()); 105 ownerElement->setWidget(localFrame.view());
97 } else { 106 } else {
98 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); 107 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame));
99 } 108 }
100 } else { 109 } else {
101 localFrame.page()->setMainFrame(&localFrame); 110 localFrame.page()->setMainFrame(&localFrame);
102 } 111 }
103 } else { 112 } else {
104 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 113 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, name);
105 } 114 }
106 toCoreFrame(frame)->finishSwapFrom(oldFrame.get()); 115 toCoreFrame(frame)->finishSwapFrom(oldFrame.get());
116 toCoreFrame(frame)->tree().invalidateScopedChildCount();
117 toCoreFrame(frame)->host()->incrementSubframeCount();
118 openedFrameTracker.reset(0);
107 119
108 return true; 120 return true;
109 } 121 }
110 122
111 void WebFrame::detach() 123 void WebFrame::detach()
112 { 124 {
113 toCoreFrame(this)->detach(); 125 toCoreFrame(this)->detach();
114 } 126 }
115 127
116 WebSecurityOrigin WebFrame::securityOrigin() const 128 WebSecurityOrigin WebFrame::securityOrigin() const
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 bool WebFrame::isFrameAlive(VisitorType visitor, const WebFrame* frame) { re turn isFrameAliveImpl(visitor, frame); } \ 330 bool WebFrame::isFrameAlive(VisitorType visitor, const WebFrame* frame) { re turn isFrameAliveImpl(visitor, frame); } \
319 void WebFrame::clearWeakFrames(VisitorType visitor) { clearWeakFramesImpl(vi sitor); } 331 void WebFrame::clearWeakFrames(VisitorType visitor) { clearWeakFramesImpl(vi sitor); }
320 332
321 DEFINE_VISITOR_METHOD(Visitor*) 333 DEFINE_VISITOR_METHOD(Visitor*)
322 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) 334 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor)
323 335
324 #undef DEFINE_VISITOR_METHOD 336 #undef DEFINE_VISITOR_METHOD
325 #endif 337 #endif
326 338
327 } // namespace blink 339 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/Frame.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698