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