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