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 | |
703 // The RenderFrame is created and inserted into the frame tree in the above | |
704 // call to createLocalChild. | |
705 render_frame->in_frame_tree_ = true; | |
702 } else { | 706 } else { |
703 RenderFrameProxy* proxy = | 707 RenderFrameProxy* proxy = |
704 RenderFrameProxy::FromRoutingID(proxy_routing_id); | 708 RenderFrameProxy::FromRoutingID(proxy_routing_id); |
705 CHECK(proxy); | 709 CHECK(proxy); |
706 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); | 710 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); |
707 render_frame->proxy_routing_id_ = proxy_routing_id; | 711 render_frame->proxy_routing_id_ = proxy_routing_id; |
708 web_frame = blink::WebLocalFrame::createProvisional( | 712 web_frame = blink::WebLocalFrame::createProvisional( |
709 render_frame, proxy->web_frame(), replicated_state.sandbox_flags, | 713 render_frame, proxy->web_frame(), replicated_state.sandbox_flags, |
710 frame_owner_properties); | 714 frame_owner_properties); |
711 } | 715 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 return opener_frame->GetWebFrame(); | 794 return opener_frame->GetWebFrame(); |
791 } | 795 } |
792 | 796 |
793 return nullptr; | 797 return nullptr; |
794 } | 798 } |
795 | 799 |
796 // RenderFrameImpl ---------------------------------------------------------- | 800 // RenderFrameImpl ---------------------------------------------------------- |
797 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 801 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
798 : frame_(NULL), | 802 : frame_(NULL), |
799 is_main_frame_(true), | 803 is_main_frame_(true), |
804 in_browser_initiated_detach_(false), | |
805 in_frame_tree_(false), | |
800 render_view_(params.render_view->AsWeakPtr()), | 806 render_view_(params.render_view->AsWeakPtr()), |
801 routing_id_(params.routing_id), | 807 routing_id_(params.routing_id), |
802 is_swapped_out_(false), | 808 is_swapped_out_(false), |
803 render_frame_proxy_(NULL), | 809 render_frame_proxy_(NULL), |
804 is_detaching_(false), | 810 is_detaching_(false), |
805 proxy_routing_id_(MSG_ROUTING_NONE), | 811 proxy_routing_id_(MSG_ROUTING_NONE), |
806 #if defined(ENABLE_PLUGINS) | 812 #if defined(ENABLE_PLUGINS) |
807 plugin_power_saver_helper_(nullptr), | 813 plugin_power_saver_helper_(nullptr), |
808 #endif | 814 #endif |
809 cookie_jar_(this), | 815 cookie_jar_(this), |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 while ((observer = it.GetNext()) != NULL) { | 1199 while ((observer = it.GetNext()) != NULL) { |
1194 if (observer->OnMessageReceived(msg)) | 1200 if (observer->OnMessageReceived(msg)) |
1195 return true; | 1201 return true; |
1196 } | 1202 } |
1197 | 1203 |
1198 bool handled = true; | 1204 bool handled = true; |
1199 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) | 1205 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) |
1200 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) | 1206 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) |
1201 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) | 1207 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) |
1202 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) | 1208 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) |
1209 IPC_MESSAGE_HANDLER(FrameMsg_Delete, OnDeleteFrame) | |
1203 IPC_MESSAGE_HANDLER(FrameMsg_Stop, OnStop) | 1210 IPC_MESSAGE_HANDLER(FrameMsg_Stop, OnStop) |
1204 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) | 1211 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) |
1205 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, | 1212 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, |
1206 OnCustomContextMenuAction) | 1213 OnCustomContextMenuAction) |
1207 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) | 1214 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
1208 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) | 1215 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
1209 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) | 1216 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
1210 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) | 1217 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
1211 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) | 1218 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
1212 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) | 1219 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1434 proxy->SetReplicatedState(replicated_frame_state); | 1441 proxy->SetReplicatedState(replicated_frame_state); |
1435 | 1442 |
1436 // Safe to exit if no one else is using the process. | 1443 // Safe to exit if no one else is using the process. |
1437 // TODO(nasko): Remove the dependency on RenderViewImpl here and ref count | 1444 // TODO(nasko): Remove the dependency on RenderViewImpl here and ref count |
1438 // the process based on the lifetime of this RenderFrameImpl object. | 1445 // the process based on the lifetime of this RenderFrameImpl object. |
1439 if (is_main_frame) { | 1446 if (is_main_frame) { |
1440 render_view->WasSwappedOut(); | 1447 render_view->WasSwappedOut(); |
1441 } | 1448 } |
1442 } | 1449 } |
1443 | 1450 |
1451 void RenderFrameImpl::OnDeleteFrame() { | |
1452 // TODO(nasko): If this message is received right after a commit has | |
1453 // swapped a RenderFrameProxy with RenderFrame, the proxy need to be | |
Charlie Reis
2015/12/14 22:12:52
nit: with this
nit: needs
nasko
2015/12/14 22:27:59
Done.
| |
1454 // recreated instead of the frame being deleted. | |
Charlie Reis
2015/12/14 22:12:52
Don't we need to delete the frame as well as recre
nasko
2015/12/14 22:27:59
Done.
| |
1455 // See https://crbug.com/569683 for details. | |
1456 in_browser_initiated_detach_ = true; | |
1457 | |
1458 // This will result in a call to RendeFrameImpl::frameDetached, which | |
1459 // deletes the object. Do not access |this| after detach. | |
1460 frame_->detach(); | |
1461 } | |
1462 | |
1444 void RenderFrameImpl::OnContextMenuClosed( | 1463 void RenderFrameImpl::OnContextMenuClosed( |
1445 const CustomContextMenuContext& custom_context) { | 1464 const CustomContextMenuContext& custom_context) { |
1446 if (custom_context.request_id) { | 1465 if (custom_context.request_id) { |
1447 // External request, should be in our map. | 1466 // External request, should be in our map. |
1448 ContextMenuClient* client = | 1467 ContextMenuClient* client = |
1449 pending_context_menus_.Lookup(custom_context.request_id); | 1468 pending_context_menus_.Lookup(custom_context.request_id); |
1450 if (client) { | 1469 if (client) { |
1451 client->OnMenuClosed(custom_context.request_id); | 1470 client->OnMenuClosed(custom_context.request_id); |
1452 pending_context_menus_.Remove(custom_context.request_id); | 1471 pending_context_menus_.Remove(custom_context.request_id); |
1453 } | 1472 } |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2431 | 2450 |
2432 // Create the RenderFrame and WebLocalFrame, linking the two. | 2451 // Create the RenderFrame and WebLocalFrame, linking the two. |
2433 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( | 2452 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( |
2434 render_view_.get(), child_routing_id); | 2453 render_view_.get(), child_routing_id); |
2435 blink::WebLocalFrame* web_frame = | 2454 blink::WebLocalFrame* web_frame = |
2436 WebLocalFrame::create(scope, child_render_frame); | 2455 WebLocalFrame::create(scope, child_render_frame); |
2437 child_render_frame->SetWebFrame(web_frame); | 2456 child_render_frame->SetWebFrame(web_frame); |
2438 | 2457 |
2439 // Add the frame to the frame tree and initialize it. | 2458 // Add the frame to the frame tree and initialize it. |
2440 parent->appendChild(web_frame); | 2459 parent->appendChild(web_frame); |
2460 child_render_frame->in_frame_tree_ = true; | |
2441 child_render_frame->Initialize(); | 2461 child_render_frame->Initialize(); |
2442 | 2462 |
2443 return web_frame; | 2463 return web_frame; |
2444 } | 2464 } |
2445 | 2465 |
2446 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { | 2466 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { |
2447 // Only active frames are able to disown their opener. | 2467 // Only active frames are able to disown their opener. |
2448 if (!opener && is_swapped_out_) | 2468 if (!opener && is_swapped_out_) |
2449 return; | 2469 return; |
2450 | 2470 |
(...skipping 11 matching lines...) Expand all Loading... | |
2462 // the parent frame. This is different from createChildFrame() which is | 2482 // the parent frame. This is different from createChildFrame() which is |
2463 // called on the parent frame. | 2483 // called on the parent frame. |
2464 CHECK(!is_detaching_); | 2484 CHECK(!is_detaching_); |
2465 DCHECK(!frame_ || frame_ == frame); | 2485 DCHECK(!frame_ || frame_ == frame); |
2466 | 2486 |
2467 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); | 2487 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FrameDetached()); |
2468 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), | 2488 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), |
2469 FrameDetached(frame)); | 2489 FrameDetached(frame)); |
2470 | 2490 |
2471 // We only notify the browser process when the frame is being detached for | 2491 // 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 | 2492 // removal and it was initiated from the renderer process. |
2473 // since we are not modifiying the frame tree. | 2493 if (!in_browser_initiated_detach_ && type == DetachType::Remove) |
2474 if (type == DetachType::Remove) | |
2475 Send(new FrameHostMsg_Detach(routing_id_)); | 2494 Send(new FrameHostMsg_Detach(routing_id_)); |
2476 | 2495 |
2477 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | 2496 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
2478 // sent before setting |is_detaching_| to true. | 2497 // sent before setting |is_detaching_| to true. |
2479 is_detaching_ = true; | 2498 is_detaching_ = true; |
2480 | 2499 |
2481 // Clean up the associated RenderWidget for the frame, if there is one. | 2500 // Clean up the associated RenderWidget for the frame, if there is one. |
2482 if (render_widget_) { | 2501 if (render_widget_) { |
2483 render_widget_->UnregisterRenderFrame(this); | 2502 render_widget_->UnregisterRenderFrame(this); |
2484 render_widget_->CloseForFrame(); | 2503 render_widget_->CloseForFrame(); |
2485 } | 2504 } |
2486 | 2505 |
2487 // We need to clean up subframes by removing them from the map and deleting | 2506 // 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 | 2507 // the RenderFrameImpl. In contrast, the main frame is owned by its |
2489 // containing RenderViewHost (so that they have the same lifetime), so only | 2508 // containing RenderViewHost (so that they have the same lifetime), so only |
2490 // removal from the map is needed and no deletion. | 2509 // removal from the map is needed and no deletion. |
2491 FrameMap::iterator it = g_frame_map.Get().find(frame); | 2510 FrameMap::iterator it = g_frame_map.Get().find(frame); |
2492 CHECK(it != g_frame_map.Get().end()); | 2511 CHECK(it != g_frame_map.Get().end()); |
2493 CHECK_EQ(it->second, this); | 2512 CHECK_EQ(it->second, this); |
2494 g_frame_map.Get().erase(it); | 2513 g_frame_map.Get().erase(it); |
2495 | 2514 |
2496 // Only remove the frame from the renderer's frame tree if the frame is | 2515 // 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 | 2516 // 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. | 2517 // In the case of a swap, the frame needs to remain in the tree so |
2499 if (!is_main_frame_ && type == DetachType::Remove) | 2518 // WebFrame::swap() can replace it with the new frame. |
2519 if (!is_main_frame_ && in_frame_tree_ && | |
2520 type == DetachType::Remove) { | |
2500 frame->parent()->removeChild(frame); | 2521 frame->parent()->removeChild(frame); |
2522 } | |
2501 | 2523 |
2502 // |frame| is invalid after here. Be sure to clear frame_ as well, since this | 2524 // |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 | 2525 // object may not be deleted immediately and other methods may try to access |
2504 // it. | 2526 // it. |
2505 frame->close(); | 2527 frame->close(); |
2506 frame_ = nullptr; | 2528 frame_ = nullptr; |
2507 | 2529 |
2508 delete this; | 2530 delete this; |
2509 // Object is invalid after this point. | 2531 // Object is invalid after this point. |
2510 } | 2532 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2919 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( | 2941 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( |
2920 frame->dataSource()->response()); | 2942 frame->dataSource()->response()); |
2921 is_using_lofi_ = extra_data && extra_data->is_using_lofi(); | 2943 is_using_lofi_ = extra_data && extra_data->is_using_lofi(); |
2922 | 2944 |
2923 if (proxy_routing_id_ != MSG_ROUTING_NONE) { | 2945 if (proxy_routing_id_ != MSG_ROUTING_NONE) { |
2924 RenderFrameProxy* proxy = | 2946 RenderFrameProxy* proxy = |
2925 RenderFrameProxy::FromRoutingID(proxy_routing_id_); | 2947 RenderFrameProxy::FromRoutingID(proxy_routing_id_); |
2926 CHECK(proxy); | 2948 CHECK(proxy); |
2927 proxy->web_frame()->swap(frame_); | 2949 proxy->web_frame()->swap(frame_); |
2928 proxy_routing_id_ = MSG_ROUTING_NONE; | 2950 proxy_routing_id_ = MSG_ROUTING_NONE; |
2951 in_frame_tree_ = true; | |
2929 | 2952 |
2930 // If this is the main frame going from a remote frame to a local frame, | 2953 // 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 | 2954 // it needs to set RenderViewImpl's pointer for the main frame to itself |
2932 // and ensure RenderWidget is no longer in swapped out mode. | 2955 // and ensure RenderWidget is no longer in swapped out mode. |
2933 if (is_main_frame_) { | 2956 if (is_main_frame_) { |
2934 CHECK(!render_view_->main_render_frame_); | 2957 CHECK(!render_view_->main_render_frame_); |
2935 render_view_->main_render_frame_ = this; | 2958 render_view_->main_render_frame_ = this; |
2936 if (render_view_->is_swapped_out()) | 2959 if (render_view_->is_swapped_out()) |
2937 render_view_->SetSwappedOut(false); | 2960 render_view_->SetSwappedOut(false); |
2938 } | 2961 } |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5516 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5539 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
5517 scoped_refptr<media::AudioOutputDevice> device = | 5540 scoped_refptr<media::AudioOutputDevice> device = |
5518 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5541 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
5519 security_origin); | 5542 security_origin); |
5520 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5543 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
5521 device->Stop(); | 5544 device->Stop(); |
5522 callback.Run(status); | 5545 callback.Run(status); |
5523 } | 5546 } |
5524 | 5547 |
5525 } // namespace content | 5548 } // namespace content |
OLD | NEW |