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

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

Issue 2628133002: When a proxy is detached, immediately delete its associated provisional frame. (Closed)
Patch Set: Remove (hopefully unnecessary) null check Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_proxy.h" 5 #include "content/renderer/render_frame_proxy.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 } // namespace 67 } // namespace
68 68
69 // static 69 // static
70 RenderFrameProxy* RenderFrameProxy::CreateProxyToReplaceFrame( 70 RenderFrameProxy* RenderFrameProxy::CreateProxyToReplaceFrame(
71 RenderFrameImpl* frame_to_replace, 71 RenderFrameImpl* frame_to_replace,
72 int routing_id, 72 int routing_id,
73 blink::WebTreeScopeType scope) { 73 blink::WebTreeScopeType scope) {
74 CHECK_NE(routing_id, MSG_ROUTING_NONE); 74 CHECK_NE(routing_id, MSG_ROUTING_NONE);
75 75
76 std::unique_ptr<RenderFrameProxy> proxy( 76 std::unique_ptr<RenderFrameProxy> proxy(new RenderFrameProxy(routing_id));
77 new RenderFrameProxy(routing_id, frame_to_replace->GetRoutingID()));
78 77
79 // When a RenderFrame is replaced by a RenderProxy, the WebRemoteFrame should 78 // When a RenderFrame is replaced by a RenderProxy, the WebRemoteFrame should
80 // always come from WebRemoteFrame::create and a call to WebFrame::swap must 79 // always come from WebRemoteFrame::create and a call to WebFrame::swap must
81 // follow later. 80 // follow later.
82 blink::WebRemoteFrame* web_frame = 81 blink::WebRemoteFrame* web_frame =
83 blink::WebRemoteFrame::create(scope, proxy.get()); 82 blink::WebRemoteFrame::create(scope, proxy.get());
84 83
85 // If frame_to_replace has a RenderFrameProxy parent, then its 84 // If frame_to_replace has a RenderFrameProxy parent, then its
86 // RenderWidget will be destroyed along with it, so the new 85 // RenderWidget will be destroyed along with it, so the new
87 // RenderFrameProxy uses its parent's RenderWidget. 86 // RenderFrameProxy uses its parent's RenderWidget.
(...skipping 17 matching lines...) Expand all
105 RenderFrameProxy* parent = nullptr; 104 RenderFrameProxy* parent = nullptr;
106 if (parent_routing_id != MSG_ROUTING_NONE) { 105 if (parent_routing_id != MSG_ROUTING_NONE) {
107 parent = RenderFrameProxy::FromRoutingID(parent_routing_id); 106 parent = RenderFrameProxy::FromRoutingID(parent_routing_id);
108 // It is possible that the parent proxy has been detached in this renderer 107 // It is possible that the parent proxy has been detached in this renderer
109 // process, just as the parent's real frame was creating this child frame. 108 // process, just as the parent's real frame was creating this child frame.
110 // In this case, do not create the proxy. See https://crbug.com/568670. 109 // In this case, do not create the proxy. See https://crbug.com/568670.
111 if (!parent) 110 if (!parent)
112 return nullptr; 111 return nullptr;
113 } 112 }
114 113
115 std::unique_ptr<RenderFrameProxy> proxy( 114 std::unique_ptr<RenderFrameProxy> proxy(new RenderFrameProxy(routing_id));
116 new RenderFrameProxy(routing_id, MSG_ROUTING_NONE));
117 RenderViewImpl* render_view = nullptr; 115 RenderViewImpl* render_view = nullptr;
118 RenderWidget* render_widget = nullptr; 116 RenderWidget* render_widget = nullptr;
119 blink::WebRemoteFrame* web_frame = nullptr; 117 blink::WebRemoteFrame* web_frame = nullptr;
120 118
121 if (!parent) { 119 if (!parent) {
122 // Create a top level WebRemoteFrame. 120 // Create a top level WebRemoteFrame.
123 render_view = RenderViewImpl::FromRoutingID(render_view_routing_id); 121 render_view = RenderViewImpl::FromRoutingID(render_view_routing_id);
124 web_frame = blink::WebRemoteFrame::create(replicated_state.scope, 122 web_frame = blink::WebRemoteFrame::create(replicated_state.scope,
125 proxy.get(), opener); 123 proxy.get(), opener);
126 render_view->webview()->setMainFrame(web_frame); 124 render_view->webview()->setMainFrame(web_frame);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 RenderFrameProxy* RenderFrameProxy::FromWebFrame(blink::WebFrame* web_frame) { 170 RenderFrameProxy* RenderFrameProxy::FromWebFrame(blink::WebFrame* web_frame) {
173 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); 171 FrameMap::iterator iter = g_frame_map.Get().find(web_frame);
174 if (iter != g_frame_map.Get().end()) { 172 if (iter != g_frame_map.Get().end()) {
175 RenderFrameProxy* proxy = iter->second; 173 RenderFrameProxy* proxy = iter->second;
176 DCHECK_EQ(web_frame, proxy->web_frame()); 174 DCHECK_EQ(web_frame, proxy->web_frame());
177 return proxy; 175 return proxy;
178 } 176 }
179 return NULL; 177 return NULL;
180 } 178 }
181 179
182 RenderFrameProxy::RenderFrameProxy(int routing_id, int frame_routing_id) 180 RenderFrameProxy::RenderFrameProxy(int routing_id)
183 : routing_id_(routing_id), 181 : routing_id_(routing_id),
184 frame_routing_id_(frame_routing_id), 182 provisional_frame_routing_id_(MSG_ROUTING_NONE),
185 web_frame_(nullptr), 183 web_frame_(nullptr),
186 render_view_(nullptr), 184 render_view_(nullptr),
187 render_widget_(nullptr) { 185 render_widget_(nullptr) {
188 std::pair<RoutingIDProxyMap::iterator, bool> result = 186 std::pair<RoutingIDProxyMap::iterator, bool> result =
189 g_routing_id_proxy_map.Get().insert(std::make_pair(routing_id_, this)); 187 g_routing_id_proxy_map.Get().insert(std::make_pair(routing_id_, this));
190 CHECK(result.second) << "Inserting a duplicate item."; 188 CHECK(result.second) << "Inserting a duplicate item.";
191 RenderThread::Get()->AddRoute(routing_id_, this); 189 RenderThread::Get()->AddRoute(routing_id_, this);
192 } 190 }
193 191
194 RenderFrameProxy::~RenderFrameProxy() { 192 RenderFrameProxy::~RenderFrameProxy() {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (type == DetachType::Remove && web_frame_->parent()) { 410 if (type == DetachType::Remove && web_frame_->parent()) {
413 web_frame_->parent()->removeChild(web_frame_); 411 web_frame_->parent()->removeChild(web_frame_);
414 412
415 // Let the browser process know this subframe is removed, so that it is 413 // Let the browser process know this subframe is removed, so that it is
416 // destroyed in its current process. 414 // destroyed in its current process.
417 Send(new FrameHostMsg_Detach(routing_id_)); 415 Send(new FrameHostMsg_Detach(routing_id_));
418 } 416 }
419 417
420 web_frame_->close(); 418 web_frame_->close();
421 419
420 // If this proxy was associated with a provisional RenderFrame, and we're not
421 // in the process of swapping with it, clean it up as well.
422 if (type == DetachType::Remove &&
423 provisional_frame_routing_id_ != MSG_ROUTING_NONE) {
424 RenderFrameImpl* provisional_frame =
425 RenderFrameImpl::FromRoutingID(provisional_frame_routing_id_);
426 // |provisional_frame| should always exist. If it was deleted via
427 // FrameMsg_Delete right before this proxy was removed,
428 // RenderFrameImpl::frameDetached would've cleared this proxy's
429 // |provisional_frame_routing_id_| and we wouldn't get here.
430 CHECK(provisional_frame);
431 provisional_frame->GetWebFrame()->detach();
432 }
433
422 // Remove the entry in the WebFrame->RenderFrameProxy map, as the |web_frame_| 434 // Remove the entry in the WebFrame->RenderFrameProxy map, as the |web_frame_|
423 // is no longer valid. 435 // is no longer valid.
424 FrameMap::iterator it = g_frame_map.Get().find(web_frame_); 436 FrameMap::iterator it = g_frame_map.Get().find(web_frame_);
425 CHECK(it != g_frame_map.Get().end()); 437 CHECK(it != g_frame_map.Get().end());
426 CHECK_EQ(it->second, this); 438 CHECK_EQ(it->second, this);
427 g_frame_map.Get().erase(it); 439 g_frame_map.Get().erase(it);
428 440
429 web_frame_ = nullptr; 441 web_frame_ = nullptr;
430 442
431 delete this; 443 delete this;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 blink::WebLocalFrame* source) { 532 blink::WebLocalFrame* source) {
521 int source_routing_id = RenderFrameImpl::FromWebFrame(source)->GetRoutingID(); 533 int source_routing_id = RenderFrameImpl::FromWebFrame(source)->GetRoutingID();
522 Send(new FrameHostMsg_AdvanceFocus(routing_id_, type, source_routing_id)); 534 Send(new FrameHostMsg_AdvanceFocus(routing_id_, type, source_routing_id));
523 } 535 }
524 536
525 void RenderFrameProxy::frameFocused() { 537 void RenderFrameProxy::frameFocused() {
526 Send(new FrameHostMsg_FrameFocused(routing_id_)); 538 Send(new FrameHostMsg_FrameFocused(routing_id_));
527 } 539 }
528 540
529 } // namespace 541 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698