| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/site_isolation_policy.h" | 5 #include "content/common/site_isolation_policy.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "content/public/common/content_client.h" | 9 #include "content/public/common/content_client.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 16 class SiteIsolationWhitelist { | |
| 17 public: | |
| 18 SiteIsolationWhitelist() { | |
| 19 // Call into the embedder to get the list of isolated schemes from the | |
| 20 // command-line configuration. | |
| 21 // | |
| 22 // TODO(nick): https://crbug.com/133403 Because the AtExitManager doesn't | |
| 23 // run between unit tests, it's not possible for unit tests to safely alter | |
| 24 // the isolated schemes here. | |
| 25 GetContentClient()->AddIsolatedSchemes(&isolated_schemes_); | |
| 26 } | |
| 27 ~SiteIsolationWhitelist() {} | |
| 28 | |
| 29 const std::set<std::string>& isolated_schemes() const { | |
| 30 return isolated_schemes_; | |
| 31 } | |
| 32 | |
| 33 bool should_isolate_all_sites() const { | |
| 34 // TODO(nick): https://crbug.com/133403 We ought to cache the value of this | |
| 35 // switch here, but cannot because the AtExitManager doesn't run between | |
| 36 // unit tests. | |
| 37 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 38 switches::kSitePerProcess); | |
| 39 } | |
| 40 | |
| 41 private: | |
| 42 std::set<std::string> isolated_schemes_; | |
| 43 DISALLOW_COPY_AND_ASSIGN(SiteIsolationWhitelist); | |
| 44 }; | |
| 45 | |
| 46 base::LazyInstance<SiteIsolationWhitelist> g_site_isolation_whitelist = | |
| 47 LAZY_INSTANCE_INITIALIZER; | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 51 // static | 14 // static |
| 52 bool SiteIsolationPolicy::AreCrossProcessFramesPossible() { | 15 bool SiteIsolationPolicy::AreCrossProcessFramesPossible() { |
| 53 const SiteIsolationWhitelist& whitelist = g_site_isolation_whitelist.Get(); | 16 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 54 return whitelist.should_isolate_all_sites() || | 17 switches::kSitePerProcess) || |
| 55 !whitelist.isolated_schemes().empty(); | 18 GetContentClient()->IsSupplementarySiteIsolationModeEnabled(); |
| 56 } | 19 } |
| 57 | 20 |
| 58 // static | 21 // static |
| 59 bool SiteIsolationPolicy::DoesSiteRequireDedicatedProcess( | 22 bool SiteIsolationPolicy::UseDedicatedProcessesForAllSites() { |
| 60 const GURL& effective_url) { | 23 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 61 const SiteIsolationWhitelist& whitelist = g_site_isolation_whitelist.Get(); | 24 switches::kSitePerProcess); |
| 62 return whitelist.should_isolate_all_sites() || | |
| 63 (!whitelist.isolated_schemes().empty() && | |
| 64 whitelist.isolated_schemes().count(effective_url.scheme())); | |
| 65 } | 25 } |
| 66 | 26 |
| 67 // static | 27 // static |
| 68 bool SiteIsolationPolicy::UseSubframeNavigationEntries() { | 28 bool SiteIsolationPolicy::UseSubframeNavigationEntries() { |
| 69 // Enable the new navigation history behavior if any manner of site isolation | 29 // Enable the new navigation history behavior if any manner of site isolation |
| 70 // is active. | 30 // is active. |
| 71 return AreCrossProcessFramesPossible(); | 31 return AreCrossProcessFramesPossible(); |
| 72 } | 32 } |
| 73 | 33 |
| 74 // static | 34 // static |
| 75 bool SiteIsolationPolicy::IsSwappedOutStateForbidden() { | 35 bool SiteIsolationPolicy::IsSwappedOutStateForbidden() { |
| 76 return AreCrossProcessFramesPossible(); | 36 return AreCrossProcessFramesPossible(); |
| 77 } | 37 } |
| 78 | 38 |
| 79 // static | |
| 80 bool SiteIsolationPolicy::IsolateAllSitesForTesting() { | |
| 81 // TODO(nick): Re-enable once https://crbug.com/133403 is fixed. | |
| 82 // if (!(g_site_isolation_whitelist == nullptr)) return false; | |
| 83 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 84 switches::kSitePerProcess); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 } // namespace content | 39 } // namespace content |
| OLD | NEW |