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

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, 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"
11 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
12 #include "core/frame/RemoteFrame.h" 12 #include "core/frame/RemoteFrame.h"
13 #include "core/html/HTMLFrameElementBase.h" 13 #include "core/html/HTMLFrameElementBase.h"
14 #include "core/html/HTMLFrameOwnerElement.h" 14 #include "core/html/HTMLFrameOwnerElement.h"
15 #include "core/loader/DocumentLoader.h"
15 #include "core/page/Page.h" 16 #include "core/page/Page.h"
16 #include "platform/UserGestureIndicator.h" 17 #include "platform/UserGestureIndicator.h"
17 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
18 #include "public/web/WebElement.h" 19 #include "public/web/WebElement.h"
19 #include "public/web/WebSandboxFlags.h" 20 #include "public/web/WebSandboxFlags.h"
20 #include "web/OpenedFrameTracker.h" 21 #include "web/OpenedFrameTracker.h"
21 #include "web/RemoteBridgeFrameOwner.h" 22 #include "web/RemoteBridgeFrameOwner.h"
22 #include "web/WebLocalFrameImpl.h" 23 #include "web/WebLocalFrameImpl.h"
23 #include "web/WebRemoteFrameImpl.h" 24 #include "web/WebRemoteFrameImpl.h"
24 #include <algorithm> 25 #include <algorithm>
25 26
26 namespace blink { 27 namespace blink {
27 28
28 Frame* toCoreFrame(const WebFrame* frame) 29 Frame* toCoreFrame(const WebFrame* frame)
29 { 30 {
30 if (!frame) 31 if (!frame)
31 return 0; 32 return 0;
32 33
33 return frame->isWebLocalFrame() 34 return frame->isWebLocalFrame()
34 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame()) 35 ? static_cast<Frame*>(toWebLocalFrameImpl(frame)->frame())
35 : toWebRemoteFrameImpl(frame)->frame(); 36 : toWebRemoteFrameImpl(frame)->frame();
36 } 37 }
37 38
38 bool WebFrame::swap(WebFrame* frame) 39 bool WebFrame::swap(WebFrame* frame)
39 { 40 {
40 using std::swap; 41 using std::swap;
41 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this); 42 RefPtrWillBeRawPtr<Frame> oldFrame = toCoreFrame(this);
43 #if !ENABLE(OILPAN)
44 RefPtrWillBeRawPtr<WebLocalFrameImpl> protectWebLocalFrame = isWebLocalFrame () ? toWebLocalFrameImpl(this) : nullptr;
45 RefPtrWillBeRawPtr<WebRemoteFrameImpl> protectWebRemoteFrame = isWebRemoteFr ame() ? toWebRemoteFrameImpl(this) : nullptr;
46 #endif
42 47
43 // All child frames must be detached first. 48 bool readyToSwap = true;
44 oldFrame->detachChildren(); 49 if (isWebLocalFrame())
50 readyToSwap = toLocalFrame(toCoreFrame(this))->loader().prepareForCommit ();
51 else
52 oldFrame->detachChildren();
dcheng 2015/06/08 19:34:42 If we're swapping remote to local, and detaching t
lfg 2015/06/10 18:41:28 At first I thought this would never be the case, b
45 53
46 // If the frame has been detached during detaching its children, return 54 // If the frame has been detached during detaching by any JS code, we should
47 // immediately. 55 // cancel the swap.
48 // FIXME: There is no unit test for this condition, so one needs to be 56 // FIXME: There is no unit test for this condition, so one needs to be
49 // written. 57 // written.
50 if (!oldFrame->host()) 58 if (!readyToSwap)
dcheng 2015/06/08 19:34:42 I think you can keep the original check here, sinc
lfg 2015/06/10 18:41:28 Done.
51 return false; 59 return false;
52 60
61 FrameOwner* owner = oldFrame->owner();
62 FrameHost* host = oldFrame->host();
63
64 // Frame::detach will call clearForClose(), we need to call
65 // clearForNavigate() before detaching.
66 oldFrame->prepareSwapFrom(oldFrame.get());
67
68 oldFrame->detach(FrameDetachType::Swap);
69
53 if (m_parent) { 70 if (m_parent) {
54 if (m_parent->m_firstChild == this) 71 if (m_parent->m_firstChild == this)
55 m_parent->m_firstChild = frame; 72 m_parent->m_firstChild = frame;
56 if (m_parent->m_lastChild == this) 73 if (m_parent->m_lastChild == this)
57 m_parent->m_lastChild = frame; 74 m_parent->m_lastChild = frame;
58 // FIXME: This is due to the fact that the |frame| may be a provisional 75 // 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 76 // 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 77 // an actual page or something else, like a download. The PlzNavigate
61 // project will remove the need for provisional local frames. 78 // project will remove the need for provisional local frames.
62 frame->m_parent = m_parent; 79 frame->m_parent = m_parent;
(...skipping 16 matching lines...) Expand all
79 } 96 }
80 if (!m_openedFrameTracker->isEmpty()) { 97 if (!m_openedFrameTracker->isEmpty()) {
81 m_openedFrameTracker->updateOpener(frame); 98 m_openedFrameTracker->updateOpener(frame);
82 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 99 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release());
83 } 100 }
84 101
85 // Finally, clone the state of the current Frame into one matching 102 // Finally, clone the state of the current Frame into one matching
86 // the type of the passed in WebFrame. 103 // the type of the passed in WebFrame.
87 // FIXME: This is a bit clunky; this results in pointless decrements and 104 // FIXME: This is a bit clunky; this results in pointless decrements and
88 // increments of connected subframes. 105 // increments of connected subframes.
89 FrameOwner* owner = oldFrame->owner();
90 oldFrame->disconnectOwnerElement();
91 if (frame->isWebLocalFrame()) { 106 if (frame->isWebLocalFrame()) {
92 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame(); 107 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame();
93 ASSERT(owner == localFrame.owner()); 108 ASSERT(owner == localFrame.owner());
94 if (owner) { 109 if (owner) {
95 if (owner->isLocal()) { 110 if (owner->isLocal()) {
96 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); 111 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner);
97 ownerElement->setContentFrame(localFrame); 112 ownerElement->setContentFrame(localFrame);
98 ownerElement->setWidget(localFrame.view()); 113 ownerElement->setWidget(localFrame.view());
99 } else { 114 } else {
100 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); 115 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame));
101 } 116 }
102 } else { 117 } else {
103 localFrame.page()->setMainFrame(&localFrame); 118 localFrame.page()->setMainFrame(&localFrame);
104 } 119 }
105 } else { 120 } else {
106 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 121 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, oldFrame-> tree().name());
107 } 122 }
108 toCoreFrame(frame)->finishSwapFrom(oldFrame.get()); 123 toCoreFrame(frame)->finishSwapFrom(oldFrame.get());
109 124
110 return true; 125 return true;
111 } 126 }
112 127
113 void WebFrame::detach() 128 void WebFrame::detach()
114 { 129 {
115 toCoreFrame(this)->detach(); 130 toCoreFrame(this)->detach(FrameDetachType::Remove);
116 } 131 }
117 132
118 WebSecurityOrigin WebFrame::securityOrigin() const 133 WebSecurityOrigin WebFrame::securityOrigin() const
119 { 134 {
120 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n()); 135 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n());
121 } 136 }
122 137
123 138
124 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags) 139 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags)
125 { 140 {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \ 358 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \
344 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); } 359 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); }
345 360
346 DEFINE_VISITOR_METHOD(Visitor*) 361 DEFINE_VISITOR_METHOD(Visitor*)
347 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) 362 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor)
348 363
349 #undef DEFINE_VISITOR_METHOD 364 #undef DEFINE_VISITOR_METHOD
350 #endif 365 #endif
351 366
352 } // namespace blink 367 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698