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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1149793002: Detach old frame on WebFrame::swap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: properly rebasing Created 5 years, 6 months 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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (contains_media_player_) 685 if (contains_media_player_)
686 render_view_->UnregisterVideoHoleFrame(this); 686 render_view_->UnregisterVideoHoleFrame(this);
687 #endif 687 #endif
688 688
689 if (!is_subframe_) { 689 if (!is_subframe_) {
690 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is 690 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is
691 // the main frame. Ensure it is deleted along with this object. 691 // the main frame. Ensure it is deleted along with this object.
692 if (render_frame_proxy_) { 692 if (render_frame_proxy_) {
693 // The following method calls back into this object and clears 693 // The following method calls back into this object and clears
694 // |render_frame_proxy_|. 694 // |render_frame_proxy_|.
695 render_frame_proxy_->frameDetached(); 695 render_frame_proxy_->frameDetached(false);
dcheng 2015/05/28 21:56:00 I don't understand the comment or this code. Why d
lfg 2015/05/29 18:34:44 This code is needed to destroy the RenderFrameProx
696 } 696 }
697 697
698 // Ensure the RenderView doesn't point to this object, once it is destroyed. 698 // Ensure the RenderView doesn't point to this object, once it is destroyed.
699 CHECK_EQ(render_view_->main_render_frame_, this); 699 CHECK_EQ(render_view_->main_render_frame_, this);
700 render_view_->main_render_frame_ = nullptr; 700 render_view_->main_render_frame_ = nullptr;
701 } 701 }
702 702
703 render_view_->UnregisterRenderFrame(this); 703 render_view_->UnregisterRenderFrame(this);
704 g_routing_id_frame_map.Get().erase(routing_id_); 704 g_routing_id_frame_map.Get().erase(routing_id_);
705 RenderThread::Get()->RemoveRoute(routing_id_); 705 RenderThread::Get()->RemoveRoute(routing_id_);
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 // opener after hearing about it from the browser, and the browser does not 2113 // opener after hearing about it from the browser, and the browser does not
2114 // (yet) care about subframe openers. 2114 // (yet) care about subframe openers.
2115 if (is_swapped_out_ || frame->parent()) 2115 if (is_swapped_out_ || frame->parent())
2116 return; 2116 return;
2117 2117
2118 // Notify WebContents and all its swapped out RenderViews. 2118 // Notify WebContents and all its swapped out RenderViews.
2119 Send(new FrameHostMsg_DidDisownOpener(routing_id_)); 2119 Send(new FrameHostMsg_DidDisownOpener(routing_id_));
2120 } 2120 }
2121 2121
2122 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { 2122 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) {
2123 frameDetached(frame, false);
2124 }
2125
2126 void RenderFrameImpl::frameDetached(blink::WebFrame* frame,
2127 bool for_replacement) {
2123 // NOTE: This function is called on the frame that is being detached and not 2128 // NOTE: This function is called on the frame that is being detached and not
2124 // the parent frame. This is different from createChildFrame() which is 2129 // the parent frame. This is different from createChildFrame() which is
2125 // called on the parent frame. 2130 // called on the parent frame.
2126 CHECK(!is_detaching_); 2131 CHECK(!is_detaching_);
2127 DCHECK(!frame_ || frame_ == frame); 2132 DCHECK(!frame_ || frame_ == frame);
2128 2133
2129 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2134 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2130 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2135 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2131 FrameDetached(frame)); 2136 FrameDetached(frame));
2132 2137
2133 Send(new FrameHostMsg_Detach(routing_id_)); 2138 if (!for_replacement)
2139 Send(new FrameHostMsg_Detach(routing_id_));
2134 2140
2135 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2141 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2136 // sent before setting |is_detaching_| to true. 2142 // sent before setting |is_detaching_| to true.
2137 is_detaching_ = true; 2143 is_detaching_ = true;
2138 2144
2139 // We need to clean up subframes by removing them from the map and deleting 2145 // We need to clean up subframes by removing them from the map and deleting
2140 // the RenderFrameImpl. In contrast, the main frame is owned by its 2146 // the RenderFrameImpl. In contrast, the main frame is owned by its
2141 // containing RenderViewHost (so that they have the same lifetime), so only 2147 // containing RenderViewHost (so that they have the same lifetime), so only
2142 // removal from the map is needed and no deletion. 2148 // removal from the map is needed and no deletion.
2143 FrameMap::iterator it = g_frame_map.Get().find(frame); 2149 FrameMap::iterator it = g_frame_map.Get().find(frame);
2144 CHECK(it != g_frame_map.Get().end()); 2150 CHECK(it != g_frame_map.Get().end());
2145 CHECK_EQ(it->second, this); 2151 CHECK_EQ(it->second, this);
2146 g_frame_map.Get().erase(it); 2152 g_frame_map.Get().erase(it);
2147 2153
2148 if (is_subframe_) { 2154 if (is_subframe_) {
2149 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2155 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2150 switches::kSitePerProcess) && render_widget_) { 2156 switches::kSitePerProcess) && render_widget_) {
2151 render_widget_->UnregisterRenderFrame(this); 2157 render_widget_->UnregisterRenderFrame(this);
2152 } 2158 }
2153 frame->parent()->removeChild(frame); 2159
2160 if (!for_replacement)
2161 frame->parent()->removeChild(frame);
2154 } 2162 }
2155 2163
2156 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2164 // |frame| is invalid after here. Be sure to clear frame_ as well, since this
2157 // object may not be deleted immediately and other methods may try to access 2165 // object may not be deleted immediately and other methods may try to access
2158 // it. 2166 // it.
2159 frame->close(); 2167 frame->close();
2160 frame_ = nullptr; 2168 frame_ = nullptr;
2161 2169
2162 delete this; 2170 delete this;
2163 // Object is invalid after this point. 2171 // Object is invalid after this point.
(...skipping 2706 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 #elif defined(ENABLE_BROWSER_CDMS) 4878 #elif defined(ENABLE_BROWSER_CDMS)
4871 cdm_manager_, 4879 cdm_manager_,
4872 #endif 4880 #endif
4873 this); 4881 this);
4874 } 4882 }
4875 4883
4876 return cdm_factory_; 4884 return cdm_factory_;
4877 } 4885 }
4878 4886
4879 } // namespace content 4887 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698