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

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: Don't send IPC for the main frame. Created 5 years 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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (previous_sibling_proxy) 692 if (previous_sibling_proxy)
693 previous_sibling_web_frame = previous_sibling_proxy->web_frame(); 693 previous_sibling_web_frame = previous_sibling_proxy->web_frame();
694 694
695 // Create the RenderFrame and WebLocalFrame, linking the two. 695 // Create the RenderFrame and WebLocalFrame, linking the two.
696 render_frame = 696 render_frame =
697 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id); 697 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id);
698 web_frame = parent_web_frame->createLocalChild( 698 web_frame = parent_web_frame->createLocalChild(
699 replicated_state.scope, WebString::fromUTF8(replicated_state.name), 699 replicated_state.scope, WebString::fromUTF8(replicated_state.name),
700 replicated_state.sandbox_flags, render_frame, 700 replicated_state.sandbox_flags, render_frame,
701 previous_sibling_web_frame, frame_owner_properties); 701 previous_sibling_web_frame, frame_owner_properties);
702
703 // The RenderFrame is created and inserted into the frame tree in the above
704 // call to createLocalChild.
705 render_frame->in_frame_tree_ = true;
702 } else { 706 } else {
703 RenderFrameProxy* proxy = 707 RenderFrameProxy* proxy =
704 RenderFrameProxy::FromRoutingID(proxy_routing_id); 708 RenderFrameProxy::FromRoutingID(proxy_routing_id);
705 CHECK(proxy); 709 CHECK(proxy);
706 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); 710 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id);
707 render_frame->proxy_routing_id_ = proxy_routing_id; 711 render_frame->proxy_routing_id_ = proxy_routing_id;
708 web_frame = blink::WebLocalFrame::createProvisional( 712 web_frame = blink::WebLocalFrame::createProvisional(
709 render_frame, proxy->web_frame(), replicated_state.sandbox_flags, 713 render_frame, proxy->web_frame(), replicated_state.sandbox_flags,
710 frame_owner_properties); 714 frame_owner_properties);
711 } 715 }
(...skipping 17 matching lines...) Expand all
729 // WasShown and WasHidden, separating page-level visibility from 733 // WasShown and WasHidden, separating page-level visibility from
730 // frame-level visibility. 734 // frame-level visibility.
731 render_frame->render_widget_->RegisterRenderFrame(render_frame); 735 render_frame->render_widget_->RegisterRenderFrame(render_frame);
732 } 736 }
733 } 737 }
734 738
735 render_frame->Initialize(); 739 render_frame->Initialize();
736 } 740 }
737 741
738 // static 742 // static
743 void RenderFrameImpl::DetachFrame(int routing_id) {
744 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
745 // 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.
746 // for a frame that is no longer alive.
747 if (frame) {
748 frame->set_in_browser_initiated_detach();
749 frame->GetWebFrame()->detach();
750 }
751 }
752
753 // static
739 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { 754 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) {
740 return RenderFrameImpl::FromWebFrame(web_frame); 755 return RenderFrameImpl::FromWebFrame(web_frame);
741 } 756 }
742 757
743 // static 758 // static
744 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { 759 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) {
745 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); 760 FrameMap::iterator iter = g_frame_map.Get().find(web_frame);
746 if (iter != g_frame_map.Get().end()) 761 if (iter != g_frame_map.Get().end())
747 return iter->second; 762 return iter->second;
748 return NULL; 763 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 return opener_frame->GetWebFrame(); 805 return opener_frame->GetWebFrame();
791 } 806 }
792 807
793 return nullptr; 808 return nullptr;
794 } 809 }
795 810
796 // RenderFrameImpl ---------------------------------------------------------- 811 // RenderFrameImpl ----------------------------------------------------------
797 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) 812 RenderFrameImpl::RenderFrameImpl(const CreateParams& params)
798 : frame_(NULL), 813 : frame_(NULL),
799 is_main_frame_(true), 814 is_main_frame_(true),
815 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
816 in_browser_initiated_detach_(false),
817 in_frame_tree_(false),
800 render_view_(params.render_view->AsWeakPtr()), 818 render_view_(params.render_view->AsWeakPtr()),
801 routing_id_(params.routing_id), 819 routing_id_(params.routing_id),
802 is_swapped_out_(false), 820 is_swapped_out_(false),
803 render_frame_proxy_(NULL), 821 render_frame_proxy_(NULL),
804 is_detaching_(false), 822 is_detaching_(false),
805 proxy_routing_id_(MSG_ROUTING_NONE), 823 proxy_routing_id_(MSG_ROUTING_NONE),
806 #if defined(ENABLE_PLUGINS) 824 #if defined(ENABLE_PLUGINS)
807 plugin_power_saver_helper_(nullptr), 825 plugin_power_saver_helper_(nullptr),
808 #endif 826 #endif
809 cookie_jar_(this), 827 cookie_jar_(this),
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 2449
2432 // Create the RenderFrame and WebLocalFrame, linking the two. 2450 // Create the RenderFrame and WebLocalFrame, linking the two.
2433 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( 2451 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create(
2434 render_view_.get(), child_routing_id); 2452 render_view_.get(), child_routing_id);
2435 blink::WebLocalFrame* web_frame = 2453 blink::WebLocalFrame* web_frame =
2436 WebLocalFrame::create(scope, child_render_frame); 2454 WebLocalFrame::create(scope, child_render_frame);
2437 child_render_frame->SetWebFrame(web_frame); 2455 child_render_frame->SetWebFrame(web_frame);
2438 2456
2439 // Add the frame to the frame tree and initialize it. 2457 // Add the frame to the frame tree and initialize it.
2440 parent->appendChild(web_frame); 2458 parent->appendChild(web_frame);
2459 child_render_frame->in_frame_tree_ = true;
2441 child_render_frame->Initialize(); 2460 child_render_frame->Initialize();
2442 2461
2443 return web_frame; 2462 return web_frame;
2444 } 2463 }
2445 2464
2446 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { 2465 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) {
2447 // Only active frames are able to disown their opener. 2466 // Only active frames are able to disown their opener.
2448 if (!opener && is_swapped_out_) 2467 if (!opener && is_swapped_out_)
2449 return; 2468 return;
2450 2469
(...skipping 11 matching lines...) Expand all
2462 // the parent frame. This is different from createChildFrame() which is 2481 // the parent frame. This is different from createChildFrame() which is
2463 // called on the parent frame. 2482 // called on the parent frame.
2464 CHECK(!is_detaching_); 2483 CHECK(!is_detaching_);
2465 DCHECK(!frame_ || frame_ == frame); 2484 DCHECK(!frame_ || frame_ == frame);
2466 2485
2467 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2486 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2468 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2487 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2469 FrameDetached(frame)); 2488 FrameDetached(frame));
2470 2489
2471 // We only notify the browser process when the frame is being detached for 2490 // We only notify the browser process when the frame is being detached for
2472 // removal. If the frame is being detached for swap, we don't need to do this 2491 // removal and it was initiated from the renderer process.
2473 // since we are not modifiying the frame tree. 2492 if (!in_browser_initiated_detach_ && type == DetachType::Remove)
2474 if (type == DetachType::Remove)
2475 Send(new FrameHostMsg_Detach(routing_id_)); 2493 Send(new FrameHostMsg_Detach(routing_id_));
2476 2494
2477 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2495 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2478 // sent before setting |is_detaching_| to true. 2496 // sent before setting |is_detaching_| to true.
2479 is_detaching_ = true; 2497 is_detaching_ = true;
2480 2498
2481 // Clean up the associated RenderWidget for the frame, if there is one. 2499 // Clean up the associated RenderWidget for the frame, if there is one.
2482 if (render_widget_) { 2500 if (render_widget_) {
2483 render_widget_->UnregisterRenderFrame(this); 2501 render_widget_->UnregisterRenderFrame(this);
2484 render_widget_->CloseForFrame(); 2502 render_widget_->CloseForFrame();
2485 } 2503 }
2486 2504
2487 // We need to clean up subframes by removing them from the map and deleting 2505 // We need to clean up subframes by removing them from the map and deleting
2488 // the RenderFrameImpl. In contrast, the main frame is owned by its 2506 // the RenderFrameImpl. In contrast, the main frame is owned by its
2489 // containing RenderViewHost (so that they have the same lifetime), so only 2507 // containing RenderViewHost (so that they have the same lifetime), so only
2490 // removal from the map is needed and no deletion. 2508 // removal from the map is needed and no deletion.
2491 FrameMap::iterator it = g_frame_map.Get().find(frame); 2509 FrameMap::iterator it = g_frame_map.Get().find(frame);
2492 CHECK(it != g_frame_map.Get().end()); 2510 CHECK(it != g_frame_map.Get().end());
2493 CHECK_EQ(it->second, this); 2511 CHECK_EQ(it->second, this);
2494 g_frame_map.Get().erase(it); 2512 g_frame_map.Get().erase(it);
2495 2513
2496 // Only remove the frame from the renderer's frame tree if the frame is 2514 // Only remove the frame from the renderer's frame tree if the frame is
2497 // being detached for removal. In the case of a swap, the frame needs to 2515 // being detached for removal and is already inserted in the frame tree.
2498 // remain in the tree so WebFrame::swap() can replace it with the new frame. 2516 // In the case of a swap, the frame needs to remain in the tree so
2499 if (!is_main_frame_ && type == DetachType::Remove) 2517 // WebFrame::swap() can replace it with the new frame.
2518 if (!is_main_frame_ && in_frame_tree_ &&
2519 type == DetachType::Remove) {
2500 frame->parent()->removeChild(frame); 2520 frame->parent()->removeChild(frame);
2521 }
2501 2522
2502 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2523 // |frame| is invalid after here. Be sure to clear frame_ as well, since this
2503 // object may not be deleted immediately and other methods may try to access 2524 // object may not be deleted immediately and other methods may try to access
2504 // it. 2525 // it.
2505 frame->close(); 2526 frame->close();
2506 frame_ = nullptr; 2527 frame_ = nullptr;
2507 2528
2508 delete this; 2529 delete this;
2509 // Object is invalid after this point. 2530 // Object is invalid after this point.
2510 } 2531 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2919 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( 2940 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(
2920 frame->dataSource()->response()); 2941 frame->dataSource()->response());
2921 is_using_lofi_ = extra_data && extra_data->is_using_lofi(); 2942 is_using_lofi_ = extra_data && extra_data->is_using_lofi();
2922 2943
2923 if (proxy_routing_id_ != MSG_ROUTING_NONE) { 2944 if (proxy_routing_id_ != MSG_ROUTING_NONE) {
2924 RenderFrameProxy* proxy = 2945 RenderFrameProxy* proxy =
2925 RenderFrameProxy::FromRoutingID(proxy_routing_id_); 2946 RenderFrameProxy::FromRoutingID(proxy_routing_id_);
2926 CHECK(proxy); 2947 CHECK(proxy);
2927 proxy->web_frame()->swap(frame_); 2948 proxy->web_frame()->swap(frame_);
2928 proxy_routing_id_ = MSG_ROUTING_NONE; 2949 proxy_routing_id_ = MSG_ROUTING_NONE;
2950 in_frame_tree_ = true;
2929 2951
2930 // If this is the main frame going from a remote frame to a local frame, 2952 // If this is the main frame going from a remote frame to a local frame,
2931 // it needs to set RenderViewImpl's pointer for the main frame to itself 2953 // it needs to set RenderViewImpl's pointer for the main frame to itself
2932 // and ensure RenderWidget is no longer in swapped out mode. 2954 // and ensure RenderWidget is no longer in swapped out mode.
2933 if (is_main_frame_) { 2955 if (is_main_frame_) {
2934 CHECK(!render_view_->main_render_frame_); 2956 CHECK(!render_view_->main_render_frame_);
2935 render_view_->main_render_frame_ = this; 2957 render_view_->main_render_frame_ = this;
2936 if (render_view_->is_swapped_out()) 2958 if (render_view_->is_swapped_out())
2937 render_view_->SetSwappedOut(false); 2959 render_view_->SetSwappedOut(false);
2938 } 2960 }
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after
5516 media::ConvertToSwitchOutputDeviceCB(web_callbacks); 5538 media::ConvertToSwitchOutputDeviceCB(web_callbacks);
5517 scoped_refptr<media::AudioOutputDevice> device = 5539 scoped_refptr<media::AudioOutputDevice> device =
5518 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), 5540 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(),
5519 security_origin); 5541 security_origin);
5520 media::OutputDeviceStatus status = device->GetDeviceStatus(); 5542 media::OutputDeviceStatus status = device->GetDeviceStatus();
5521 device->Stop(); 5543 device->Stop();
5522 callback.Run(status); 5544 callback.Run(status);
5523 } 5545 }
5524 5546
5525 } // namespace content 5547 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698