cookie_access_result.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 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 NET_COOKIES_COOKIE_ACCESS_RESULT_H_
  5. #define NET_COOKIES_COOKIE_ACCESS_RESULT_H_
  6. #include <ostream>
  7. #include "net/base/net_export.h"
  8. #include "net/cookies/cookie_constants.h"
  9. #include "net/cookies/cookie_inclusion_status.h"
  10. namespace net {
  11. struct NET_EXPORT CookieAccessResult {
  12. // Creating a CookieAccessResult with out any parameters will create a
  13. // CookieInclusionStatus that has no exclusion reasons, therefore
  14. // indicates inclusion.
  15. CookieAccessResult();
  16. CookieAccessResult(CookieEffectiveSameSite effective_same_site,
  17. CookieInclusionStatus status,
  18. CookieAccessSemantics access_semantics,
  19. bool is_allowed_to_access_secure_cookie);
  20. explicit CookieAccessResult(CookieInclusionStatus status);
  21. CookieAccessResult(const CookieAccessResult& cookie_access_result);
  22. CookieAccessResult& operator=(const CookieAccessResult& cookie_access_result);
  23. CookieAccessResult(CookieAccessResult&& cookie_access_result);
  24. ~CookieAccessResult();
  25. bool operator==(const CookieAccessResult& other) const {
  26. return status == other.status &&
  27. effective_same_site == other.effective_same_site &&
  28. access_semantics == other.access_semantics &&
  29. is_allowed_to_access_secure_cookies ==
  30. other.is_allowed_to_access_secure_cookies;
  31. }
  32. CookieInclusionStatus status;
  33. CookieEffectiveSameSite effective_same_site =
  34. CookieEffectiveSameSite::UNDEFINED;
  35. CookieAccessSemantics access_semantics = CookieAccessSemantics::UNKNOWN;
  36. // Whether access to Secure cookies should be allowed. This is expected to be
  37. // set based on the scheme of the source URL.
  38. bool is_allowed_to_access_secure_cookies = false;
  39. };
  40. // Provided to allow gtest to create more helpful error messages, instead of
  41. // printing hex.
  42. inline void PrintTo(const CookieAccessResult& car, std::ostream* os) {
  43. *os << "{ { ";
  44. PrintTo(car.status, os);
  45. *os << " }, " << static_cast<int>(car.effective_same_site) << ", "
  46. << static_cast<int>(car.access_semantics) << ", "
  47. << car.is_allowed_to_access_secure_cookies << " }";
  48. }
  49. } // namespace net
  50. #endif // NET_COOKIES_COOKIE_ACCESS_RESULT_H_