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

Unified Diff: content/renderer/render_frame_impl.cc

Issue 1409693009: Fix leaking of RenderFrames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed frame checking and not detaching for main frames. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698