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

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: print 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 118 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
119 #include "net/http/http_util.h" 119 #include "net/http/http_util.h"
120 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" 120 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
121 #include "third_party/WebKit/public/platform/WebString.h" 121 #include "third_party/WebKit/public/platform/WebString.h"
122 #include "third_party/WebKit/public/platform/WebURL.h" 122 #include "third_party/WebKit/public/platform/WebURL.h"
123 #include "third_party/WebKit/public/platform/WebURLError.h" 123 #include "third_party/WebKit/public/platform/WebURLError.h"
124 #include "third_party/WebKit/public/platform/WebURLResponse.h" 124 #include "third_party/WebKit/public/platform/WebURLResponse.h"
125 #include "third_party/WebKit/public/platform/WebVector.h" 125 #include "third_party/WebKit/public/platform/WebVector.h"
126 #include "third_party/WebKit/public/web/WebColorSuggestion.h" 126 #include "third_party/WebKit/public/web/WebColorSuggestion.h"
127 #include "third_party/WebKit/public/web/WebDocument.h" 127 #include "third_party/WebKit/public/web/WebDocument.h"
128 #include "third_party/WebKit/public/web/WebFrameClient.h"
128 #include "third_party/WebKit/public/web/WebFrameWidget.h" 129 #include "third_party/WebKit/public/web/WebFrameWidget.h"
129 #include "third_party/WebKit/public/web/WebGlyphCache.h" 130 #include "third_party/WebKit/public/web/WebGlyphCache.h"
130 #include "third_party/WebKit/public/web/WebKit.h" 131 #include "third_party/WebKit/public/web/WebKit.h"
131 #include "third_party/WebKit/public/web/WebLocalFrame.h" 132 #include "third_party/WebKit/public/web/WebLocalFrame.h"
132 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" 133 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
133 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 134 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
134 #include "third_party/WebKit/public/web/WebPlugin.h" 135 #include "third_party/WebKit/public/web/WebPlugin.h"
135 #include "third_party/WebKit/public/web/WebPluginParams.h" 136 #include "third_party/WebKit/public/web/WebPluginParams.h"
136 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h" 137 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h"
137 #include "third_party/WebKit/public/web/WebRange.h" 138 #include "third_party/WebKit/public/web/WebRange.h"
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (contains_media_player_) 686 if (contains_media_player_)
686 render_view_->UnregisterVideoHoleFrame(this); 687 render_view_->UnregisterVideoHoleFrame(this);
687 #endif 688 #endif
688 689
689 if (!is_subframe_) { 690 if (!is_subframe_) {
690 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is 691 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is
691 // the main frame. Ensure it is deleted along with this object. 692 // the main frame. Ensure it is deleted along with this object.
692 if (render_frame_proxy_) { 693 if (render_frame_proxy_) {
693 // The following method calls back into this object and clears 694 // The following method calls back into this object and clears
694 // |render_frame_proxy_|. 695 // |render_frame_proxy_|.
695 render_frame_proxy_->frameDetached(); 696 render_frame_proxy_->frameDetached(blink::WebDetachReason::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 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 2114 // opener after hearing about it from the browser, and the browser does not
2114 // (yet) care about subframe openers. 2115 // (yet) care about subframe openers.
2115 if (is_swapped_out_ || frame->parent()) 2116 if (is_swapped_out_ || frame->parent())
2116 return; 2117 return;
2117 2118
2118 // Notify WebContents and all its swapped out RenderViews. 2119 // Notify WebContents and all its swapped out RenderViews.
2119 Send(new FrameHostMsg_DidDisownOpener(routing_id_)); 2120 Send(new FrameHostMsg_DidDisownOpener(routing_id_));
2120 } 2121 }
2121 2122
2122 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { 2123 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) {
2124 frameDetached(frame, blink::WebDetachReason::Remove);
2125 }
2126
2127 void RenderFrameImpl::frameDetached(blink::WebFrame* frame,
2128 blink::WebDetachReason reason) {
2123 // NOTE: This function is called on the frame that is being detached and not 2129 // 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 2130 // the parent frame. This is different from createChildFrame() which is
2125 // called on the parent frame. 2131 // called on the parent frame.
2126 CHECK(!is_detaching_); 2132 CHECK(!is_detaching_);
2127 DCHECK(!frame_ || frame_ == frame); 2133 DCHECK(!frame_ || frame_ == frame);
2128 2134
2129 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); 2135 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached());
2130 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2136 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2131 FrameDetached(frame)); 2137 FrameDetached(frame));
2132 2138
2133 Send(new FrameHostMsg_Detach(routing_id_)); 2139 if (reason == blink::WebDetachReason::Remove)
2140 Send(new FrameHostMsg_Detach(routing_id_));
2134 2141
2135 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be 2142 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be
2136 // sent before setting |is_detaching_| to true. 2143 // sent before setting |is_detaching_| to true.
2137 is_detaching_ = true; 2144 is_detaching_ = true;
2138 2145
2139 // We need to clean up subframes by removing them from the map and deleting 2146 // 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 2147 // the RenderFrameImpl. In contrast, the main frame is owned by its
2141 // containing RenderViewHost (so that they have the same lifetime), so only 2148 // containing RenderViewHost (so that they have the same lifetime), so only
2142 // removal from the map is needed and no deletion. 2149 // removal from the map is needed and no deletion.
2143 FrameMap::iterator it = g_frame_map.Get().find(frame); 2150 FrameMap::iterator it = g_frame_map.Get().find(frame);
2144 CHECK(it != g_frame_map.Get().end()); 2151 CHECK(it != g_frame_map.Get().end());
2145 CHECK_EQ(it->second, this); 2152 CHECK_EQ(it->second, this);
2146 g_frame_map.Get().erase(it); 2153 g_frame_map.Get().erase(it);
2147 2154
2148 if (is_subframe_) { 2155 if (is_subframe_) {
2149 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2156 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2150 switches::kSitePerProcess) && render_widget_) { 2157 switches::kSitePerProcess) && render_widget_) {
2151 render_widget_->UnregisterRenderFrame(this); 2158 render_widget_->UnregisterRenderFrame(this);
2152 } 2159 }
2153 frame->parent()->removeChild(frame); 2160
2161 if (reason == blink::WebDetachReason::Remove)
2162 frame->parent()->removeChild(frame);
2154 } 2163 }
2155 2164
2156 // |frame| is invalid after here. Be sure to clear frame_ as well, since this 2165 // |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 2166 // object may not be deleted immediately and other methods may try to access
2158 // it. 2167 // it.
2159 frame->close(); 2168 frame->close();
2160 frame_ = nullptr; 2169 frame_ = nullptr;
2161 2170
2162 delete this; 2171 delete this;
2163 // Object is invalid after this point. 2172 // Object is invalid after this point.
(...skipping 2706 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 #elif defined(ENABLE_BROWSER_CDMS) 4879 #elif defined(ENABLE_BROWSER_CDMS)
4871 cdm_manager_, 4880 cdm_manager_,
4872 #endif 4881 #endif
4873 this); 4882 this);
4874 } 4883 }
4875 4884
4876 return cdm_factory_; 4885 return cdm_factory_;
4877 } 4886 }
4878 4887
4879 } // namespace content 4888 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698