OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/chrome_content_browser_client_extensions_par
t.h" | 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par
t.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 const GURL& current_url, | 412 const GURL& current_url, |
413 const GURL& new_url) { | 413 const GURL& new_url) { |
414 // If we don't have an ExtensionRegistry, then rely on the SiteInstance logic | 414 // If we don't have an ExtensionRegistry, then rely on the SiteInstance logic |
415 // in RenderFrameHostManager to decide when to swap. | 415 // in RenderFrameHostManager to decide when to swap. |
416 ExtensionRegistry* registry = | 416 ExtensionRegistry* registry = |
417 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 417 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
418 if (!registry) | 418 if (!registry) |
419 return false; | 419 return false; |
420 | 420 |
421 // We must use a new BrowsingInstance (forcing a process swap and disabling | 421 // We must use a new BrowsingInstance (forcing a process swap and disabling |
422 // scripting by existing tabs) if one of the URLs is an extension and the | 422 // scripting by existing tabs) if one of the URLs corresponds to the Chrome |
423 // other is not the exact same extension. | 423 // Web Store hosted app, and the other does not. |
424 // | 424 // |
425 // We ignore hosted apps here so that other tabs in their BrowsingInstance can | 425 // We don't force a BrowsingInstance swap in other cases (i.e., when opening |
426 // use postMessage with them. (The exception is the Chrome Web Store, which | 426 // a popup from one extension to a different extension, or to a non-extension |
427 // is a hosted app that requires its own BrowsingInstance.) Navigations | 427 // URL) to preserve script connections and allow use cases like postMessage |
428 // to/from a hosted app will still trigger a SiteInstance swap in | 428 // via window.opener. Those cases would still force a SiteInstance swap in |
429 // RenderFrameHostManager. | 429 // RenderFrameHostManager. This behavior is similar to how extension |
| 430 // subframes on a web main frame are also placed in the same BrowsingInstance |
| 431 // (by the content/ part of ShouldSwapBrowsingInstancesForNavigation); this |
| 432 // check is just doing the same for top-level frames. See |
| 433 // https://crbug.com/590068. |
430 const Extension* current_extension = | 434 const Extension* current_extension = |
431 registry->enabled_extensions().GetExtensionOrAppByURL(current_url); | 435 registry->enabled_extensions().GetExtensionOrAppByURL(current_url); |
432 if (current_extension && current_extension->is_hosted_app() && | 436 bool is_current_url_for_web_store = |
433 current_extension->id() != kWebStoreAppId) | 437 current_extension && current_extension->id() == kWebStoreAppId; |
434 current_extension = NULL; | |
435 | 438 |
436 const Extension* new_extension = | 439 const Extension* new_extension = |
437 registry->enabled_extensions().GetExtensionOrAppByURL(new_url); | 440 registry->enabled_extensions().GetExtensionOrAppByURL(new_url); |
438 if (new_extension && new_extension->is_hosted_app() && | 441 bool is_new_url_for_web_store = |
439 new_extension->id() != kWebStoreAppId) | 442 new_extension && new_extension->id() == kWebStoreAppId; |
440 new_extension = NULL; | |
441 | 443 |
442 // First do a process check. We should force a BrowsingInstance swap if the | 444 // First do a process check. We should force a BrowsingInstance swap if we |
443 // current process doesn't know about new_extension, even if current_extension | 445 // are going to Chrome Web Store, but the current process doesn't know about |
444 // is somehow the same as new_extension. | 446 // CWS, even if current_extension somehow corresponds to CWS. |
445 ProcessMap* process_map = ProcessMap::Get(site_instance->GetBrowserContext()); | 447 ProcessMap* process_map = ProcessMap::Get(site_instance->GetBrowserContext()); |
446 if (new_extension && | 448 if (is_new_url_for_web_store && site_instance->HasProcess() && |
447 site_instance->HasProcess() && | 449 !process_map->Contains(new_extension->id(), |
448 !process_map->Contains( | 450 site_instance->GetProcess()->GetID())) |
449 new_extension->id(), site_instance->GetProcess()->GetID())) | |
450 return true; | 451 return true; |
451 | 452 |
452 // Otherwise, swap BrowsingInstances if current_extension and new_extension | 453 // Otherwise, swap BrowsingInstances when transitioning to/from Chrome Web |
453 // differ. | 454 // Store. |
454 return current_extension != new_extension; | 455 return is_current_url_for_web_store != is_new_url_for_web_store; |
455 } | 456 } |
456 | 457 |
457 // static | 458 // static |
458 bool ChromeContentBrowserClientExtensionsPart::ShouldSwapProcessesForRedirect( | 459 bool ChromeContentBrowserClientExtensionsPart::ShouldSwapProcessesForRedirect( |
459 content::BrowserContext* browser_context, | 460 content::BrowserContext* browser_context, |
460 const GURL& current_url, | 461 const GURL& current_url, |
461 const GURL& new_url) { | 462 const GURL& new_url) { |
462 return CrossesExtensionProcessBoundary( | 463 return CrossesExtensionProcessBoundary( |
463 ExtensionRegistry::Get(browser_context)->enabled_extensions(), | 464 ExtensionRegistry::Get(browser_context)->enabled_extensions(), |
464 current_url, new_url, false); | 465 current_url, new_url, false); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 } | 686 } |
686 } | 687 } |
687 } | 688 } |
688 | 689 |
689 void ChromeContentBrowserClientExtensionsPart::ResourceDispatcherHostCreated() { | 690 void ChromeContentBrowserClientExtensionsPart::ResourceDispatcherHostCreated() { |
690 content::ResourceDispatcherHost::Get()->RegisterInterceptor( | 691 content::ResourceDispatcherHost::Get()->RegisterInterceptor( |
691 "Origin", kExtensionScheme, base::Bind(&OnHttpHeaderReceived)); | 692 "Origin", kExtensionScheme, base::Bind(&OnHttpHeaderReceived)); |
692 } | 693 } |
693 | 694 |
694 } // namespace extensions | 695 } // namespace extensions |
OLD | NEW |