aw_proxying_restricted_cookie_manager.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_PROXYING_RESTRICTED_COOKIE_MANAGER_H_
  5. #define ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_PROXYING_RESTRICTED_COOKIE_MANAGER_H_
  6. #include <string>
  7. #include "base/memory/weak_ptr.h"
  8. #include "mojo/public/cpp/bindings/remote.h"
  9. #include "services/network/public/mojom/restricted_cookie_manager.mojom.h"
  10. class GURL;
  11. namespace android_webview {
  12. // A RestrictedCookieManager which conditionally proxies to an underlying
  13. // RestrictedCookieManager, first consulting WebView's cookie settings.
  14. class AwProxyingRestrictedCookieManager
  15. : public network::mojom::RestrictedCookieManager {
  16. public:
  17. // Creates a AwProxyingRestrictedCookieManager that lives on IO thread,
  18. // binding it to handle communications from |receiver|. The requests will be
  19. // delegated to |underlying_rcm|. The resulting object will be owned by the
  20. // pipe corresponding to |request| and will in turn own |underlying_rcm|.
  21. //
  22. // Expects to be called on the UI thread.
  23. static void CreateAndBind(
  24. mojo::PendingRemote<network::mojom::RestrictedCookieManager>
  25. underlying_rcm,
  26. bool is_service_worker,
  27. int process_id,
  28. int frame_id,
  29. mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver);
  30. AwProxyingRestrictedCookieManager(const AwProxyingRestrictedCookieManager&) =
  31. delete;
  32. AwProxyingRestrictedCookieManager& operator=(
  33. const AwProxyingRestrictedCookieManager&) = delete;
  34. ~AwProxyingRestrictedCookieManager() override;
  35. // network::mojom::RestrictedCookieManager interface:
  36. void GetAllForUrl(const GURL& url,
  37. const net::SiteForCookies& site_for_cookies,
  38. const url::Origin& top_frame_origin,
  39. network::mojom::CookieManagerGetOptionsPtr options,
  40. bool partitioned_cookies_runtime_feature_enabled,
  41. GetAllForUrlCallback callback) override;
  42. void SetCanonicalCookie(const net::CanonicalCookie& cookie,
  43. const GURL& url,
  44. const net::SiteForCookies& site_for_cookies,
  45. const url::Origin& top_frame_origin,
  46. net::CookieInclusionStatus status,
  47. SetCanonicalCookieCallback callback) override;
  48. void AddChangeListener(
  49. const GURL& url,
  50. const net::SiteForCookies& site_for_cookies,
  51. const url::Origin& top_frame_origin,
  52. mojo::PendingRemote<network::mojom::CookieChangeListener> listener,
  53. AddChangeListenerCallback callback) override;
  54. void SetCookieFromString(const GURL& url,
  55. const net::SiteForCookies& site_for_cookies,
  56. const url::Origin& top_frame_origin,
  57. const std::string& cookie,
  58. bool partitioned_cookies_runtime_feature_enabled,
  59. SetCookieFromStringCallback callback) override;
  60. void GetCookiesString(const GURL& url,
  61. const net::SiteForCookies& site_for_cookies,
  62. const url::Origin& top_frame_origin,
  63. bool partitioned_cookies_runtime_feature_enabled,
  64. GetCookiesStringCallback callback) override;
  65. void CookiesEnabledFor(const GURL& url,
  66. const net::SiteForCookies& site_for_cookies,
  67. const url::Origin& top_frame_origin,
  68. CookiesEnabledForCallback callback) override;
  69. // This one is internal.
  70. bool AllowCookies(const GURL& url,
  71. const net::SiteForCookies& site_for_cookies) const;
  72. // TODO(https://crbug.com/1296161): Delete this function.
  73. void ConvertPartitionedCookiesToUnpartitioned(const GURL& url) override;
  74. private:
  75. AwProxyingRestrictedCookieManager(
  76. mojo::PendingRemote<network::mojom::RestrictedCookieManager>
  77. underlying_restricted_cookie_manager,
  78. bool is_service_worker,
  79. int process_id,
  80. int frame_id);
  81. static void CreateAndBindOnIoThread(
  82. mojo::PendingRemote<network::mojom::RestrictedCookieManager>
  83. underlying_rcm,
  84. bool is_service_worker,
  85. int process_id,
  86. int frame_id,
  87. mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver);
  88. mojo::Remote<network::mojom::RestrictedCookieManager>
  89. underlying_restricted_cookie_manager_;
  90. bool is_service_worker_;
  91. int process_id_;
  92. int frame_id_;
  93. base::WeakPtrFactory<AwProxyingRestrictedCookieManager> weak_factory_{this};
  94. };
  95. } // namespace android_webview
  96. #endif // ANDROID_WEBVIEW_BROWSER_NETWORK_SERVICE_AW_PROXYING_RESTRICTED_COOKIE_MANAGER_H_