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/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 // const GURL& current_url = current_instance->site(); | 928 // const GURL& current_url = current_instance->site(); |
929 // For now, though, we're in a hybrid model where you only switch | 929 // For now, though, we're in a hybrid model where you only switch |
930 // SiteInstances if you type in a cross-site URL. This means we have to | 930 // SiteInstances if you type in a cross-site URL. This means we have to |
931 // compare the entry's URL to the last committed entry's URL. | 931 // compare the entry's URL to the last committed entry's URL. |
932 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); | 932 NavigationEntry* current_entry = controller.GetLastCommittedEntry(); |
933 if (interstitial_page_) { | 933 if (interstitial_page_) { |
934 // The interstitial is currently the last committed entry, but we want to | 934 // The interstitial is currently the last committed entry, but we want to |
935 // compare against the last non-interstitial entry. | 935 // compare against the last non-interstitial entry. |
936 current_entry = controller.GetEntryAtOffset(-1); | 936 current_entry = controller.GetEntryAtOffset(-1); |
937 } | 937 } |
938 // If there is no last non-interstitial entry (and current_instance already | |
939 // has a site), then we must have been opened from another tab. We want | |
940 // to compare against the URL of the page that opened us, but we can't | |
941 // get to it directly. The best we can do is check against the site of | |
942 // the SiteInstance. This will be correct when we intercept links and | |
943 // script-based navigations, but for now, it could place some pages in a | |
944 // new process unnecessarily. We should only hit this case if a page tries | |
945 // to open a new tab to an interstitial-inducing URL, and then navigates | |
946 // the page to a different same-site URL. (This seems very unlikely in | |
947 // practice.) | |
948 const GURL& current_url = (current_entry) ? current_entry->GetURL() : | |
949 current_instance->GetSiteURL(); | |
950 | 938 |
951 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 939 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
952 // We don't need a swap when going from view-source to a debug URL like | 940 // We don't need a swap when going from view-source to a debug URL like |
953 // chrome://crash, however. | 941 // chrome://crash, however. |
954 // TODO(creis): Refactor this method so this duplicated code isn't needed. | 942 // TODO(creis): Refactor this method so this duplicated code isn't needed. |
955 // See http://crbug.com/123007. | 943 // See http://crbug.com/123007. |
956 if (current_entry && | 944 if (current_entry && |
957 current_entry->IsViewSourceMode() != dest_is_view_source_mode && | 945 current_entry->IsViewSourceMode() != dest_is_view_source_mode && |
958 !IsRendererDebugURL(dest_url)) { | 946 !IsRendererDebugURL(dest_url)) { |
959 return SiteInstance::CreateForURL(browser_context, dest_url); | 947 return SiteInstance::CreateForURL(browser_context, dest_url); |
960 } | 948 } |
961 | 949 |
962 // Use the current SiteInstance for same site navigations, as long as the | 950 // Use the current SiteInstance for same site navigations, as long as the |
963 // process type is correct. (The URL may have been installed as an app since | 951 // process type is correct. (The URL may have been installed as an app since |
964 // the last time we visited it.) | 952 // the last time we visited it.) |
| 953 const GURL& current_url = |
| 954 GetCurrentURLForSiteInstance(current_instance, current_entry); |
965 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && | 955 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && |
966 !current_site_instance->HasWrongProcessForURL(dest_url)) { | 956 !current_site_instance->HasWrongProcessForURL(dest_url)) { |
967 return current_instance; | 957 return current_instance; |
968 } | 958 } |
969 | 959 |
970 // Start the new renderer in a new SiteInstance, but in the current | 960 // Start the new renderer in a new SiteInstance, but in the current |
971 // BrowsingInstance. It is important to immediately give this new | 961 // BrowsingInstance. It is important to immediately give this new |
972 // SiteInstance to a RenderViewHost (if it is different than our current | 962 // SiteInstance to a RenderViewHost (if it is different than our current |
973 // SiteInstance), so that it is ref counted. This will happen in | 963 // SiteInstance), so that it is ref counted. This will happen in |
974 // CreateRenderView. | 964 // CreateRenderView. |
975 return current_instance->GetRelatedSiteInstance(dest_url); | 965 return current_instance->GetRelatedSiteInstance(dest_url); |
976 } | 966 } |
977 | 967 |
| 968 const GURL& RenderFrameHostManager::GetCurrentURLForSiteInstance( |
| 969 SiteInstance* current_instance, NavigationEntry* current_entry) { |
| 970 // If this is a subframe that is potentially out of process from its parent, |
| 971 // don't consider using current_entry's url for SiteInstance selection, since |
| 972 // current_entry's url is for the main frame and may be in a different site |
| 973 // than this frame. |
| 974 // TODO(creis): Remove this when we can check the FrameNavigationEntry's url. |
| 975 // See http://crbug.com/369654 |
| 976 if (!frame_tree_node_->IsMainFrame() && |
| 977 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
| 978 return frame_tree_node_->current_url(); |
| 979 |
| 980 // If there is no last non-interstitial entry (and current_instance already |
| 981 // has a site), then we must have been opened from another tab. We want |
| 982 // to compare against the URL of the page that opened us, but we can't |
| 983 // get to it directly. The best we can do is check against the site of |
| 984 // the SiteInstance. This will be correct when we intercept links and |
| 985 // script-based navigations, but for now, it could place some pages in a |
| 986 // new process unnecessarily. We should only hit this case if a page tries |
| 987 // to open a new tab to an interstitial-inducing URL, and then navigates |
| 988 // the page to a different same-site URL. (This seems very unlikely in |
| 989 // practice.) |
| 990 if (current_entry) |
| 991 return current_entry->GetURL(); |
| 992 return current_instance->GetSiteURL(); |
| 993 } |
| 994 |
978 void RenderFrameHostManager::CreateRenderFrameHostForNewSiteInstance( | 995 void RenderFrameHostManager::CreateRenderFrameHostForNewSiteInstance( |
979 SiteInstance* old_instance, | 996 SiteInstance* old_instance, |
980 SiteInstance* new_instance, | 997 SiteInstance* new_instance, |
981 bool is_main_frame) { | 998 bool is_main_frame) { |
982 // Ensure that we have created RFHs for the new RFH's opener chain if | 999 // Ensure that we have created RFHs for the new RFH's opener chain if |
983 // we are staying in the same BrowsingInstance. This allows the new RFH | 1000 // we are staying in the same BrowsingInstance. This allows the new RFH |
984 // to send cross-process script calls to its opener(s). | 1001 // to send cross-process script calls to its opener(s). |
985 int opener_route_id = MSG_ROUTING_NONE; | 1002 int opener_route_id = MSG_ROUTING_NONE; |
986 if (new_instance->IsRelatedSiteInstance(old_instance)) { | 1003 if (new_instance->IsRelatedSiteInstance(old_instance)) { |
987 opener_route_id = | 1004 opener_route_id = |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 proxy_routing_id, | 1202 proxy_routing_id, |
1186 for_main_frame_navigation); | 1203 for_main_frame_navigation); |
1187 } | 1204 } |
1188 | 1205 |
1189 bool RenderFrameHostManager::InitRenderFrame( | 1206 bool RenderFrameHostManager::InitRenderFrame( |
1190 RenderFrameHostImpl* render_frame_host) { | 1207 RenderFrameHostImpl* render_frame_host) { |
1191 if (render_frame_host->IsRenderFrameLive()) | 1208 if (render_frame_host->IsRenderFrameLive()) |
1192 return true; | 1209 return true; |
1193 | 1210 |
1194 int parent_routing_id = MSG_ROUTING_NONE; | 1211 int parent_routing_id = MSG_ROUTING_NONE; |
| 1212 int proxy_routing_id = MSG_ROUTING_NONE; |
1195 if (frame_tree_node_->parent()) { | 1213 if (frame_tree_node_->parent()) { |
1196 parent_routing_id = frame_tree_node_->parent()->render_manager()-> | 1214 parent_routing_id = frame_tree_node_->parent()->render_manager()-> |
1197 GetRoutingIdForSiteInstance(render_frame_host->GetSiteInstance()); | 1215 GetRoutingIdForSiteInstance(render_frame_host->GetSiteInstance()); |
1198 CHECK_NE(parent_routing_id, MSG_ROUTING_NONE); | 1216 CHECK_NE(parent_routing_id, MSG_ROUTING_NONE); |
1199 } | 1217 } |
| 1218 // Check whether there is an existing proxy for this frame in this |
| 1219 // SiteInstance. If there is, the new RenderFrame needs to be able to find |
| 1220 // the proxy it is replacing, so that it can fully initialize itself. |
| 1221 // NOTE: This is the only time that a RenderFrameProxyHost can be in the same |
| 1222 // SiteInstance as its RenderFrameHost. This is only the case until the |
| 1223 // RenderFrameHost commits, at which point it will replace and delete the |
| 1224 // RenderFrameProxyHost. |
| 1225 RenderFrameProxyHost* existing_proxy = |
| 1226 GetRenderFrameProxyHost(render_frame_host->GetSiteInstance()); |
| 1227 if (existing_proxy) { |
| 1228 proxy_routing_id = existing_proxy->GetRoutingID(); |
| 1229 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE); |
| 1230 } |
1200 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, | 1231 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, |
1201 parent_routing_id); | 1232 parent_routing_id, |
| 1233 proxy_routing_id); |
1202 } | 1234 } |
1203 | 1235 |
1204 int RenderFrameHostManager::GetRoutingIdForSiteInstance( | 1236 int RenderFrameHostManager::GetRoutingIdForSiteInstance( |
1205 SiteInstance* site_instance) { | 1237 SiteInstance* site_instance) { |
1206 if (render_frame_host_->GetSiteInstance() == site_instance) | 1238 if (render_frame_host_->GetSiteInstance() == site_instance) |
1207 return render_frame_host_->GetRoutingID(); | 1239 return render_frame_host_->GetRoutingID(); |
1208 | 1240 |
1209 RenderFrameProxyHostMap::iterator iter = | 1241 RenderFrameProxyHostMap::iterator iter = |
1210 proxy_hosts_.find(site_instance->GetId()); | 1242 proxy_hosts_.find(site_instance->GetId()); |
1211 if (iter != proxy_hosts_.end()) | 1243 if (iter != proxy_hosts_.end()) |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1652 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
1621 SiteInstance* instance) { | 1653 SiteInstance* instance) { |
1622 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1654 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
1623 if (iter != proxy_hosts_.end()) { | 1655 if (iter != proxy_hosts_.end()) { |
1624 delete iter->second; | 1656 delete iter->second; |
1625 proxy_hosts_.erase(iter); | 1657 proxy_hosts_.erase(iter); |
1626 } | 1658 } |
1627 } | 1659 } |
1628 | 1660 |
1629 } // namespace content | 1661 } // namespace content |
OLD | NEW |