OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/tab_contents/render_view_host_manager.h" | 5 #include "chrome/browser/tab_contents/render_view_host_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/dom_ui/dom_ui.h" | 9 #include "chrome/browser/dom_ui/dom_ui.h" |
10 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 10 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // True if we are using process-per-site-instance (default) or | 285 // True if we are using process-per-site-instance (default) or |
286 // process-per-site (kProcessPerSite). | 286 // process-per-site (kProcessPerSite). |
287 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); | 287 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); |
288 } | 288 } |
289 | 289 |
290 bool RenderViewHostManager::ShouldSwapProcessesForNavigation( | 290 bool RenderViewHostManager::ShouldSwapProcessesForNavigation( |
291 const NavigationEntry* cur_entry, | 291 const NavigationEntry* cur_entry, |
292 const NavigationEntry* new_entry) const { | 292 const NavigationEntry* new_entry) const { |
293 DCHECK(new_entry); | 293 DCHECK(new_entry); |
294 | 294 |
| 295 // Check for reasons to swap processes even if we are in a process model that |
| 296 // doesn't usually swap (e.g., process-per-tab). |
| 297 |
| 298 // For security, we should transition between processes when one is a DOM UI |
| 299 // page and one isn't. If there's no cur_entry, check the current RVH's |
| 300 // site, which might already be committed to a DOM UI URL (such as the NTP). |
| 301 const GURL& current_url = (cur_entry) ? cur_entry->url() : |
| 302 render_view_host_->site_instance()->site(); |
| 303 Profile* profile = delegate_->GetControllerForRenderManager().profile(); |
| 304 if (DOMUIFactory::UseDOMUIForURL(profile, current_url)) { |
| 305 // Force swap if it's not an acceptable URL for DOM UI. |
| 306 if (!DOMUIFactory::IsURLAcceptableForDOMUI(profile, new_entry->url())) |
| 307 return true; |
| 308 } else { |
| 309 // Force swap if it's a DOM UI URL. |
| 310 if (DOMUIFactory::UseDOMUIForURL(profile, new_entry->url())) |
| 311 return true; |
| 312 } |
| 313 |
295 if (!cur_entry) { | 314 if (!cur_entry) { |
296 // Always choose a new process when navigating to extension URLs. The | 315 // Always choose a new process when navigating to extension URLs. The |
297 // process grouping logic will combine all of a given extension's pages | 316 // process grouping logic will combine all of a given extension's pages |
298 // into the same process. | 317 // into the same process. |
299 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) | 318 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) |
300 return true; | 319 return true; |
301 // When a tab is created, it starts as TYPE_NORMAL. If the new entry is a | 320 |
302 // DOM UI page, it needs to be grouped with other DOM UI pages. This matches | |
303 // the logic when transitioning between DOM UI and normal pages. | |
304 Profile* profile = delegate_->GetControllerForRenderManager().profile(); | |
305 if (DOMUIFactory::UseDOMUIForURL(profile, new_entry->url())) | |
306 return true; | |
307 return false; | 321 return false; |
308 } | 322 } |
309 | 323 |
310 // We can't switch a RenderView between view source and non-view source mode | 324 // We can't switch a RenderView between view source and non-view source mode |
311 // without screwing up the session history sometimes (when navigating between | 325 // without screwing up the session history sometimes (when navigating between |
312 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat | 326 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat |
313 // it as a new navigation). So require a view switch. | 327 // it as a new navigation). So require a view switch. |
314 if (cur_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) | 328 if (cur_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) |
315 return true; | 329 return true; |
316 | 330 |
317 // For security, we should transition between processes when one is a DOM UI | |
318 // page and one isn't. | |
319 Profile* profile = delegate_->GetControllerForRenderManager().profile(); | |
320 if (DOMUIFactory::UseDOMUIForURL(profile, cur_entry->url())) { | |
321 // Force swap if it's not an acceptable URL for DOM UI. | |
322 if (!DOMUIFactory::IsURLAcceptableForDOMUI(profile, new_entry->url())) | |
323 return true; | |
324 } else { | |
325 // Force swap if it's a DOM UI URL. | |
326 if (DOMUIFactory::UseDOMUIForURL(profile, new_entry->url())) | |
327 return true; | |
328 } | |
329 | |
330 // Also, we must switch if one is an extension and the other is not the exact | 331 // Also, we must switch if one is an extension and the other is not the exact |
331 // same extension. | 332 // same extension. |
332 if (cur_entry->url().SchemeIs(chrome::kExtensionScheme) || | 333 if (cur_entry->url().SchemeIs(chrome::kExtensionScheme) || |
333 new_entry->url().SchemeIs(chrome::kExtensionScheme)) { | 334 new_entry->url().SchemeIs(chrome::kExtensionScheme)) { |
334 if (cur_entry->url().GetOrigin() != new_entry->url().GetOrigin()) | 335 if (cur_entry->url().GetOrigin() != new_entry->url().GetOrigin()) |
335 return true; | 336 return true; |
336 } | 337 } |
337 | 338 |
338 return false; | 339 return false; |
339 } | 340 } |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 Source<NavigationController>(&delegate_->GetControllerForRenderManager()), | 720 Source<NavigationController>(&delegate_->GetControllerForRenderManager()), |
720 Details<RenderViewHostSwitchedDetails>(&details)); | 721 Details<RenderViewHostSwitchedDetails>(&details)); |
721 | 722 |
722 // This will cause the old RenderViewHost to delete itself. | 723 // This will cause the old RenderViewHost to delete itself. |
723 old_render_view_host->Shutdown(); | 724 old_render_view_host->Shutdown(); |
724 | 725 |
725 // Let the task manager know that we've swapped RenderViewHosts, since it | 726 // Let the task manager know that we've swapped RenderViewHosts, since it |
726 // might need to update its process groupings. | 727 // might need to update its process groupings. |
727 delegate_->NotifySwappedFromRenderManager(); | 728 delegate_->NotifySwappedFromRenderManager(); |
728 } | 729 } |
OLD | NEW |