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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 // WasShown and WasHidden, separating page-level visibility from | 664 // WasShown and WasHidden, separating page-level visibility from |
665 // frame-level visibility. | 665 // frame-level visibility. |
666 render_frame->render_widget_->RegisterRenderFrame(render_frame); | 666 render_frame->render_widget_->RegisterRenderFrame(render_frame); |
667 } | 667 } |
668 } | 668 } |
669 | 669 |
670 render_frame->Initialize(); | 670 render_frame->Initialize(); |
671 } | 671 } |
672 | 672 |
673 // static | 673 // static |
674 void RenderFrameImpl::DetachFrame(int routing_id) { | |
dcheng
2015/11/03 04:22:54
Is it worth DCHECKing our current limitations? For
nasko
2015/11/03 17:59:08
Done.
Charlie Reis
2015/11/04 21:28:30
I don't see the new DCHECK. I guess it doesn't ap
| |
675 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); | |
676 frame->set_in_browser_initiated_detach(); | |
677 frame->GetWebFrame()->detach(); | |
678 } | |
679 | |
680 // static | |
674 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { | 681 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
675 return RenderFrameImpl::FromWebFrame(web_frame); | 682 return RenderFrameImpl::FromWebFrame(web_frame); |
676 } | 683 } |
677 | 684 |
678 // static | 685 // static |
679 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { | 686 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { |
680 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); | 687 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); |
681 if (iter != g_frame_map.Get().end()) | 688 if (iter != g_frame_map.Get().end()) |
682 return iter->second; | 689 return iter->second; |
683 return NULL; | 690 return NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 } | 733 } |
727 | 734 |
728 return nullptr; | 735 return nullptr; |
729 } | 736 } |
730 | 737 |
731 // RenderFrameImpl ---------------------------------------------------------- | 738 // RenderFrameImpl ---------------------------------------------------------- |
732 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 739 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
733 : frame_(NULL), | 740 : frame_(NULL), |
734 is_main_frame_(true), | 741 is_main_frame_(true), |
735 is_local_root_(false), | 742 is_local_root_(false), |
743 in_browser_initiated_detach_(false), | |
736 render_view_(params.render_view->AsWeakPtr()), | 744 render_view_(params.render_view->AsWeakPtr()), |
737 routing_id_(params.routing_id), | 745 routing_id_(params.routing_id), |
738 is_swapped_out_(false), | 746 is_swapped_out_(false), |
739 render_frame_proxy_(NULL), | 747 render_frame_proxy_(NULL), |
740 is_detaching_(false), | 748 is_detaching_(false), |
741 proxy_routing_id_(MSG_ROUTING_NONE), | 749 proxy_routing_id_(MSG_ROUTING_NONE), |
742 #if defined(ENABLE_PLUGINS) | 750 #if defined(ENABLE_PLUGINS) |
743 plugin_power_saver_helper_(nullptr), | 751 plugin_power_saver_helper_(nullptr), |
744 #endif | 752 #endif |
745 cookie_jar_(this), | 753 cookie_jar_(this), |
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2362 // the parent frame. This is different from createChildFrame() which is | 2370 // the parent frame. This is different from createChildFrame() which is |
2363 // called on the parent frame. | 2371 // called on the parent frame. |
2364 CHECK(!is_detaching_); | 2372 CHECK(!is_detaching_); |
2365 DCHECK(!frame_ || frame_ == frame); | 2373 DCHECK(!frame_ || frame_ == frame); |
2366 | 2374 |
2367 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); | 2375 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); |
2368 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), | 2376 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), |
2369 FrameDetached(frame)); | 2377 FrameDetached(frame)); |
2370 | 2378 |
2371 // We only notify the browser process when the frame is being detached for | 2379 // We only notify the browser process when the frame is being detached for |
2372 // removal. If the frame is being detached for swap, we don't need to do this | 2380 // removal and it was initiated from the renderer process. |
2373 // since we are not modifiying the frame tree. | 2381 if (!in_browser_initiated_detach_ && type == DetachType::Remove) |
2374 if (type == DetachType::Remove) | |
2375 Send(new FrameHostMsg_Detach(routing_id_)); | 2382 Send(new FrameHostMsg_Detach(routing_id_)); |
2376 | 2383 |
2377 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | 2384 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
2378 // sent before setting |is_detaching_| to true. | 2385 // sent before setting |is_detaching_| to true. |
2379 is_detaching_ = true; | 2386 is_detaching_ = true; |
2380 | 2387 |
2381 // Clean up the associated RenderWidget for the frame, if there is one. | 2388 // Clean up the associated RenderWidget for the frame, if there is one. |
2382 if (render_widget_) { | 2389 if (render_widget_) { |
2383 render_widget_->UnregisterRenderFrame(this); | 2390 render_widget_->UnregisterRenderFrame(this); |
2384 render_widget_->CloseForFrame(); | 2391 render_widget_->CloseForFrame(); |
2385 } | 2392 } |
2386 | 2393 |
2387 // We need to clean up subframes by removing them from the map and deleting | 2394 // We need to clean up subframes by removing them from the map and deleting |
2388 // the RenderFrameImpl. In contrast, the main frame is owned by its | 2395 // the RenderFrameImpl. In contrast, the main frame is owned by its |
2389 // containing RenderViewHost (so that they have the same lifetime), so only | 2396 // containing RenderViewHost (so that they have the same lifetime), so only |
2390 // removal from the map is needed and no deletion. | 2397 // removal from the map is needed and no deletion. |
2391 FrameMap::iterator it = g_frame_map.Get().find(frame); | 2398 FrameMap::iterator it = g_frame_map.Get().find(frame); |
2392 CHECK(it != g_frame_map.Get().end()); | 2399 CHECK(it != g_frame_map.Get().end()); |
2393 CHECK_EQ(it->second, this); | 2400 CHECK_EQ(it->second, this); |
2394 g_frame_map.Get().erase(it); | 2401 g_frame_map.Get().erase(it); |
2395 | 2402 |
2396 // Only remove the frame from the renderer's frame tree if the frame is | 2403 // Only remove the frame from the renderer's frame tree if the frame is |
2397 // being detached for removal. In the case of a swap, the frame needs to | 2404 // being detached for removal and it is inserted in the set of child frames. |
2398 // remain in the tree so WebFrame::swap() can replace it with the new frame. | 2405 // In the case of a swap, the frame needs to remain in the tree so |
2399 if (!is_main_frame_ && type == DetachType::Remove) | 2406 // WebFrame::swap() can replace it with the new frame. |
2400 frame->parent()->removeChild(frame); | 2407 if (!is_main_frame_ && type == DetachType::Remove) { |
2408 for (WebFrame* child = frame->parent()->firstChild(); child; | |
dcheng
2015/11/03 04:22:53
Is there no heuristic we can use inside //content
nasko
2015/11/03 17:59:08
Well, content/ is now in charge of maintaining the
| |
2409 child = child->nextSibling()) { | |
2410 if (child == frame) { | |
2411 frame->parent()->removeChild(frame); | |
2412 break; | |
2413 } | |
2414 } | |
2415 } | |
2401 | 2416 |
2402 // |frame| is invalid after here. Be sure to clear frame_ as well, since this | 2417 // |frame| is invalid after here. Be sure to clear frame_ as well, since this |
2403 // object may not be deleted immediately and other methods may try to access | 2418 // object may not be deleted immediately and other methods may try to access |
2404 // it. | 2419 // it. |
2405 frame->close(); | 2420 frame->close(); |
2406 frame_ = nullptr; | 2421 frame_ = nullptr; |
2407 | 2422 |
2408 delete this; | 2423 delete this; |
2409 // Object is invalid after this point. | 2424 // Object is invalid after this point. |
2410 } | 2425 } |
(...skipping 2884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5295 mojo::ServiceProviderPtr service_provider; | 5310 mojo::ServiceProviderPtr service_provider; |
5296 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 5311 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
5297 request->url = mojo::String::From(url); | 5312 request->url = mojo::String::From(url); |
5298 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), | 5313 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), |
5299 nullptr, nullptr, | 5314 nullptr, nullptr, |
5300 base::Bind(&OnGotContentHandlerID)); | 5315 base::Bind(&OnGotContentHandlerID)); |
5301 return service_provider.Pass(); | 5316 return service_provider.Pass(); |
5302 } | 5317 } |
5303 | 5318 |
5304 } // namespace content | 5319 } // namespace content |
OLD | NEW |