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

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: adding comments 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(
696 blink::WebRemoteFrameClient::DetachType::Remove);
696 } 697 }
697 698
698 // Ensure the RenderView doesn't point to this object, once it is destroyed. 699 // Ensure the RenderView doesn't point to this object, once it is destroyed.
699 CHECK_EQ(render_view_->main_render_frame_, this); 700 CHECK_EQ(render_view_->main_render_frame_, this);
700 render_view_->main_render_frame_ = nullptr; 701 render_view_->main_render_frame_ = nullptr;
701 } 702 }
702 703
703 render_view_->UnregisterRenderFrame(this); 704 render_view_->UnregisterRenderFrame(this);
704 g_routing_id_frame_map.Get().erase(routing_id_); 705 g_routing_id_frame_map.Get().erase(routing_id_);
705 RenderThread::Get()->RemoveRoute(routing_id_); 706 RenderThread::Get()->RemoveRoute(routing_id_);
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 // opener after hearing about it from the browser, and the browser does not 2121 // opener after hearing about it from the browser, and the browser does not
2121 // (yet) care about subframe openers. 2122 // (yet) care about subframe openers.
2122 if (is_swapped_out_ || frame->parent()) 2123 if (is_swapped_out_ || frame->parent())
2123 return; 2124 return;
2124 2125
2125 // Notify WebContents and all its swapped out RenderViews. 2126 // Notify WebContents and all its swapped out RenderViews.
2126 Send(new FrameHostMsg_DidDisownOpener(routing_id_)); 2127 Send(new FrameHostMsg_DidDisownOpener(routing_id_));
2127 } 2128 }
2128 2129
2129 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { 2130 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) {
2131 frameDetached(frame, DetachType::Remove);
2132 }
2133
2134 void RenderFrameImpl::frameDetached(blink::WebFrame* frame, DetachType type) {
2130 // NOTE: This function is called on the frame that is being detached and not 2135 // NOTE: This function is called on the frame that is being detached and not
2131 // the parent frame. This is different from createChildFrame() which is 2136 // the parent frame. This is different from createChildFrame() which is
2132 // called on the parent frame. 2137 // called on the parent frame.
2133 CHECK(!is_detaching_); 2138 CHECK(!is_detaching_);
2134 DCHECK(!frame_ || frame_ == frame); 2139 DCHECK(!frame_ || frame_ == frame);
2135 2140
2136 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2141 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2137 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2142 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2138 FrameDetached(frame)); 2143 FrameDetached(frame));
2139 2144
2140 Send(new FrameHostMsg_Detach(routing_id_)); 2145 // We only notify the browser process when the frame is being detached for
2146 // removal. If the frame is being detached for swap, we don't need to do this
2147 // since we are not modifiying the frame tree.
2148 if (type == DetachType::Remove)
2149 Send(new FrameHostMsg_Detach(routing_id_));
2141 2150
2142 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2151 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2143 // sent before setting |is_detaching_| to true. 2152 // sent before setting |is_detaching_| to true.
2144 is_detaching_ = true; 2153 is_detaching_ = true;
2145 2154
2146 // We need to clean up subframes by removing them from the map and deleting 2155 // We need to clean up subframes by removing them from the map and deleting
2147 // the RenderFrameImpl. In contrast, the main frame is owned by its 2156 // the RenderFrameImpl. In contrast, the main frame is owned by its
2148 // containing RenderViewHost (so that they have the same lifetime), so only 2157 // containing RenderViewHost (so that they have the same lifetime), so only
2149 // removal from the map is needed and no deletion. 2158 // removal from the map is needed and no deletion.
2150 FrameMap::iterator it = g_frame_map.Get().find(frame); 2159 FrameMap::iterator it = g_frame_map.Get().find(frame);
2151 CHECK(it != g_frame_map.Get().end()); 2160 CHECK(it != g_frame_map.Get().end());
2152 CHECK_EQ(it->second, this); 2161 CHECK_EQ(it->second, this);
2153 g_frame_map.Get().erase(it); 2162 g_frame_map.Get().erase(it);
2154 2163
2155 if (is_subframe_) { 2164 if (is_subframe_) {
2156 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2165 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2157 switches::kSitePerProcess) && render_widget_) { 2166 switches::kSitePerProcess) && render_widget_) {
2158 render_widget_->UnregisterRenderFrame(this); 2167 render_widget_->UnregisterRenderFrame(this);
2159 } 2168 }
2160 frame->parent()->removeChild(frame); 2169
2170 // Only remove the frame from the renderer's frame tree if the frame is
2171 // being detached for removal. For swaps, WebFrame::swap already takes care
2172 // of replacing the frame with a RemoteFrame.
2173 if (type == DetachType::Remove)
2174 frame->parent()->removeChild(frame);
2161 } 2175 }
2162 2176
2163 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2177 // |frame| is invalid after here. Be sure to clear frame_ as well, since this
2164 // object may not be deleted immediately and other methods may try to access 2178 // object may not be deleted immediately and other methods may try to access
2165 // it. 2179 // it.
2166 frame->close(); 2180 frame->close();
2167 frame_ = nullptr; 2181 frame_ = nullptr;
2168 2182
2169 delete this; 2183 delete this;
2170 // Object is invalid after this point. 2184 // Object is invalid after this point.
(...skipping 2713 matching lines...) Expand 10 before | Expand all | Expand 10 after
4884 #elif defined(ENABLE_BROWSER_CDMS) 4898 #elif defined(ENABLE_BROWSER_CDMS)
4885 cdm_manager_, 4899 cdm_manager_,
4886 #endif 4900 #endif
4887 this); 4901 this);
4888 } 4902 }
4889 4903
4890 return cdm_factory_; 4904 return cdm_factory_;
4891 } 4905 }
4892 4906
4893 } // namespace content 4907 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698