aw_cookie_access_policy.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 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_AW_COOKIE_ACCESS_POLICY_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_
  6. #include "base/no_destructor.h"
  7. #include "base/synchronization/lock.h"
  8. class GURL;
  9. namespace net {
  10. class SiteForCookies;
  11. } // namespace net
  12. namespace android_webview {
  13. // Manages the cookie access (both setting and getting) policy for WebView.
  14. // Currently we don't distinguish between sources (i.e. network vs. JavaScript)
  15. // or between reading vs. writing cookies.
  16. class AwCookieAccessPolicy {
  17. public:
  18. static AwCookieAccessPolicy* GetInstance();
  19. AwCookieAccessPolicy(const AwCookieAccessPolicy&) = delete;
  20. AwCookieAccessPolicy& operator=(const AwCookieAccessPolicy&) = delete;
  21. // Can we read/write any cookies? Can be called from any thread.
  22. bool GetShouldAcceptCookies();
  23. void SetShouldAcceptCookies(bool allow);
  24. // Can we read/write third party cookies?
  25. // |render_process_id| and |render_frame_id| must be valid.
  26. // Navigation requests are not associated with a renderer process. In this
  27. // case, |frame_tree_node_id| must be valid instead. Can only be called from
  28. // the IO thread.
  29. bool GetShouldAcceptThirdPartyCookies(int render_process_id,
  30. int render_frame_id,
  31. int frame_tree_node_id);
  32. // Whether or not to allow cookies for requests with these parameters.
  33. bool AllowCookies(const GURL& url,
  34. const net::SiteForCookies& site_for_cookies,
  35. int render_process_id,
  36. int render_frame_id);
  37. private:
  38. friend class base::NoDestructor<AwCookieAccessPolicy>;
  39. friend class AwCookieAccessPolicyTest;
  40. AwCookieAccessPolicy();
  41. ~AwCookieAccessPolicy();
  42. bool CanAccessCookies(const GURL& url,
  43. const net::SiteForCookies& site_for_cookies,
  44. bool accept_third_party_cookies);
  45. bool accept_cookies_;
  46. base::Lock lock_;
  47. };
  48. } // namespace android_webview
  49. #endif // ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_