site_isolation_policy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_SITE_ISOLATION_SITE_ISOLATION_POLICY_H_
  5. #define COMPONENTS_SITE_ISOLATION_SITE_ISOLATION_POLICY_H_
  6. #include <vector>
  7. #include "content/public/browser/child_process_security_policy.h"
  8. class GURL;
  9. namespace content {
  10. enum class SiteIsolationMode;
  11. class BrowserContext;
  12. }
  13. namespace url {
  14. class Origin;
  15. }
  16. namespace site_isolation {
  17. // A centralized place for making policy decisions about site isolation modes
  18. // which can be shared between content embedders. This supplements
  19. // content::SiteIsolationPolicy with features that may be useful to embedders.
  20. //
  21. // These methods can be called from any thread.
  22. class SiteIsolationPolicy {
  23. public:
  24. SiteIsolationPolicy() = delete;
  25. SiteIsolationPolicy(const SiteIsolationPolicy&) = delete;
  26. SiteIsolationPolicy& operator=(const SiteIsolationPolicy&) = delete;
  27. // Returns true if the site isolation mode for isolating sites where users
  28. // enter passwords is enabled.
  29. static bool IsIsolationForPasswordSitesEnabled();
  30. // Returns true if the site isolation mode for isolating sites where users
  31. // log in via OAuth, as determined by runtime heuristics.
  32. static bool IsIsolationForOAuthSitesEnabled();
  33. // Returns true if Site Isolation related enterprise policies should take
  34. // effect (e.g. such policies might not be applicable to low-end Android
  35. // devices because of 1) performance impact and 2) infeasibility of
  36. // Spectre-like attacks on such devices).
  37. static bool IsEnterprisePolicyApplicable();
  38. // Saves a new dynamic isolated origin to user prefs associated with
  39. // `context` so that it can be persisted across restarts. `source`
  40. // specifies why the isolated origin was added; different sources may have
  41. // different persistence policies.
  42. static void PersistIsolatedOrigin(
  43. content::BrowserContext* context,
  44. const url::Origin& origin,
  45. content::ChildProcessSecurityPolicy::IsolatedOriginSource source);
  46. // Reads and applies any isolated origins stored in user prefs associated with
  47. // |browser_context|. This is expected to be called on startup after user
  48. // prefs have been loaded.
  49. static void ApplyPersistedIsolatedOrigins(
  50. content::BrowserContext* browser_context);
  51. // Helper to register all passed-in `logged_in_sites` as isolated sites in
  52. // the provided `browser_context`. Should be called on startup before any
  53. // navigations in `browser_context`.
  54. static void IsolateStoredOAuthSites(
  55. content::BrowserContext* browser_context,
  56. const std::vector<url::Origin>& logged_in_sites);
  57. // Called when runtime heuristics have determined a user logging in via
  58. // OAuth on `signed_in_url`, so that site isolation can be applied to the
  59. // corresponding site (i.e., scheme + eTLD+1). Used only when site isolation
  60. // for OAuth sites is enabled (see IsIsolationForOAuthSitesEnabled() above),
  61. // which is typically on Android.
  62. static void IsolateNewOAuthURL(content::BrowserContext* browser_context,
  63. const GURL& signed_in_url);
  64. // Determines whether Site Isolation should be disabled because the device
  65. // does not have the minimum required amount of memory. `site_isolation_mode`
  66. // determines the type of memory threshold to apply; for example, strict site
  67. // isolation on Android might require a higher memory threshold than partial
  68. // site isolation.
  69. static bool ShouldDisableSiteIsolationDueToMemoryThreshold(
  70. content::SiteIsolationMode site_isolation_mode);
  71. // Returns true if the PDF compositor should be enabled to allow out-of-
  72. // process iframes (OOPIF's) to print properly.
  73. static bool ShouldPdfCompositorBeEnabledForOopifs();
  74. // When set to true bypasses the caching of the results of
  75. // ShouldDisableSiteIsolationDueToMemoryThreshold(). Setting to false reverts
  76. // to the default behavior (caching is controlled by a base::Feature).
  77. static void SetDisallowMemoryThresholdCachingForTesting(
  78. bool disallow_caching);
  79. private:
  80. // Helpers for implementing PersistIsolatedOrigin().
  81. static void PersistUserTriggeredIsolatedOrigin(
  82. content::BrowserContext* context,
  83. const url::Origin& origin);
  84. static void PersistWebTriggeredIsolatedOrigin(
  85. content::BrowserContext* context,
  86. const url::Origin& origin);
  87. };
  88. } // namespace site_isolation
  89. #endif // COMPONENTS_SITE_ISOLATION_SITE_ISOLATION_POLICY_H_