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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // WasShown and WasHidden, separating page-level visibility from 663 // WasShown and WasHidden, separating page-level visibility from
664 // frame-level visibility. 664 // frame-level visibility.
665 render_frame->render_widget_->RegisterRenderFrame(render_frame); 665 render_frame->render_widget_->RegisterRenderFrame(render_frame);
666 } 666 }
667 } 667 }
668 668
669 render_frame->Initialize(); 669 render_frame->Initialize();
670 } 670 }
671 671
672 // static 672 // static
673 void RenderFrameImpl::DeleteFrame(int routing_id) {
674 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
675 frame->GetWebFrame()->detach();
Charlie Reis 2015/10/29 17:28:58 We should get Daniel to confirm that detach is the
dcheng 2015/10/29 18:50:52 It's kind of wonky, but we should basically treat
nasko 2015/10/29 19:09:45 It isn't in the tree, but there are a lot of suppo
676 }
677
678 // static
673 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { 679 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) {
674 return RenderFrameImpl::FromWebFrame(web_frame); 680 return RenderFrameImpl::FromWebFrame(web_frame);
675 } 681 }
676 682
677 // static 683 // static
678 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { 684 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) {
679 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); 685 FrameMap::iterator iter = g_frame_map.Get().find(web_frame);
680 if (iter != g_frame_map.Get().end()) 686 if (iter != g_frame_map.Get().end())
681 return iter->second; 687 return iter->second;
682 return NULL; 688 return NULL;
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 // NOTE: This function is called on the frame that is being detached and not 2358 // NOTE: This function is called on the frame that is being detached and not
2353 // the parent frame. This is different from createChildFrame() which is 2359 // the parent frame. This is different from createChildFrame() which is
2354 // called on the parent frame. 2360 // called on the parent frame.
2355 CHECK(!is_detaching_); 2361 CHECK(!is_detaching_);
2356 DCHECK(!frame_ || frame_ == frame); 2362 DCHECK(!frame_ || frame_ == frame);
2357 2363
2358 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2364 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2359 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2365 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2360 FrameDetached(frame)); 2366 FrameDetached(frame));
2361 2367
2368 // When navigating cross-process and a pending RenderFrameHost is used,
2369 // the RenderFrame is initialized to replace a RenderFrameProxy and its
Charlie Reis 2015/10/29 17:28:58 This isn't always true, is it? If the pending Ren
nasko 2015/10/29 19:09:45 In the case of pending RenderFrame being first the
2370 // routing id is stored until commit time. If the navigation is cancelled,
2371 // the RenderFrame must be deleted, but it isn't fully initialized.
2372 bool is_fully_initialized = (proxy_routing_id_ == MSG_ROUTING_NONE);
2373
2374
Charlie Reis 2015/10/29 17:28:59 nit: Remove extra blank line.
nasko 2015/10/29 19:09:45 Done.
2362 // We only notify the browser process when the frame is being detached for 2375 // We only notify the browser process when the frame is being detached for
2363 // removal. If the frame is being detached for swap, we don't need to do this 2376 // removal. If the frame is being detached for swap or the frame isn't fully
2364 // since we are not modifiying the frame tree. 2377 // initialized, we don't need to do this since we are not modifiying the frame
2365 if (type == DetachType::Remove) 2378 // tree.
2379 if (is_fully_initialized && type == DetachType::Remove)
2366 Send(new FrameHostMsg_Detach(routing_id_)); 2380 Send(new FrameHostMsg_Detach(routing_id_));
2367 2381
2368 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2382 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2369 // sent before setting |is_detaching_| to true. 2383 // sent before setting |is_detaching_| to true.
2370 is_detaching_ = true; 2384 is_detaching_ = true;
2371 2385
2372 // Clean up the associated RenderWidget for the frame, if there is one. 2386 // Clean up the associated RenderWidget for the frame, if there is one.
2373 if (render_widget_) { 2387 if (render_widget_) {
2374 render_widget_->UnregisterRenderFrame(this); 2388 render_widget_->UnregisterRenderFrame(this);
2375 render_widget_->CloseForFrame(); 2389 render_widget_->CloseForFrame();
2376 } 2390 }
2377 2391
2378 // We need to clean up subframes by removing them from the map and deleting 2392 // We need to clean up subframes by removing them from the map and deleting
2379 // the RenderFrameImpl. In contrast, the main frame is owned by its 2393 // the RenderFrameImpl. In contrast, the main frame is owned by its
2380 // containing RenderViewHost (so that they have the same lifetime), so only 2394 // containing RenderViewHost (so that they have the same lifetime), so only
2381 // removal from the map is needed and no deletion. 2395 // removal from the map is needed and no deletion.
2382 FrameMap::iterator it = g_frame_map.Get().find(frame); 2396 FrameMap::iterator it = g_frame_map.Get().find(frame);
2383 CHECK(it != g_frame_map.Get().end()); 2397 CHECK(it != g_frame_map.Get().end());
2384 CHECK_EQ(it->second, this); 2398 CHECK_EQ(it->second, this);
2385 g_frame_map.Get().erase(it); 2399 g_frame_map.Get().erase(it);
2386 2400
2387 // Only remove the frame from the renderer's frame tree if the frame is 2401 // Only remove the frame from the renderer's frame tree if the frame is
2388 // being detached for removal. In the case of a swap, the frame needs to 2402 // being detached for removal. In the case of a swap, the frame needs to
2389 // remain in the tree so WebFrame::swap() can replace it with the new frame. 2403 // remain in the tree so WebFrame::swap() can replace it with the new frame.
2390 if (!is_main_frame_ && type == DetachType::Remove) 2404 // If the frame isn't fully initialized (e.g. deleting a pending RenderFrame)
2405 // it is not linked into the frame tree, so it should not be removed.
2406 if (is_fully_initialized && !is_main_frame_ && type == DetachType::Remove)
2391 frame->parent()->removeChild(frame); 2407 frame->parent()->removeChild(frame);
2392 2408
2393 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2409 // |frame| is invalid after here. Be sure to clear frame_ as well, since this
2394 // object may not be deleted immediately and other methods may try to access 2410 // object may not be deleted immediately and other methods may try to access
2395 // it. 2411 // it.
2396 frame->close(); 2412 frame->close();
2397 frame_ = nullptr; 2413 frame_ = nullptr;
2398 2414
2399 delete this; 2415 delete this;
2400 // Object is invalid after this point. 2416 // Object is invalid after this point.
(...skipping 2886 matching lines...) Expand 10 before | Expand all | Expand 10 after
5287 mojo::ServiceProviderPtr service_provider; 5303 mojo::ServiceProviderPtr service_provider;
5288 mojo::URLRequestPtr request(mojo::URLRequest::New()); 5304 mojo::URLRequestPtr request(mojo::URLRequest::New());
5289 request->url = mojo::String::From(url); 5305 request->url = mojo::String::From(url);
5290 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), 5306 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider),
5291 nullptr, nullptr, 5307 nullptr, nullptr,
5292 base::Bind(&OnGotContentHandlerID)); 5308 base::Bind(&OnGotContentHandlerID));
5293 return service_provider.Pass(); 5309 return service_provider.Pass();
5294 } 5310 }
5295 5311
5296 } // namespace content 5312 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698