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 frame->set_is_browser_initiated_detach(); | |
676 frame->GetWebFrame()->detach(); | |
677 } | |
678 | |
679 // static | |
673 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { | 680 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
674 return RenderFrameImpl::FromWebFrame(web_frame); | 681 return RenderFrameImpl::FromWebFrame(web_frame); |
675 } | 682 } |
676 | 683 |
677 // static | 684 // static |
678 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { | 685 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { |
679 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); | 686 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); |
680 if (iter != g_frame_map.Get().end()) | 687 if (iter != g_frame_map.Get().end()) |
681 return iter->second; | 688 return iter->second; |
682 return NULL; | 689 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 } | 732 } |
726 | 733 |
727 return nullptr; | 734 return nullptr; |
728 } | 735 } |
729 | 736 |
730 // RenderFrameImpl ---------------------------------------------------------- | 737 // RenderFrameImpl ---------------------------------------------------------- |
731 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 738 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
732 : frame_(NULL), | 739 : frame_(NULL), |
733 is_main_frame_(true), | 740 is_main_frame_(true), |
734 is_local_root_(false), | 741 is_local_root_(false), |
742 is_browser_initiated_detach_(false), | |
735 render_view_(params.render_view->AsWeakPtr()), | 743 render_view_(params.render_view->AsWeakPtr()), |
736 routing_id_(params.routing_id), | 744 routing_id_(params.routing_id), |
737 is_swapped_out_(false), | 745 is_swapped_out_(false), |
738 render_frame_proxy_(NULL), | 746 render_frame_proxy_(NULL), |
739 is_detaching_(false), | 747 is_detaching_(false), |
740 proxy_routing_id_(MSG_ROUTING_NONE), | 748 proxy_routing_id_(MSG_ROUTING_NONE), |
741 #if defined(ENABLE_PLUGINS) | 749 #if defined(ENABLE_PLUGINS) |
742 plugin_power_saver_helper_(nullptr), | 750 plugin_power_saver_helper_(nullptr), |
743 #endif | 751 #endif |
744 cookie_jar_(this), | 752 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 | 2361 // the parent frame. This is different from createChildFrame() which is |
2354 // called on the parent frame. | 2362 // called on the parent frame. |
2355 CHECK(!is_detaching_); | 2363 CHECK(!is_detaching_); |
2356 DCHECK(!frame_ || frame_ == frame); | 2364 DCHECK(!frame_ || frame_ == frame); |
2357 | 2365 |
2358 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); | 2366 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); |
2359 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), | 2367 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), |
2360 FrameDetached(frame)); | 2368 FrameDetached(frame)); |
2361 | 2369 |
2362 // We only notify the browser process when the frame is being detached for | 2370 // 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 | 2371 // removal. If the frame is being detached for swap or the frame isn't fully |
Charlie Reis
2015/10/30 20:15:44
Is this comment change stale? I'm not sure how is
nasko
2015/11/02 22:48:51
I think the confusion came from my failure to upda
| |
2364 // since we are not modifiying the frame tree. | 2372 // initialized, we don't need to do this since we are not modifiying the frame |
2365 if (type == DetachType::Remove) | 2373 // tree. |
2374 if (!is_browser_initiated_detach_ && type == DetachType::Remove) | |
2366 Send(new FrameHostMsg_Detach(routing_id_)); | 2375 Send(new FrameHostMsg_Detach(routing_id_)); |
2367 | 2376 |
2368 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | 2377 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
2369 // sent before setting |is_detaching_| to true. | 2378 // sent before setting |is_detaching_| to true. |
2370 is_detaching_ = true; | 2379 is_detaching_ = true; |
2371 | 2380 |
2372 // Clean up the associated RenderWidget for the frame, if there is one. | 2381 // Clean up the associated RenderWidget for the frame, if there is one. |
2373 if (render_widget_) { | 2382 if (render_widget_) { |
2374 render_widget_->UnregisterRenderFrame(this); | 2383 render_widget_->UnregisterRenderFrame(this); |
2375 render_widget_->CloseForFrame(); | 2384 render_widget_->CloseForFrame(); |
2376 } | 2385 } |
2377 | 2386 |
2378 // We need to clean up subframes by removing them from the map and deleting | 2387 // 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 | 2388 // the RenderFrameImpl. In contrast, the main frame is owned by its |
2380 // containing RenderViewHost (so that they have the same lifetime), so only | 2389 // containing RenderViewHost (so that they have the same lifetime), so only |
2381 // removal from the map is needed and no deletion. | 2390 // removal from the map is needed and no deletion. |
2382 FrameMap::iterator it = g_frame_map.Get().find(frame); | 2391 FrameMap::iterator it = g_frame_map.Get().find(frame); |
2383 CHECK(it != g_frame_map.Get().end()); | 2392 CHECK(it != g_frame_map.Get().end()); |
2384 CHECK_EQ(it->second, this); | 2393 CHECK_EQ(it->second, this); |
2385 g_frame_map.Get().erase(it); | 2394 g_frame_map.Get().erase(it); |
2386 | 2395 |
2387 // Only remove the frame from the renderer's frame tree if the frame is | 2396 // 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 | 2397 // 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. | 2398 // remain in the tree so WebFrame::swap() can replace it with the new frame. |
2390 if (!is_main_frame_ && type == DetachType::Remove) | 2399 // If the frame isn't fully initialized (e.g. deleting a pending RenderFrame) |
2400 // it is not linked into the frame tree, so it should not be removed. | |
2401 if (!is_browser_initiated_detach_ && !is_main_frame_ && | |
Charlie Reis
2015/10/30 20:15:44
The name is confusing here as well. Whether the f
nasko
2015/11/02 22:48:51
I think this isn't correct usage here actually. Th
| |
2402 type == DetachType::Remove) | |
2391 frame->parent()->removeChild(frame); | 2403 frame->parent()->removeChild(frame); |
2392 | 2404 |
2393 // |frame| is invalid after here. Be sure to clear frame_ as well, since this | 2405 // |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 | 2406 // object may not be deleted immediately and other methods may try to access |
2395 // it. | 2407 // it. |
2396 frame->close(); | 2408 frame->close(); |
2397 frame_ = nullptr; | 2409 frame_ = nullptr; |
2398 | 2410 |
2399 delete this; | 2411 delete this; |
2400 // Object is invalid after this point. | 2412 // Object is invalid after this point. |
(...skipping 2886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5287 mojo::ServiceProviderPtr service_provider; | 5299 mojo::ServiceProviderPtr service_provider; |
5288 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 5300 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
5289 request->url = mojo::String::From(url); | 5301 request->url = mojo::String::From(url); |
5290 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), | 5302 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), |
5291 nullptr, nullptr, | 5303 nullptr, nullptr, |
5292 base::Bind(&OnGotContentHandlerID)); | 5304 base::Bind(&OnGotContentHandlerID)); |
5293 return service_provider.Pass(); | 5305 return service_provider.Pass(); |
5294 } | 5306 } |
5295 | 5307 |
5296 } // namespace content | 5308 } // namespace content |
OLD | NEW |