• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_COOKIES_COOKIE_ACCESS_RESULT_H_
6 #define NET_COOKIES_COOKIE_ACCESS_RESULT_H_
7 
8 #include <ostream>
9 
10 #include "net/base/net_export.h"
11 #include "net/cookies/cookie_constants.h"
12 #include "net/cookies/cookie_inclusion_status.h"
13 
14 namespace net {
15 
16 struct NET_EXPORT CookieAccessResult {
17   // Creating a CookieAccessResult with out any parameters will create a
18   // CookieInclusionStatus that has no exclusion reasons, therefore
19   // indicates inclusion.
20   CookieAccessResult();
21   CookieAccessResult(CookieEffectiveSameSite effective_same_site,
22                      CookieInclusionStatus status,
23                      CookieAccessSemantics access_semantics,
24                      bool is_allowed_to_access_secure_cookie);
25 
26   explicit CookieAccessResult(CookieInclusionStatus status);
27 
28   CookieAccessResult(const CookieAccessResult& cookie_access_result);
29 
30   CookieAccessResult& operator=(const CookieAccessResult& cookie_access_result);
31 
32   CookieAccessResult(CookieAccessResult&& cookie_access_result);
33 
34   ~CookieAccessResult();
35 
36   bool operator==(const CookieAccessResult& other) const {
37     return status == other.status &&
38            effective_same_site == other.effective_same_site &&
39            access_semantics == other.access_semantics &&
40            is_allowed_to_access_secure_cookies ==
41                other.is_allowed_to_access_secure_cookies;
42   }
43 
44   CookieInclusionStatus status;
45   CookieEffectiveSameSite effective_same_site =
46       CookieEffectiveSameSite::UNDEFINED;
47   CookieAccessSemantics access_semantics = CookieAccessSemantics::UNKNOWN;
48   // Whether access to Secure cookies should be allowed. This is expected to be
49   // set based on the scheme of the source URL.
50   bool is_allowed_to_access_secure_cookies = false;
51 };
52 
53 // Provided to allow gtest to create more helpful error messages, instead of
54 // printing hex.
PrintTo(const CookieAccessResult & car,std::ostream * os)55 inline void PrintTo(const CookieAccessResult& car, std::ostream* os) {
56   *os << "{ { ";
57   PrintTo(car.status, os);
58   *os << " }, effective_same_site=" << static_cast<int>(car.effective_same_site)
59       << ", access_semantics=" << static_cast<int>(car.access_semantics)
60       << ", is_allowed_to_access_secure_cookies="
61       << car.is_allowed_to_access_secure_cookies << " }";
62 }
63 
64 }  // namespace net
65 
66 #endif  // NET_COOKIES_COOKIE_ACCESS_RESULT_H_
67