Index: content/renderer/render_frame_impl.cc |
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc |
index 9e432ba9394f11a708bce49a6d40d9c62c5f3a65..0e3a5882dcefaa6925b863663cdc76423c7e3dd8 100644 |
--- a/content/renderer/render_frame_impl.cc |
+++ b/content/renderer/render_frame_impl.cc |
@@ -699,6 +699,10 @@ void RenderFrameImpl::CreateFrame( |
replicated_state.scope, WebString::fromUTF8(replicated_state.name), |
replicated_state.sandbox_flags, render_frame, |
previous_sibling_web_frame, frame_owner_properties); |
+ |
+ // The RenderFrame is created and inserted into the frame tree in the above |
+ // call to createLocalChild. |
+ render_frame->in_frame_tree_ = true; |
} else { |
RenderFrameProxy* proxy = |
RenderFrameProxy::FromRoutingID(proxy_routing_id); |
@@ -736,6 +740,17 @@ void RenderFrameImpl::CreateFrame( |
} |
// static |
+void RenderFrameImpl::DetachFrame(int routing_id) { |
+ RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
+ // TODO(nasko): Investigate why it is possible to receive a FrameMsg_Detach |
Charlie Reis
2015/12/11 20:10:14
Wouldn't it be possible for the renderer process t
nasko
2015/12/14 21:00:02
Done.
|
+ // for a frame that is no longer alive. |
+ if (frame) { |
+ frame->set_in_browser_initiated_detach(); |
+ frame->GetWebFrame()->detach(); |
+ } |
+} |
+ |
+// static |
RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
return RenderFrameImpl::FromWebFrame(web_frame); |
} |
@@ -797,6 +812,9 @@ blink::WebFrame* RenderFrameImpl::ResolveOpener(int opener_frame_routing_id, |
RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
: frame_(NULL), |
is_main_frame_(true), |
+ is_local_root_(false), |
Charlie Reis
2015/12/11 20:10:14
We set is_main_frame_ to true by default. Should
nasko
2015/12/14 21:00:02
I have no recollection what that was here ... oh w
|
+ in_browser_initiated_detach_(false), |
+ in_frame_tree_(false), |
render_view_(params.render_view->AsWeakPtr()), |
routing_id_(params.routing_id), |
is_swapped_out_(false), |
@@ -2438,6 +2456,7 @@ blink::WebFrame* RenderFrameImpl::createChildFrame( |
// Add the frame to the frame tree and initialize it. |
parent->appendChild(web_frame); |
+ child_render_frame->in_frame_tree_ = true; |
child_render_frame->Initialize(); |
return web_frame; |
@@ -2469,9 +2488,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 |
@@ -2494,10 +2512,13 @@ 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) |
+ // being detached for removal and is already inserted in the frame tree. |
+ // 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_ && in_frame_tree_ && |
+ type == DetachType::Remove) { |
frame->parent()->removeChild(frame); |
+ } |
// |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 |
@@ -2926,6 +2947,7 @@ void RenderFrameImpl::didCommitProvisionalLoad( |
CHECK(proxy); |
proxy->web_frame()->swap(frame_); |
proxy_routing_id_ = MSG_ROUTING_NONE; |
+ in_frame_tree_ = true; |
// If this is the main frame going from a remote frame to a local frame, |
// it needs to set RenderViewImpl's pointer for the main frame to itself |