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

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: rebase, addressing dcheng's comments 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"
dcheng 2015/06/10 19:56:29 Nit: remove this since it's no longer needed here.
lfg 2015/06/10 22:43:35 Done.
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 if (isWebLocalFrame())
44 oldFrame->detachChildren(); 49 toLocalFrame(toCoreFrame(this))->loader().prepareForCommit();
dcheng 2015/06/10 19:56:29 Let's use virtual dispatch on Frame instead. We ca
lfg 2015/06/10 22:43:35 I've moved to a virtual dispatch, but I'm hoping y
dcheng 2015/06/11 18:45:02 Meh. It's good enough =)
50 else
51 oldFrame->detachChildren();
45 52
46 // If the frame has been detached during detaching its children, return 53 // If the frame has been detached during detaching by any JS code, we should
47 // immediately. 54 // cancel the swap.
48 // FIXME: There is no unit test for this condition, so one needs to be 55 // FIXME: There is no unit test for this condition, so one needs to be
49 // written. 56 // written.
50 if (!oldFrame->host()) 57 if (!oldFrame->host())
51 return false; 58 return false;
52 59
60 FrameOwner* owner = oldFrame->owner();
61 FrameHost* host = oldFrame->host();
62
63 // Frame::detach will call clearForClose(), we need to call
64 // clearForNavigate() before detaching.
65 oldFrame->prepareSwapFrom(oldFrame.get());
66
67 oldFrame->detach(FrameDetachType::Swap);
68
53 if (m_parent) { 69 if (m_parent) {
54 if (m_parent->m_firstChild == this) 70 if (m_parent->m_firstChild == this)
55 m_parent->m_firstChild = frame; 71 m_parent->m_firstChild = frame;
56 if (m_parent->m_lastChild == this) 72 if (m_parent->m_lastChild == this)
57 m_parent->m_lastChild = frame; 73 m_parent->m_lastChild = frame;
58 // FIXME: This is due to the fact that the |frame| may be a provisional 74 // 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 75 // 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 76 // an actual page or something else, like a download. The PlzNavigate
61 // project will remove the need for provisional local frames. 77 // project will remove the need for provisional local frames.
62 frame->m_parent = m_parent; 78 frame->m_parent = m_parent;
(...skipping 16 matching lines...) Expand all
79 } 95 }
80 if (!m_openedFrameTracker->isEmpty()) { 96 if (!m_openedFrameTracker->isEmpty()) {
81 m_openedFrameTracker->updateOpener(frame); 97 m_openedFrameTracker->updateOpener(frame);
82 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release()); 98 frame->m_openedFrameTracker.reset(m_openedFrameTracker.release());
83 } 99 }
84 100
85 // Finally, clone the state of the current Frame into one matching 101 // Finally, clone the state of the current Frame into one matching
86 // the type of the passed in WebFrame. 102 // the type of the passed in WebFrame.
87 // FIXME: This is a bit clunky; this results in pointless decrements and 103 // FIXME: This is a bit clunky; this results in pointless decrements and
88 // increments of connected subframes. 104 // increments of connected subframes.
89 FrameOwner* owner = oldFrame->owner();
90 oldFrame->disconnectOwnerElement();
91 if (frame->isWebLocalFrame()) { 105 if (frame->isWebLocalFrame()) {
92 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame(); 106 LocalFrame& localFrame = *toWebLocalFrameImpl(frame)->frame();
93 ASSERT(owner == localFrame.owner()); 107 ASSERT(owner == localFrame.owner());
94 if (owner) { 108 if (owner) {
95 if (owner->isLocal()) { 109 if (owner->isLocal()) {
96 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner); 110 HTMLFrameOwnerElement* ownerElement = toHTMLFrameOwnerElement(ow ner);
97 ownerElement->setContentFrame(localFrame); 111 ownerElement->setContentFrame(localFrame);
98 ownerElement->setWidget(localFrame.view()); 112 ownerElement->setWidget(localFrame.view());
99 } else { 113 } else {
100 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame)); 114 toRemoteBridgeFrameOwner(owner)->setContentFrame(toWebLocalFrame Impl(frame));
101 } 115 }
102 } else { 116 } else {
103 localFrame.page()->setMainFrame(&localFrame); 117 localFrame.page()->setMainFrame(&localFrame);
104 } 118 }
105 } else { 119 } else {
106 toWebRemoteFrameImpl(frame)->initializeCoreFrame(oldFrame->host(), owner , oldFrame->tree().name()); 120 toWebRemoteFrameImpl(frame)->initializeCoreFrame(host, owner, oldFrame-> tree().name());
107 } 121 }
108 toCoreFrame(frame)->finishSwapFrom(oldFrame.get()); 122 toCoreFrame(frame)->finishSwapFrom(oldFrame.get());
109 123
110 return true; 124 return true;
111 } 125 }
112 126
113 void WebFrame::detach() 127 void WebFrame::detach()
114 { 128 {
115 toCoreFrame(this)->detach(); 129 toCoreFrame(this)->detach(FrameDetachType::Remove);
116 } 130 }
117 131
118 WebSecurityOrigin WebFrame::securityOrigin() const 132 WebSecurityOrigin WebFrame::securityOrigin() const
119 { 133 {
120 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n()); 134 return WebSecurityOrigin(toCoreFrame(this)->securityContext()->securityOrigi n());
121 } 135 }
122 136
123 137
124 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags) 138 void WebFrame::setFrameOwnerSandboxFlags(WebSandboxFlags flags)
125 { 139 {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \ 357 void WebFrame::traceFrames(VisitorDispatcher visitor, WebFrame* frame) { tra ceFramesImpl(visitor, frame); } \
344 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); } 358 void WebFrame::clearWeakFrames(VisitorDispatcher visitor) { clearWeakFramesI mpl(visitor); }
345 359
346 DEFINE_VISITOR_METHOD(Visitor*) 360 DEFINE_VISITOR_METHOD(Visitor*)
347 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor) 361 DEFINE_VISITOR_METHOD(InlinedGlobalMarkingVisitor)
348 362
349 #undef DEFINE_VISITOR_METHOD 363 #undef DEFINE_VISITOR_METHOD
350 #endif 364 #endif
351 365
352 } // namespace blink 366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698