OLD | NEW |
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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 // WasShown and WasHidden, separating page-level visibility from | 663 // WasShown and WasHidden, separating page-level visibility from |
664 // frame-level visibility. | 664 // frame-level visibility. |
665 render_frame->render_widget_->RegisterRenderFrame(render_frame); | 665 render_frame->render_widget_->RegisterRenderFrame(render_frame); |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 render_frame->Initialize(); | 669 render_frame->Initialize(); |
670 } | 670 } |
671 | 671 |
672 // static | 672 // static |
| 673 void RenderFrameImpl::DetachFrame(int routing_id) { |
| 674 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
| 675 // TODO(nasko): Investigate why it is possible to receive a FrameMsg_Detach |
| 676 // for a frame that is no longer alive. |
| 677 if (frame) { |
| 678 frame->set_is_browser_initiated_detach(); |
| 679 frame->GetWebFrame()->detach(); |
| 680 } |
| 681 } |
| 682 |
| 683 // static |
673 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { | 684 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
674 return RenderFrameImpl::FromWebFrame(web_frame); | 685 return RenderFrameImpl::FromWebFrame(web_frame); |
675 } | 686 } |
676 | 687 |
677 // static | 688 // static |
678 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { | 689 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { |
679 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); | 690 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); |
680 if (iter != g_frame_map.Get().end()) | 691 if (iter != g_frame_map.Get().end()) |
681 return iter->second; | 692 return iter->second; |
682 return NULL; | 693 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 736 } |
726 | 737 |
727 return nullptr; | 738 return nullptr; |
728 } | 739 } |
729 | 740 |
730 // RenderFrameImpl ---------------------------------------------------------- | 741 // RenderFrameImpl ---------------------------------------------------------- |
731 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 742 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
732 : frame_(NULL), | 743 : frame_(NULL), |
733 is_main_frame_(true), | 744 is_main_frame_(true), |
734 is_local_root_(false), | 745 is_local_root_(false), |
| 746 is_browser_initiated_detach_(false), |
735 render_view_(params.render_view->AsWeakPtr()), | 747 render_view_(params.render_view->AsWeakPtr()), |
736 routing_id_(params.routing_id), | 748 routing_id_(params.routing_id), |
737 is_swapped_out_(false), | 749 is_swapped_out_(false), |
738 render_frame_proxy_(NULL), | 750 render_frame_proxy_(NULL), |
739 is_detaching_(false), | 751 is_detaching_(false), |
740 proxy_routing_id_(MSG_ROUTING_NONE), | 752 proxy_routing_id_(MSG_ROUTING_NONE), |
741 #if defined(ENABLE_PLUGINS) | 753 #if defined(ENABLE_PLUGINS) |
742 plugin_power_saver_helper_(nullptr), | 754 plugin_power_saver_helper_(nullptr), |
743 #endif | 755 #endif |
744 cookie_jar_(this), | 756 cookie_jar_(this), |
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 // the parent frame. This is different from createChildFrame() which is | 2365 // the parent frame. This is different from createChildFrame() which is |
2354 // called on the parent frame. | 2366 // called on the parent frame. |
2355 CHECK(!is_detaching_); | 2367 CHECK(!is_detaching_); |
2356 DCHECK(!frame_ || frame_ == frame); | 2368 DCHECK(!frame_ || frame_ == frame); |
2357 | 2369 |
2358 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); | 2370 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); |
2359 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), | 2371 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), |
2360 FrameDetached(frame)); | 2372 FrameDetached(frame)); |
2361 | 2373 |
2362 // We only notify the browser process when the frame is being detached for | 2374 // We only notify the browser process when the frame is being detached for |
2363 // removal. If the frame is being detached for swap, we don't need to do this | 2375 // removal. If the frame is being detached for swap or the frame isn't fully |
2364 // since we are not modifiying the frame tree. | 2376 // initialized, we don't need to do this since we are not modifiying the frame |
2365 if (type == DetachType::Remove) | 2377 // tree. |
| 2378 if (!is_browser_initiated_detach_ && type == DetachType::Remove) |
2366 Send(new FrameHostMsg_Detach(routing_id_)); | 2379 Send(new FrameHostMsg_Detach(routing_id_)); |
2367 | 2380 |
2368 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | 2381 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
2369 // sent before setting |is_detaching_| to true. | 2382 // sent before setting |is_detaching_| to true. |
2370 is_detaching_ = true; | 2383 is_detaching_ = true; |
2371 | 2384 |
2372 // Clean up the associated RenderWidget for the frame, if there is one. | 2385 // Clean up the associated RenderWidget for the frame, if there is one. |
2373 if (render_widget_) { | 2386 if (render_widget_) { |
2374 render_widget_->UnregisterRenderFrame(this); | 2387 render_widget_->UnregisterRenderFrame(this); |
2375 render_widget_->CloseForFrame(); | 2388 render_widget_->CloseForFrame(); |
2376 } | 2389 } |
2377 | 2390 |
2378 // We need to clean up subframes by removing them from the map and deleting | 2391 // We need to clean up subframes by removing them from the map and deleting |
2379 // the RenderFrameImpl. In contrast, the main frame is owned by its | 2392 // the RenderFrameImpl. In contrast, the main frame is owned by its |
2380 // containing RenderViewHost (so that they have the same lifetime), so only | 2393 // containing RenderViewHost (so that they have the same lifetime), so only |
2381 // removal from the map is needed and no deletion. | 2394 // removal from the map is needed and no deletion. |
2382 FrameMap::iterator it = g_frame_map.Get().find(frame); | 2395 FrameMap::iterator it = g_frame_map.Get().find(frame); |
2383 CHECK(it != g_frame_map.Get().end()); | 2396 CHECK(it != g_frame_map.Get().end()); |
2384 CHECK_EQ(it->second, this); | 2397 CHECK_EQ(it->second, this); |
2385 g_frame_map.Get().erase(it); | 2398 g_frame_map.Get().erase(it); |
2386 | 2399 |
2387 // Only remove the frame from the renderer's frame tree if the frame is | 2400 // Only remove the frame from the renderer's frame tree if the frame is |
2388 // being detached for removal. In the case of a swap, the frame needs to | 2401 // being detached for removal. In the case of a swap, the frame needs to |
2389 // remain in the tree so WebFrame::swap() can replace it with the new frame. | 2402 // remain in the tree so WebFrame::swap() can replace it with the new frame. |
2390 if (!is_main_frame_ && type == DetachType::Remove) | 2403 // If the frame isn't fully initialized (e.g. deleting a pending RenderFrame) |
| 2404 // it is not linked into the frame tree, so it should not be removed. |
| 2405 if (!is_browser_initiated_detach_ && !is_main_frame_ && |
| 2406 type == DetachType::Remove) |
2391 frame->parent()->removeChild(frame); | 2407 frame->parent()->removeChild(frame); |
2392 | 2408 |
2393 // |frame| is invalid after here. Be sure to clear frame_ as well, since this | 2409 // |frame| is invalid after here. Be sure to clear frame_ as well, since this |
2394 // object may not be deleted immediately and other methods may try to access | 2410 // object may not be deleted immediately and other methods may try to access |
2395 // it. | 2411 // it. |
2396 frame->close(); | 2412 frame->close(); |
2397 frame_ = nullptr; | 2413 frame_ = nullptr; |
2398 | 2414 |
2399 delete this; | 2415 delete this; |
2400 // Object is invalid after this point. | 2416 // Object is invalid after this point. |
(...skipping 2886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5287 mojo::ServiceProviderPtr service_provider; | 5303 mojo::ServiceProviderPtr service_provider; |
5288 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 5304 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
5289 request->url = mojo::String::From(url); | 5305 request->url = mojo::String::From(url); |
5290 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), | 5306 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), |
5291 nullptr, nullptr, | 5307 nullptr, nullptr, |
5292 base::Bind(&OnGotContentHandlerID)); | 5308 base::Bind(&OnGotContentHandlerID)); |
5293 return service_provider.Pass(); | 5309 return service_provider.Pass(); |
5294 } | 5310 } |
5295 | 5311 |
5296 } // namespace content | 5312 } // namespace content |
OLD | NEW |