Index: content/renderer/render_frame_impl.cc |
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc |
index 1693d1f77ba56e0899765c4c384cf8835c0c3484..7cb664f5347d8bd8d6b2eaf545f690bad94121eb 100644 |
--- a/content/renderer/render_frame_impl.cc |
+++ b/content/renderer/render_frame_impl.cc |
@@ -671,6 +671,13 @@ void RenderFrameImpl::CreateFrame( |
} |
// static |
+void RenderFrameImpl::DetachFrame(int routing_id) { |
dcheng
2015/11/03 04:22:54
Is it worth DCHECKing our current limitations? For
nasko
2015/11/03 17:59:08
Done.
Charlie Reis
2015/11/04 21:28:30
I don't see the new DCHECK. I guess it doesn't ap
|
+ RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
+ frame->set_in_browser_initiated_detach(); |
+ frame->GetWebFrame()->detach(); |
+} |
+ |
+// static |
RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
return RenderFrameImpl::FromWebFrame(web_frame); |
} |
@@ -733,6 +740,7 @@ RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
: frame_(NULL), |
is_main_frame_(true), |
is_local_root_(false), |
+ in_browser_initiated_detach_(false), |
render_view_(params.render_view->AsWeakPtr()), |
routing_id_(params.routing_id), |
is_swapped_out_(false), |
@@ -2369,9 +2377,8 @@ void RenderFrameImpl::frameDetached(blink::WebFrame* frame, DetachType type) { |
FrameDetached(frame)); |
// We only notify the browser process when the frame is being detached for |
- // removal. If the frame is being detached for swap, we don't need to do this |
- // since we are not modifiying the frame tree. |
- if (type == DetachType::Remove) |
+ // removal and it was initiated from the renderer process. |
+ if (!in_browser_initiated_detach_ && type == DetachType::Remove) |
Send(new FrameHostMsg_Detach(routing_id_)); |
// The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
@@ -2394,10 +2401,18 @@ void RenderFrameImpl::frameDetached(blink::WebFrame* frame, DetachType type) { |
g_frame_map.Get().erase(it); |
// Only remove the frame from the renderer's frame tree if the frame is |
- // being detached for removal. In the case of a swap, the frame needs to |
- // remain in the tree so WebFrame::swap() can replace it with the new frame. |
- if (!is_main_frame_ && type == DetachType::Remove) |
- frame->parent()->removeChild(frame); |
+ // being detached for removal and it is inserted in the set of child frames. |
+ // In the case of a swap, the frame needs to remain in the tree so |
+ // WebFrame::swap() can replace it with the new frame. |
+ if (!is_main_frame_ && type == DetachType::Remove) { |
+ for (WebFrame* child = frame->parent()->firstChild(); child; |
dcheng
2015/11/03 04:22:53
Is there no heuristic we can use inside //content
nasko
2015/11/03 17:59:08
Well, content/ is now in charge of maintaining the
|
+ child = child->nextSibling()) { |
+ if (child == frame) { |
+ frame->parent()->removeChild(frame); |
+ break; |
+ } |
+ } |
+ } |
// |frame| is invalid after here. Be sure to clear frame_ as well, since this |
// object may not be deleted immediately and other methods may try to access |