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

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: tests and cleanup Created 5 years, 6 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
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 19 matching lines...) Expand all
30 if (!frame) 30 if (!frame)
31 return 0; 31 return 0;
32 32
33 return frame->isWebLocalFrame() 33 return frame->isWebLocalFrame()
34 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) 34 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame())
35 : toWebRemoteFrameImpl(frame)->frame(); 35 : toWebRemoteFrameImpl(frame)->frame();
36 } 36 }
37 37
38 bool WebFrame::swap(WebFrame* frame) 38 bool WebFrame::swap(WebFrame* frame)
39 { 39 {
40 using std::swap;
41 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this); 40 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this);
41 #if !ENABLE(OILPAN)
42 RefPtrWillBeRawPtr<WebLocalFrameImpl> protectWebLocalFrame =
43 isWebLocalFrame() ? toWebLocalFrameImpl(this) : nullptr;
44 RefPtrWillBeRawPtr<WebRemoteFrameImpl> protectWebRemoteFrame =
45 isWebRemoteFrame() ? toWebRemoteFrameImpl(this) : nullptr;
46 #endif
42 47
43 // All child frames must be detached first. 48 if (isWebLocalFrame())
49 dispatchUnloadEvent();
44 oldFrame->detachChildren(); 50 oldFrame->detachChildren();
45 51
46 // If the frame has been detached during detaching its children, return 52 // If the frame has been detached during detaching its children, return
dcheng 2015/06/04 00:58:23 Update this comment to reflect that we want to che
lfg 2015/06/04 19:16:58 Updated.
dcheng 2015/06/05 02:11:50 We need to call it independently, because it can a
47 // immediately. 53 // immediately.
48 // FIXME: There is no unit test for this condition, so one needs to be 54 // FIXME: There is no unit test for this condition, so one needs to be
49 // written. 55 // written.
50 if (!oldFrame->host()) 56 if (!oldFrame->host())
51 return false; 57 return false;
52 58
59 FrameOwner* owner = oldFrame->owner();
60 FrameHost* host = oldFrame->host();
61
62 // Frame::detach will call clearForClose(), we need to call
63 // clearForNavigate() before detaching.
64 oldFrame->prepareSwapFrom(oldFrame.get());
65
66 oldFrame->detach(DetachType::Swap);
67
53 if (m_parent) { 68 if (m_parent) {
54 if (m_parent->m_firstChild == this) 69 if (m_parent->m_firstChild == this)
55 m_parent->m_firstChild = frame; 70 m_parent->m_firstChild = frame;
56 if (m_parent->m_lastChild == this) 71 if (m_parent->m_lastChild == this)
57 m_parent->m_lastChild = frame; 72 m_parent->m_lastChild = frame;
58 // FIXME: This is due to the fact that the |frame| may be a provisional 73 // FIXME: This is due to the fact that the |frame| may be a provisional
59 // local frame, because we don't know if the navigation will result in 74 // local frame, because we don't know if the navigation will result in
60 // an actual page or something else, like a download. The PlzNavigate 75 // an actual page or something else, like a download. The PlzNavigate
61 // project will remove the need for provisional local frames. 76 // project will remove the need for provisional local frames.
62 frame->m_parent = m_parent; 77 frame->m_parent = m_parent;
63 m_parent = nullptr; 78 m_parent = nullptr;
64 } 79 }
65 80
66 if (m_previousSibling) { 81 if (m_previousSibling) {
67 m_previousSibling->m_nextSibling = frame; 82 m_previousSibling->m_nextSibling = frame;
68 swap(m_previousSibling, frame->m_previousSibling); 83 std::swap(m_previousSibling, frame->m_previousSibling);
dcheng 2015/06/04 00:58:23 No std:: since swap() is special.
lfg 2015/06/04 19:16:58 Not sure I understand this, do you mean don't use
dcheng 2015/06/05 02:11:50 Yes, restore the using std::swap and then remove t
69 } 84 }
70 if (m_nextSibling) { 85 if (m_nextSibling) {
71 m_nextSibling->m_previousSibling = frame; 86 m_nextSibling->m_previousSibling = frame;
72 swap(m_nextSibling, frame->m_nextSibling); 87 std::swap(m_nextSibling, frame->m_nextSibling);
dcheng 2015/06/04 00:58:23 Ditto.
73 } 88 }
74 89
75 if (m_opener) { 90 if (m_opener) {
76 m_opener->m_openedFrameTracker->remove(this); 91 m_opener->m_openedFrameTracker->remove(this);
77 m_opener->m_openedFrameTracker->add(frame); 92 m_opener->m_openedFrameTracker->add(frame);
78 swap(m_opener, frame->m_opener); 93 std::swap(m_opener, frame->m_opener);
dcheng 2015/06/04 00:58:23 Ditto.
79 } 94 }
80 if (!m_openedFrameTracker->isEmpty()) { 95 if (!m_openedFrameTracker->isEmpty()) {
81 m_openedFrameTracker->updateOpener(frame); 96 m_openedFrameTracker->updateOpener(frame);
82 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 97 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release());
83 } 98 }
84 99
85 // Finally, clone the state of the current Frame into one matching 100 // Finally, clone the state of the current Frame into one matching
86 // the type of the passed in WebFrame. 101 // the type of the passed in WebFrame.
87 // FIXME: This is a bit clunky; this results in pointless decrements and 102 // FIXME: This is a bit clunky; this results in pointless decrements and
88 // increments of connected subframes. 103 // increments of connected subframes.
89 FrameOwner* owner = oldFrame->owner();
90 oldFrame->disconnectOwnerElement();
91 if (frame->isWebLocalFrame()) { 104 if (frame->isWebLocalFrame()) {
92 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame(); 105 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame();
93 ASSERT(owner == localFrame.owner()); 106 ASSERT(owner == localFrame.owner());
94 if (owner) { 107 if (owner) {
95 if (owner->isLocal()) { 108 if (owner->isLocal()) {
96 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); 109 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner);
97 ownerElement->setContentFrame(localFrame); 110 ownerElement->setContentFrame(localFrame);
98 ownerElement->setWidget(localFrame.view()); 111 ownerElement->setWidget(localFrame.view());
99 } else { 112 } else {
100 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); 113 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame));
101 } 114 }
102 } else { 115 } else {
103 localFrame.page()->setMainFrame(&localFrame); 116 localFrame.page()->setMainFrame(&localFrame);
104 } 117 }
105 } else { 118 } else {
106 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 119 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, oldFrame-> tree().name());
107 } 120 }
108 toCoreFrame(frame)->finishSwapFrom(oldFrame.get()); 121 toCoreFrame(frame)->finishSwapFrom(oldFrame.get());
109 122
110 return true; 123 return true;
111 } 124 }
112 125
113 void WebFrame::detach() 126 void WebFrame::detach()
114 { 127 {
115 toCoreFrame(this)->detach(); 128 toCoreFrame(this)->detach(DetachType::Remove);
116 } 129 }
117 130
118 WebSecurityOrigin WebFrame::securityOrigin() const 131 WebSecurityOrigin WebFrame::securityOrigin() const
119 { 132 {
120 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n()); 133 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n());
121 } 134 }
122 135
123 136
124 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags) 137 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags)
125 { 138 {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \ 356 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \
344 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); } 357 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); }
345 358
346 DEFINE_VISITOR_METHOD(Visitor*) 359 DEFINE_VISITOR_METHOD(Visitor*)
347 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) 360 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor)
348 361
349 #undef DEFINE_VISITOR_METHOD 362 #undef DEFINE_VISITOR_METHOD
350 #endif 363 #endif
351 364
352 } // namespace blink 365 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698