Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1785153005: Remove SiteIsolationPolicy::IsSwappedOutStateForbidden(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 return nullptr; 949 return nullptr;
950 950
951 // Opener routing ID could refer to either a RenderFrameProxy or a 951 // Opener routing ID could refer to either a RenderFrameProxy or a
952 // RenderFrame, so need to check both. 952 // RenderFrame, so need to check both.
953 RenderFrameProxy* opener_proxy = 953 RenderFrameProxy* opener_proxy =
954 RenderFrameProxy::FromRoutingID(opener_frame_routing_id); 954 RenderFrameProxy::FromRoutingID(opener_frame_routing_id);
955 if (opener_proxy) { 955 if (opener_proxy) {
956 if (opener_view_routing_id) 956 if (opener_view_routing_id)
957 *opener_view_routing_id = opener_proxy->render_view()->GetRoutingID(); 957 *opener_view_routing_id = opener_proxy->render_view()->GetRoutingID();
958 958
959 // TODO(nasko,alexmos): This check won't be needed once swappedout:// is 959 return opener_proxy->web_frame();
960 // gone.
961 if (opener_proxy->IsMainFrameDetachedFromTree()) {
962 DCHECK(!SiteIsolationPolicy::IsSwappedOutStateForbidden());
963 return opener_proxy->render_view()->webview()->mainFrame();
964 } else {
965 return opener_proxy->web_frame();
966 }
967 } 960 }
968 961
969 RenderFrameImpl* opener_frame = 962 RenderFrameImpl* opener_frame =
970 RenderFrameImpl::FromRoutingID(opener_frame_routing_id); 963 RenderFrameImpl::FromRoutingID(opener_frame_routing_id);
971 if (opener_frame) { 964 if (opener_frame) {
972 if (opener_view_routing_id) 965 if (opener_view_routing_id)
973 *opener_view_routing_id = opener_frame->render_view()->GetRoutingID(); 966 *opener_view_routing_id = opener_frame->render_view()->GetRoutingID();
974 return opener_frame->GetWebFrame(); 967 return opener_frame->GetWebFrame();
975 } 968 }
976 969
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnDestruct()); 1044 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnDestruct());
1052 1045
1053 base::trace_event::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_); 1046 base::trace_event::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
1054 1047
1055 #if defined(VIDEO_HOLE) 1048 #if defined(VIDEO_HOLE)
1056 if (contains_media_player_) 1049 if (contains_media_player_)
1057 render_view_->UnregisterVideoHoleFrame(this); 1050 render_view_->UnregisterVideoHoleFrame(this);
1058 #endif 1051 #endif
1059 1052
1060 if (is_main_frame_) { 1053 if (is_main_frame_) {
1061 // When using swapped out frames, RenderFrameProxy is owned by
1062 // RenderFrameImpl in the case it is the main frame. Ensure it is deleted
1063 // along with this object.
1064 if (render_frame_proxy_ &&
1065 !SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
1066 // The following method calls back into this object and clears
1067 // |render_frame_proxy_|.
1068 render_frame_proxy_->frameDetached(
1069 blink::WebRemoteFrameClient::DetachType::Remove);
1070 }
1071
1072 // Ensure the RenderView doesn't point to this object, once it is destroyed. 1054 // Ensure the RenderView doesn't point to this object, once it is destroyed.
1073 // TODO(nasko): Add a check that the |main_render_frame_| of |render_view_| 1055 // TODO(nasko): Add a check that the |main_render_frame_| of |render_view_|
1074 // is |this|, once the object is no longer leaked. 1056 // is |this|, once the object is no longer leaked.
1075 // See https://crbug.com/464764. 1057 // See https://crbug.com/464764.
1076 render_view_->main_render_frame_ = nullptr; 1058 render_view_->main_render_frame_ = nullptr;
1077 } 1059 }
1078 1060
1079 render_view_->UnregisterRenderFrame(this); 1061 render_view_->UnregisterRenderFrame(this);
1080 g_routing_id_frame_map.Get().erase(routing_id_); 1062 g_routing_id_frame_map.Get().erase(routing_id_);
1081 RenderThread::Get()->RemoveRoute(routing_id_); 1063 RenderThread::Get()->RemoveRoute(routing_id_);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 before_unload_start_time, 1518 before_unload_start_time,
1537 before_unload_end_time)); 1519 before_unload_end_time));
1538 } 1520 }
1539 1521
1540 void RenderFrameImpl::OnSwapOut( 1522 void RenderFrameImpl::OnSwapOut(
1541 int proxy_routing_id, 1523 int proxy_routing_id,
1542 bool is_loading, 1524 bool is_loading,
1543 const FrameReplicationState& replicated_frame_state) { 1525 const FrameReplicationState& replicated_frame_state) {
1544 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); 1526 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_);
1545 RenderFrameProxy* proxy = NULL; 1527 RenderFrameProxy* proxy = NULL;
1546 bool swapped_out_forbidden =
1547 SiteIsolationPolicy::IsSwappedOutStateForbidden();
1548 1528
1549 // This codepath should only be hit for subframes when in --site-per-process. 1529 // This codepath should only be hit for subframes when in --site-per-process.
1550 CHECK(is_main_frame_ || SiteIsolationPolicy::AreCrossProcessFramesPossible()); 1530 CHECK(is_main_frame_ || SiteIsolationPolicy::AreCrossProcessFramesPossible());
1551 1531
1552 // Only run unload if we're not swapped out yet, but send the ack either way. 1532 // Only run unload if we're not swapped out yet, but send the ack either way.
1553 if (!is_swapped_out_) { 1533 if (!is_swapped_out_) {
1554 // Swap this RenderFrame out so the frame can navigate to a page rendered by 1534 // Swap this RenderFrame out so the frame can navigate to a page rendered by
1555 // a different process. This involves running the unload handler and 1535 // a different process. This involves running the unload handler and
1556 // clearing the page. We also allow this process to exit if there are no 1536 // clearing the page. We also allow this process to exit if there are no
1557 // other active RenderFrames in it. 1537 // other active RenderFrames in it.
(...skipping 21 matching lines...) Expand all
1579 if (is_main_frame_) 1559 if (is_main_frame_)
1580 render_view_->SetSwappedOut(true); 1560 render_view_->SetSwappedOut(true);
1581 is_swapped_out_ = true; 1561 is_swapped_out_ = true;
1582 1562
1583 // Set the proxy here, since OnStop() below could cause an onload event 1563 // Set the proxy here, since OnStop() below could cause an onload event
1584 // handler to execute, which could trigger code such as 1564 // handler to execute, which could trigger code such as
1585 // willCheckAndDispatchMessageEvent() that needs the proxy. 1565 // willCheckAndDispatchMessageEvent() that needs the proxy.
1586 if (proxy) 1566 if (proxy)
1587 set_render_frame_proxy(proxy); 1567 set_render_frame_proxy(proxy);
1588 1568
1589 // Now that we're swapped out and filtering IPC messages, stop loading to
1590 // ensure that no other in-progress navigation continues. We do this here
1591 // to avoid sending a DidStopLoading message to the browser process.
1592 // TODO(creis): Should we be stopping all frames here and using
1593 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this
1594 // frame?
1595 if (!swapped_out_forbidden)
1596 OnStop();
1597
1598 // Transfer settings such as initial drawing parameters to the remote frame, 1569 // Transfer settings such as initial drawing parameters to the remote frame,
1599 // if one is created, that will replace this frame. 1570 // if one is created, that will replace this frame.
1600 if (!is_main_frame_ && proxy) 1571 if (!is_main_frame_ && proxy)
1601 proxy->web_frame()->initializeFromFrame(frame_); 1572 proxy->web_frame()->initializeFromFrame(frame_);
1602 1573
1603 // Replace the page with a blank dummy URL. The unload handler will not be
1604 // run a second time, thanks to a check in FrameLoader::stopLoading.
1605 // TODO(creis): Need to add a better way to do this that avoids running the
1606 // beforeunload handler. For now, we just run it a second time silently.
1607 if (!swapped_out_forbidden)
1608 NavigateToSwappedOutURL();
1609
1610 // Let WebKit know that this view is hidden so it can drop resources and 1574 // Let WebKit know that this view is hidden so it can drop resources and
1611 // stop compositing. 1575 // stop compositing.
1612 // TODO(creis): Support this for subframes as well. 1576 // TODO(creis): Support this for subframes as well.
1613 if (is_main_frame_) { 1577 if (is_main_frame_) {
1614 render_view_->webview()->setVisibilityState( 1578 render_view_->webview()->setVisibilityState(
1615 blink::WebPageVisibilityStateHidden, false); 1579 blink::WebPageVisibilityStateHidden, false);
1616 } 1580 }
1617 } 1581 }
1618 1582
1619 // It is now safe to show modal dialogs again. 1583 // It is now safe to show modal dialogs again.
1620 // TODO(creis): Deal with modal dialogs from subframes. 1584 // TODO(creis): Deal with modal dialogs from subframes.
1621 if (is_main_frame_) 1585 if (is_main_frame_)
1622 render_view_->suppress_dialogs_until_swap_out_ = false; 1586 render_view_->suppress_dialogs_until_swap_out_ = false;
1623 1587
1624 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); 1588 Send(new FrameHostMsg_SwapOut_ACK(routing_id_));
1625 1589
1626 RenderViewImpl* render_view = render_view_.get(); 1590 RenderViewImpl* render_view = render_view_.get();
1627 bool is_main_frame = is_main_frame_; 1591 bool is_main_frame = is_main_frame_;
1628 int routing_id = GetRoutingID(); 1592 int routing_id = GetRoutingID();
1629 1593
1630 // Now that all of the cleanup is complete and the browser side is notified, 1594 // Now that all of the cleanup is complete and the browser side is notified,
1631 // start using the RenderFrameProxy, if one is created. 1595 // start using the RenderFrameProxy, if one is created.
1632 if (proxy && swapped_out_forbidden) { 1596 if (proxy) {
1633 // The swap call deletes this RenderFrame via frameDetached. Do not access 1597 // The swap call deletes this RenderFrame via frameDetached. Do not access
1634 // any members after this call. 1598 // any members after this call.
1635 // TODO(creis): WebFrame::swap() can return false. Most of those cases 1599 // TODO(creis): WebFrame::swap() can return false. Most of those cases
1636 // should be due to the frame being detached during unload (in which case 1600 // should be due to the frame being detached during unload (in which case
1637 // the necessary cleanup has happened anyway), but it might be possible for 1601 // the necessary cleanup has happened anyway), but it might be possible for
1638 // it to return false without detaching. Catch those cases below to track 1602 // it to return false without detaching. Catch those cases below to track
1639 // down https://crbug.com/575245. 1603 // down https://crbug.com/575245.
1640 frame_->swap(proxy->web_frame()); 1604 frame_->swap(proxy->web_frame());
1641 1605
1642 // For main frames, the swap should have cleared the RenderView's pointer to 1606 // For main frames, the swap should have cleared the RenderView's pointer to
1643 // this frame. 1607 // this frame.
1644 if (is_main_frame) { 1608 if (is_main_frame) {
1645 base::debug::SetCrashKeyValue("swapout_frame_id", 1609 base::debug::SetCrashKeyValue("swapout_frame_id",
1646 base::IntToString(routing_id)); 1610 base::IntToString(routing_id));
1647 base::debug::SetCrashKeyValue("swapout_proxy_id", 1611 base::debug::SetCrashKeyValue("swapout_proxy_id",
1648 base::IntToString(proxy->routing_id())); 1612 base::IntToString(proxy->routing_id()));
1649 base::debug::SetCrashKeyValue( 1613 base::debug::SetCrashKeyValue(
1650 "swapout_view_id", base::IntToString(render_view->GetRoutingID())); 1614 "swapout_view_id", base::IntToString(render_view->GetRoutingID()));
1651 CHECK(!render_view->main_render_frame_); 1615 CHECK(!render_view->main_render_frame_);
1652 } 1616 }
1653 1617
1654 if (is_loading) 1618 if (is_loading)
1655 proxy->OnDidStartLoading(); 1619 proxy->OnDidStartLoading();
1656 } 1620 }
1657 1621
1658 // In --site-per-process, initialize the WebRemoteFrame with the replication 1622 // Initialize the WebRemoteFrame with the replication state passed by the
1659 // state passed by the process that is now rendering the frame. 1623 // process that is now rendering the frame.
1660 // TODO(alexmos): We cannot yet do this for swapped-out main frames, because 1624 if (proxy)
1661 // in that case we leave the LocalFrame as the main frame visible to Blink
1662 // and don't call swap() above. Because swap() is what creates a RemoteFrame
1663 // in proxy->web_frame(), the RemoteFrame will not exist for main frames.
1664 // When we do an unconditional swap for all frames, we can remove
1665 // !is_main_frame below.
1666 if (proxy && swapped_out_forbidden)
1667 proxy->SetReplicatedState(replicated_frame_state); 1625 proxy->SetReplicatedState(replicated_frame_state);
1668 1626
1669 // Safe to exit if no one else is using the process. 1627 // Safe to exit if no one else is using the process.
1670 // TODO(nasko): Remove the dependency on RenderViewImpl here and ref count 1628 // TODO(nasko): Remove the dependency on RenderViewImpl here and ref count
1671 // the process based on the lifetime of this RenderFrameImpl object. 1629 // the process based on the lifetime of this RenderFrameImpl object.
1672 if (is_main_frame) { 1630 if (is_main_frame)
1673 render_view->WasSwappedOut(); 1631 render_view->WasSwappedOut();
1674 }
1675 } 1632 }
1676 1633
1677 void RenderFrameImpl::OnDeleteFrame() { 1634 void RenderFrameImpl::OnDeleteFrame() {
1678 // TODO(nasko): If this message is received right after a commit has 1635 // TODO(nasko): If this message is received right after a commit has
1679 // swapped a RenderFrameProxy with this RenderFrame, the proxy needs to be 1636 // swapped a RenderFrameProxy with this RenderFrame, the proxy needs to be
1680 // recreated in addition to the RenderFrame being deleted. 1637 // recreated in addition to the RenderFrame being deleted.
1681 // See https://crbug.com/569683 for details. 1638 // See https://crbug.com/569683 for details.
1682 in_browser_initiated_detach_ = true; 1639 in_browser_initiated_detach_ = true;
1683 1640
1684 // This will result in a call to RendeFrameImpl::frameDetached, which 1641 // This will result in a call to RendeFrameImpl::frameDetached, which
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 WebString::fromUTF8(params.text_track_text_size)); 2059 WebString::fromUTF8(params.text_track_text_size));
2103 } 2060 }
2104 2061
2105 void RenderFrameImpl::OnPostMessageEvent( 2062 void RenderFrameImpl::OnPostMessageEvent(
2106 const FrameMsg_PostMessage_Params& params) { 2063 const FrameMsg_PostMessage_Params& params) {
2107 // Find the source frame if it exists. 2064 // Find the source frame if it exists.
2108 WebFrame* source_frame = NULL; 2065 WebFrame* source_frame = NULL;
2109 if (params.source_routing_id != MSG_ROUTING_NONE) { 2066 if (params.source_routing_id != MSG_ROUTING_NONE) {
2110 RenderFrameProxy* source_proxy = 2067 RenderFrameProxy* source_proxy =
2111 RenderFrameProxy::FromRoutingID(params.source_routing_id); 2068 RenderFrameProxy::FromRoutingID(params.source_routing_id);
2112 if (source_proxy) { 2069 if (source_proxy)
2113 // Currently, navigating a top-level frame cross-process does not swap 2070 source_frame = source_proxy->web_frame();
2114 // the WebLocalFrame for a WebRemoteFrame in the frame tree, and the
2115 // WebRemoteFrame will not have an associated blink::Frame. If this is
2116 // the case for |source_proxy|, use the corresponding (swapped-out)
2117 // WebLocalFrame instead, so that event.source for this message can be
2118 // set and used properly.
2119 if (source_proxy->IsMainFrameDetachedFromTree())
2120 source_frame = source_proxy->render_view()->webview()->mainFrame();
2121 else
2122 source_frame = source_proxy->web_frame();
2123 }
2124 } 2071 }
2125 2072
2126 // If the message contained MessagePorts, create the corresponding endpoints. 2073 // If the message contained MessagePorts, create the corresponding endpoints.
2127 blink::WebMessagePortChannelArray channels = 2074 blink::WebMessagePortChannelArray channels =
2128 WebMessagePortChannelImpl::CreatePorts( 2075 WebMessagePortChannelImpl::CreatePorts(
2129 params.message_ports, params.new_routing_ids, 2076 params.message_ports, params.new_routing_ids,
2130 base::ThreadTaskRunnerHandle::Get().get()); 2077 base::ThreadTaskRunnerHandle::Get().get());
2131 2078
2132 WebSerializedScriptValue serialized_script_value; 2079 WebSerializedScriptValue serialized_script_value;
2133 if (params.is_data_raw_string) { 2080 if (params.is_data_raw_string) {
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4776 info.urlRequest, info.navigationType, info.defaultPolicy, 4723 info.urlRequest, info.navigationType, info.defaultPolicy,
4777 is_redirect)) { 4724 is_redirect)) {
4778 return blink::WebNavigationPolicyIgnore; 4725 return blink::WebNavigationPolicyIgnore;
4779 } 4726 }
4780 #endif 4727 #endif
4781 4728
4782 Referrer referrer( 4729 Referrer referrer(
4783 RenderViewImpl::GetReferrerFromRequest(frame_, info.urlRequest)); 4730 RenderViewImpl::GetReferrerFromRequest(frame_, info.urlRequest));
4784 4731
4785 // TODO(nick): Is consulting |is_main_frame| here correct? 4732 // TODO(nick): Is consulting |is_main_frame| here correct?
4786 if (SiteIsolationPolicy::IsSwappedOutStateForbidden() && !is_main_frame_) { 4733 if (is_main_frame_ && is_swapped_out_) {
4787 // There's no reason to ignore navigations on subframes, since the swap out 4734 if (info.urlRequest.url() != GURL(kSwappedOutURL)) {
4788 // logic no longer applies. 4735 // Targeted links may try to navigate a swapped out frame. Allow the
4789 } else { 4736 // browser process to navigate the tab instead. Note that it is also
4790 if (is_swapped_out_) { 4737 // possible for non-targeted navigations (from this view) to arrive
4791 if (info.urlRequest.url() != GURL(kSwappedOutURL)) { 4738 // here just after we are swapped out. It's ok to send them to the
4792 // Targeted links may try to navigate a swapped out frame. Allow the 4739 // browser, as long as they're for the top level frame.
4793 // browser process to navigate the tab instead. Note that it is also 4740 // TODO(creis): Ensure this supports targeted form submissions when
4794 // possible for non-targeted navigations (from this view) to arrive 4741 // fixing http://crbug.com/101395.
4795 // here just after we are swapped out. It's ok to send them to the 4742 if (frame_->parent() == NULL) {
4796 // browser, as long as they're for the top level frame. 4743 OpenURL(info.urlRequest.url(), referrer, info.defaultPolicy,
4797 // TODO(creis): Ensure this supports targeted form submissions when 4744 info.replacesCurrentHistoryItem, false);
4798 // fixing http://crbug.com/101395. 4745 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
4799 if (frame_->parent() == NULL) {
4800 OpenURL(info.urlRequest.url(), referrer, info.defaultPolicy,
4801 info.replacesCurrentHistoryItem, false);
4802 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
4803 }
4804
4805 // We should otherwise ignore in-process iframe navigations, if they
4806 // arrive just after we are swapped out.
4807 return blink::WebNavigationPolicyIgnore;
4808 } 4746 }
4809 4747
4810 // Allow kSwappedOutURL to complete. 4748 // We should otherwise ignore in-process iframe navigations, if they
4811 return info.defaultPolicy; 4749 // arrive just after we are swapped out.
4750 return blink::WebNavigationPolicyIgnore;
4812 } 4751 }
4752
4753 // Allow kSwappedOutURL to complete.
4754 return info.defaultPolicy;
4813 } 4755 }
4814 4756
4815 // Webkit is asking whether to navigate to a new URL. 4757 // Webkit is asking whether to navigate to a new URL.
4816 // This is fine normally, except if we're showing UI from one security 4758 // This is fine normally, except if we're showing UI from one security
4817 // context and they're trying to navigate to a different context. 4759 // context and they're trying to navigate to a different context.
4818 const GURL& url = info.urlRequest.url(); 4760 const GURL& url = info.urlRequest.url();
4819 4761
4820 // If the browser is interested, then give it a chance to look at the request. 4762 // If the browser is interested, then give it a chance to look at the request.
4821 if (is_content_initiated && IsTopLevelNavigation(frame_) && 4763 if (is_content_initiated && IsTopLevelNavigation(frame_) &&
4822 render_view_->renderer_preferences_ 4764 render_view_->renderer_preferences_
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
6130 int match_count, 6072 int match_count,
6131 int ordinal, 6073 int ordinal,
6132 const WebRect& selection_rect, 6074 const WebRect& selection_rect,
6133 bool final_status_update) { 6075 bool final_status_update) {
6134 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, 6076 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count,
6135 selection_rect, ordinal, 6077 selection_rect, ordinal,
6136 final_status_update)); 6078 final_status_update));
6137 } 6079 }
6138 6080
6139 } // namespace content 6081 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/accessibility/renderer_accessibility_browsertest.cc ('k') | content/renderer/render_frame_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698