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

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: Fixes based on another review round. 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::DetachFrame(int routing_id) {
674 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
675 frame->set_in_browser_initiated_detach();
676 frame->GetWebFrame()->detach();
677 }
678
679 // static
673 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { 680 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) {
674 return RenderFrameImpl::FromWebFrame(web_frame); 681 return RenderFrameImpl::FromWebFrame(web_frame);
675 } 682 }
676 683
677 // static 684 // static
678 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { 685 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) {
679 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); 686 FrameMap::iterator iter = g_frame_map.Get().find(web_frame);
680 if (iter != g_frame_map.Get().end()) 687 if (iter != g_frame_map.Get().end())
681 return iter->second; 688 return iter->second;
682 return NULL; 689 return NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 732 }
726 733
727 return nullptr; 734 return nullptr;
728 } 735 }
729 736
730 // RenderFrameImpl ---------------------------------------------------------- 737 // RenderFrameImpl ----------------------------------------------------------
731 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) 738 RenderFrameImpl::RenderFrameImpl(const CreateParams& params)
732 : frame_(NULL), 739 : frame_(NULL),
733 is_main_frame_(true), 740 is_main_frame_(true),
734 is_local_root_(false), 741 is_local_root_(false),
742 in_browser_initiated_detach_(false),
735 render_view_(params.render_view->AsWeakPtr()), 743 render_view_(params.render_view->AsWeakPtr()),
736 routing_id_(params.routing_id), 744 routing_id_(params.routing_id),
737 is_swapped_out_(false), 745 is_swapped_out_(false),
738 render_frame_proxy_(NULL), 746 render_frame_proxy_(NULL),
739 is_detaching_(false), 747 is_detaching_(false),
740 proxy_routing_id_(MSG_ROUTING_NONE), 748 proxy_routing_id_(MSG_ROUTING_NONE),
741 #if defined(ENABLE_PLUGINS) 749 #if defined(ENABLE_PLUGINS)
742 plugin_power_saver_helper_(nullptr), 750 plugin_power_saver_helper_(nullptr),
743 #endif 751 #endif
744 cookie_jar_(this), 752 cookie_jar_(this),
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2353 // the parent frame. This is different from createChildFrame() which is 2361 // the parent frame. This is different from createChildFrame() which is
2354 // called on the parent frame. 2362 // called on the parent frame.
2355 CHECK(!is_detaching_); 2363 CHECK(!is_detaching_);
2356 DCHECK(!frame_ || frame_ == frame); 2364 DCHECK(!frame_ || frame_ == frame);
2357 2365
2358 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2366 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2359 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2367 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2360 FrameDetached(frame)); 2368 FrameDetached(frame));
2361 2369
2362 // We only notify the browser process when the frame is being detached for 2370 // 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 2371 // removal and it was initiated from the renderer process.
2364 // since we are not modifiying the frame tree. 2372 if (!in_browser_initiated_detach_ && type == DetachType::Remove)
2365 if (type == DetachType::Remove)
2366 Send(new FrameHostMsg_Detach(routing_id_)); 2373 Send(new FrameHostMsg_Detach(routing_id_));
2367 2374
2368 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2375 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2369 // sent before setting |is_detaching_| to true. 2376 // sent before setting |is_detaching_| to true.
2370 is_detaching_ = true; 2377 is_detaching_ = true;
2371 2378
2372 // Clean up the associated RenderWidget for the frame, if there is one. 2379 // Clean up the associated RenderWidget for the frame, if there is one.
2373 if (render_widget_) { 2380 if (render_widget_) {
2374 render_widget_->UnregisterRenderFrame(this); 2381 render_widget_->UnregisterRenderFrame(this);
2375 render_widget_->CloseForFrame(); 2382 render_widget_->CloseForFrame();
2376 } 2383 }
2377 2384
2378 // We need to clean up subframes by removing them from the map and deleting 2385 // 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 2386 // the RenderFrameImpl. In contrast, the main frame is owned by its
2380 // containing RenderViewHost (so that they have the same lifetime), so only 2387 // containing RenderViewHost (so that they have the same lifetime), so only
2381 // removal from the map is needed and no deletion. 2388 // removal from the map is needed and no deletion.
2382 FrameMap::iterator it = g_frame_map.Get().find(frame); 2389 FrameMap::iterator it = g_frame_map.Get().find(frame);
2383 CHECK(it != g_frame_map.Get().end()); 2390 CHECK(it != g_frame_map.Get().end());
2384 CHECK_EQ(it->second, this); 2391 CHECK_EQ(it->second, this);
2385 g_frame_map.Get().erase(it); 2392 g_frame_map.Get().erase(it);
2386 2393
2387 // Only remove the frame from the renderer's frame tree if the frame is 2394 // 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 2395 // being detached for removal and it is inserted in the set of child frames.
2389 // remain in the tree so WebFrame::swap() can replace it with the new frame. 2396 // In the case of a swap, the frame needs to remain in the tree so
2390 if (!is_main_frame_ && type == DetachType::Remove) 2397 // WebFrame::swap() can replace it with the new frame.
2391 frame->parent()->removeChild(frame); 2398 if (!is_main_frame_ && type == DetachType::Remove) {
2399 for (WebFrame* child = frame->firstChild(); child;
Charlie Reis 2015/11/02 23:43:50 This doesn't look right to me. Shouldn't we be lo
2400 child = child->nextSibling()) {
2401 if (child == frame) {
2402 LOG(ERROR) << "Removing child from parent";
2403 frame->parent()->removeChild(frame);
2404 break;
2405 }
2406 }
2407 LOG(ERROR) << "Frame not found in parent's children";
2408 }
2392 2409
2393 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2410 // |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 2411 // object may not be deleted immediately and other methods may try to access
2395 // it. 2412 // it.
2396 frame->close(); 2413 frame->close();
2397 frame_ = nullptr; 2414 frame_ = nullptr;
2398 2415
2399 delete this; 2416 delete this;
2400 // Object is invalid after this point. 2417 // Object is invalid after this point.
2401 } 2418 }
(...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after
5287 mojo::ServiceProviderPtr service_provider; 5304 mojo::ServiceProviderPtr service_provider;
5288 mojo::URLRequestPtr request(mojo::URLRequest::New()); 5305 mojo::URLRequestPtr request(mojo::URLRequest::New());
5289 request->url = mojo::String::From(url); 5306 request->url = mojo::String::From(url);
5290 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), 5307 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider),
5291 nullptr, nullptr, 5308 nullptr, nullptr,
5292 base::Bind(&OnGotContentHandlerID)); 5309 base::Bind(&OnGotContentHandlerID));
5293 return service_provider.Pass(); 5310 return service_provider.Pass();
5294 } 5311 }
5295 5312
5296 } // namespace content 5313 } // namespace content
OLDNEW
« 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