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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 if (previous_sibling_proxy) | 692 if (previous_sibling_proxy) |
693 previous_sibling_web_frame = previous_sibling_proxy->web_frame(); | 693 previous_sibling_web_frame = previous_sibling_proxy->web_frame(); |
694 | 694 |
695 // Create the RenderFrame and WebLocalFrame, linking the two. | 695 // Create the RenderFrame and WebLocalFrame, linking the two. |
696 render_frame = | 696 render_frame = |
697 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id); | 697 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id); |
698 web_frame = parent_web_frame->createLocalChild( | 698 web_frame = parent_web_frame->createLocalChild( |
699 replicated_state.scope, WebString::fromUTF8(replicated_state.name), | 699 replicated_state.scope, WebString::fromUTF8(replicated_state.name), |
700 replicated_state.sandbox_flags, render_frame, | 700 replicated_state.sandbox_flags, render_frame, |
701 previous_sibling_web_frame, frame_owner_properties); | 701 previous_sibling_web_frame, frame_owner_properties); |
702 // Since the RenderFrame is created and inserted into the frame tree in the | |
703 // above call to createLocalChild, ensure the state is set properly. | |
Charlie Reis
2015/12/11 00:03:17
nit: Drop "Since" and "ensure the state is set pro
nasko
2015/12/11 00:47:25
Done.
| |
704 render_frame->in_frame_tree_ = true; | |
nasko
2015/12/10 21:26:52
Charlie: This is newly added code, which was promp
Charlie Reis
2015/12/11 00:03:17
Acknowledged.
| |
702 } else { | 705 } else { |
703 RenderFrameProxy* proxy = | 706 RenderFrameProxy* proxy = |
704 RenderFrameProxy::FromRoutingID(proxy_routing_id); | 707 RenderFrameProxy::FromRoutingID(proxy_routing_id); |
705 CHECK(proxy); | 708 CHECK(proxy); |
706 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); | 709 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); |
707 render_frame->proxy_routing_id_ = proxy_routing_id; | 710 render_frame->proxy_routing_id_ = proxy_routing_id; |
708 web_frame = blink::WebLocalFrame::createProvisional( | 711 web_frame = blink::WebLocalFrame::createProvisional( |
709 render_frame, proxy->web_frame(), replicated_state.sandbox_flags, | 712 render_frame, proxy->web_frame(), replicated_state.sandbox_flags, |
710 frame_owner_properties); | 713 frame_owner_properties); |
711 } | 714 } |
(...skipping 17 matching lines...) Expand all Loading... | |
729 // WasShown and WasHidden, separating page-level visibility from | 732 // WasShown and WasHidden, separating page-level visibility from |
730 // frame-level visibility. | 733 // frame-level visibility. |
731 render_frame->render_widget_->RegisterRenderFrame(render_frame); | 734 render_frame->render_widget_->RegisterRenderFrame(render_frame); |
732 } | 735 } |
733 } | 736 } |
734 | 737 |
735 render_frame->Initialize(); | 738 render_frame->Initialize(); |
736 } | 739 } |
737 | 740 |
738 // static | 741 // static |
742 void RenderFrameImpl::DetachFrame(int routing_id) { | |
Charlie Reis
2015/12/11 00:03:17
Is this ever meant to be called when in_frame_tree
nasko
2015/12/11 00:47:25
With my latest change it is supposed to. It detach
Charlie Reis
2015/12/11 00:47:40
Nick had an idea for this. If we get here when is
Charlie Reis
2015/12/11 20:10:11
This sounds like it's still bad, right? We could
| |
743 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); | |
744 frame->set_in_browser_initiated_detach(); | |
745 frame->GetWebFrame()->detach(); | |
746 } | |
747 | |
748 // static | |
739 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { | 749 RenderFrame* RenderFrame::FromWebFrame(blink::WebFrame* web_frame) { |
740 return RenderFrameImpl::FromWebFrame(web_frame); | 750 return RenderFrameImpl::FromWebFrame(web_frame); |
741 } | 751 } |
742 | 752 |
743 // static | 753 // static |
744 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { | 754 RenderFrameImpl* RenderFrameImpl::FromWebFrame(blink::WebFrame* web_frame) { |
745 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); | 755 FrameMap::iterator iter = g_frame_map.Get().find(web_frame); |
746 if (iter != g_frame_map.Get().end()) | 756 if (iter != g_frame_map.Get().end()) |
747 return iter->second; | 757 return iter->second; |
748 return NULL; | 758 return NULL; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 return opener_frame->GetWebFrame(); | 800 return opener_frame->GetWebFrame(); |
791 } | 801 } |
792 | 802 |
793 return nullptr; | 803 return nullptr; |
794 } | 804 } |
795 | 805 |
796 // RenderFrameImpl ---------------------------------------------------------- | 806 // RenderFrameImpl ---------------------------------------------------------- |
797 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 807 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
798 : frame_(NULL), | 808 : frame_(NULL), |
799 is_main_frame_(true), | 809 is_main_frame_(true), |
810 is_local_root_(false), | |
811 in_browser_initiated_detach_(false), | |
812 in_frame_tree_(false), | |
800 render_view_(params.render_view->AsWeakPtr()), | 813 render_view_(params.render_view->AsWeakPtr()), |
801 routing_id_(params.routing_id), | 814 routing_id_(params.routing_id), |
802 is_swapped_out_(false), | 815 is_swapped_out_(false), |
803 render_frame_proxy_(NULL), | 816 render_frame_proxy_(NULL), |
804 is_detaching_(false), | 817 is_detaching_(false), |
805 proxy_routing_id_(MSG_ROUTING_NONE), | 818 proxy_routing_id_(MSG_ROUTING_NONE), |
806 #if defined(ENABLE_PLUGINS) | 819 #if defined(ENABLE_PLUGINS) |
807 plugin_power_saver_helper_(nullptr), | 820 plugin_power_saver_helper_(nullptr), |
808 #endif | 821 #endif |
809 cookie_jar_(this), | 822 cookie_jar_(this), |
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2431 | 2444 |
2432 // Create the RenderFrame and WebLocalFrame, linking the two. | 2445 // Create the RenderFrame and WebLocalFrame, linking the two. |
2433 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( | 2446 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( |
2434 render_view_.get(), child_routing_id); | 2447 render_view_.get(), child_routing_id); |
2435 blink::WebLocalFrame* web_frame = | 2448 blink::WebLocalFrame* web_frame = |
2436 WebLocalFrame::create(scope, child_render_frame); | 2449 WebLocalFrame::create(scope, child_render_frame); |
2437 child_render_frame->SetWebFrame(web_frame); | 2450 child_render_frame->SetWebFrame(web_frame); |
2438 | 2451 |
2439 // Add the frame to the frame tree and initialize it. | 2452 // Add the frame to the frame tree and initialize it. |
2440 parent->appendChild(web_frame); | 2453 parent->appendChild(web_frame); |
2454 child_render_frame->in_frame_tree_ = true; | |
2441 child_render_frame->Initialize(); | 2455 child_render_frame->Initialize(); |
2442 | 2456 |
2443 return web_frame; | 2457 return web_frame; |
2444 } | 2458 } |
2445 | 2459 |
2446 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { | 2460 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { |
2447 // Only active frames are able to disown their opener. | 2461 // Only active frames are able to disown their opener. |
2448 if (!opener && is_swapped_out_) | 2462 if (!opener && is_swapped_out_) |
2449 return; | 2463 return; |
2450 | 2464 |
(...skipping 11 matching lines...) Expand all Loading... | |
2462 // the parent frame. This is different from createChildFrame() which is | 2476 // the parent frame. This is different from createChildFrame() which is |
2463 // called on the parent frame. | 2477 // called on the parent frame. |
2464 CHECK(!is_detaching_); | 2478 CHECK(!is_detaching_); |
2465 DCHECK(!frame_ || frame_ == frame); | 2479 DCHECK(!frame_ || frame_ == frame); |
2466 | 2480 |
2467 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); | 2481 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); |
2468 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), | 2482 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), |
2469 FrameDetached(frame)); | 2483 FrameDetached(frame)); |
2470 | 2484 |
2471 // We only notify the browser process when the frame is being detached for | 2485 // We only notify the browser process when the frame is being detached for |
2472 // removal. If the frame is being detached for swap, we don't need to do this | 2486 // removal and it was initiated from the renderer process. |
2473 // since we are not modifiying the frame tree. | 2487 if (!in_browser_initiated_detach_ && type == DetachType::Remove) |
2474 if (type == DetachType::Remove) | |
2475 Send(new FrameHostMsg_Detach(routing_id_)); | 2488 Send(new FrameHostMsg_Detach(routing_id_)); |
2476 | 2489 |
2477 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | 2490 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
2478 // sent before setting |is_detaching_| to true. | 2491 // sent before setting |is_detaching_| to true. |
2479 is_detaching_ = true; | 2492 is_detaching_ = true; |
2480 | 2493 |
2481 // Clean up the associated RenderWidget for the frame, if there is one. | 2494 // Clean up the associated RenderWidget for the frame, if there is one. |
2482 if (render_widget_) { | 2495 if (render_widget_) { |
2483 render_widget_->UnregisterRenderFrame(this); | 2496 render_widget_->UnregisterRenderFrame(this); |
2484 render_widget_->CloseForFrame(); | 2497 render_widget_->CloseForFrame(); |
2485 } | 2498 } |
2486 | 2499 |
2487 // We need to clean up subframes by removing them from the map and deleting | 2500 // We need to clean up subframes by removing them from the map and deleting |
2488 // the RenderFrameImpl. In contrast, the main frame is owned by its | 2501 // the RenderFrameImpl. In contrast, the main frame is owned by its |
2489 // containing RenderViewHost (so that they have the same lifetime), so only | 2502 // containing RenderViewHost (so that they have the same lifetime), so only |
2490 // removal from the map is needed and no deletion. | 2503 // removal from the map is needed and no deletion. |
2491 FrameMap::iterator it = g_frame_map.Get().find(frame); | 2504 FrameMap::iterator it = g_frame_map.Get().find(frame); |
2492 CHECK(it != g_frame_map.Get().end()); | 2505 CHECK(it != g_frame_map.Get().end()); |
2493 CHECK_EQ(it->second, this); | 2506 CHECK_EQ(it->second, this); |
2494 g_frame_map.Get().erase(it); | 2507 g_frame_map.Get().erase(it); |
2495 | 2508 |
2496 // Only remove the frame from the renderer's frame tree if the frame is | 2509 // Only remove the frame from the renderer's frame tree if the frame is |
2497 // being detached for removal. In the case of a swap, the frame needs to | 2510 // being detached for removal and is already inserted in the frame tree. |
2498 // remain in the tree so WebFrame::swap() can replace it with the new frame. | 2511 // In the case of a swap, the frame needs to remain in the tree so |
2499 if (!is_main_frame_ && type == DetachType::Remove) | 2512 // WebFrame::swap() can replace it with the new frame. |
2513 if (!is_main_frame_ && in_frame_tree_ && | |
2514 type == DetachType::Remove) { | |
2500 frame->parent()->removeChild(frame); | 2515 frame->parent()->removeChild(frame); |
2516 } | |
2501 | 2517 |
2502 // |frame| is invalid after here. Be sure to clear frame_ as well, since this | 2518 // |frame| is invalid after here. Be sure to clear frame_ as well, since this |
2503 // object may not be deleted immediately and other methods may try to access | 2519 // object may not be deleted immediately and other methods may try to access |
2504 // it. | 2520 // it. |
2505 frame->close(); | 2521 frame->close(); |
2506 frame_ = nullptr; | 2522 frame_ = nullptr; |
2507 | 2523 |
2508 delete this; | 2524 delete this; |
2509 // Object is invalid after this point. | 2525 // Object is invalid after this point. |
2510 } | 2526 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2919 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( | 2935 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( |
2920 frame->dataSource()->response()); | 2936 frame->dataSource()->response()); |
2921 is_using_lofi_ = extra_data && extra_data->is_using_lofi(); | 2937 is_using_lofi_ = extra_data && extra_data->is_using_lofi(); |
2922 | 2938 |
2923 if (proxy_routing_id_ != MSG_ROUTING_NONE) { | 2939 if (proxy_routing_id_ != MSG_ROUTING_NONE) { |
2924 RenderFrameProxy* proxy = | 2940 RenderFrameProxy* proxy = |
2925 RenderFrameProxy::FromRoutingID(proxy_routing_id_); | 2941 RenderFrameProxy::FromRoutingID(proxy_routing_id_); |
2926 CHECK(proxy); | 2942 CHECK(proxy); |
2927 proxy->web_frame()->swap(frame_); | 2943 proxy->web_frame()->swap(frame_); |
2928 proxy_routing_id_ = MSG_ROUTING_NONE; | 2944 proxy_routing_id_ = MSG_ROUTING_NONE; |
2945 in_frame_tree_ = true; | |
2929 | 2946 |
2930 // If this is the main frame going from a remote frame to a local frame, | 2947 // If this is the main frame going from a remote frame to a local frame, |
2931 // it needs to set RenderViewImpl's pointer for the main frame to itself | 2948 // it needs to set RenderViewImpl's pointer for the main frame to itself |
2932 // and ensure RenderWidget is no longer in swapped out mode. | 2949 // and ensure RenderWidget is no longer in swapped out mode. |
2933 if (is_main_frame_) { | 2950 if (is_main_frame_) { |
2934 CHECK(!render_view_->main_render_frame_); | 2951 CHECK(!render_view_->main_render_frame_); |
2935 render_view_->main_render_frame_ = this; | 2952 render_view_->main_render_frame_ = this; |
2936 if (render_view_->is_swapped_out()) | 2953 if (render_view_->is_swapped_out()) |
2937 render_view_->SetSwappedOut(false); | 2954 render_view_->SetSwappedOut(false); |
2938 } | 2955 } |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5516 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5533 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
5517 scoped_refptr<media::AudioOutputDevice> device = | 5534 scoped_refptr<media::AudioOutputDevice> device = |
5518 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5535 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
5519 security_origin); | 5536 security_origin); |
5520 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5537 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
5521 device->Stop(); | 5538 device->Stop(); |
5522 callback.Run(status); | 5539 callback.Run(status); |
5523 } | 5540 } |
5524 | 5541 |
5525 } // namespace content | 5542 } // namespace content |
OLD | NEW |