xref: /aosp_15_r20/external/cronet/net/cookies/cookie_monster_netlog_params.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 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 #include "net/cookies/cookie_monster_netlog_params.h"
6 
7 #include "net/cookies/cookie_constants.h"
8 #include "net/cookies/cookie_store.h"
9 
10 namespace net {
11 
NetLogCookieMonsterConstructorParams(bool persistent_store)12 base::Value::Dict NetLogCookieMonsterConstructorParams(bool persistent_store) {
13   base::Value::Dict dict;
14   dict.Set("persistent_store", persistent_store);
15   return dict;
16 }
17 
NetLogCookieMonsterCookieAdded(const CanonicalCookie * cookie,bool sync_requested,NetLogCaptureMode capture_mode)18 base::Value::Dict NetLogCookieMonsterCookieAdded(
19     const CanonicalCookie* cookie,
20     bool sync_requested,
21     NetLogCaptureMode capture_mode) {
22   if (!NetLogCaptureIncludesSensitive(capture_mode))
23     return base::Value::Dict();
24 
25   base::Value::Dict dict;
26   dict.Set("name", cookie->Name());
27   dict.Set("value", cookie->Value());
28   dict.Set("domain", cookie->Domain());
29   dict.Set("path", cookie->Path());
30   dict.Set("httponly", cookie->IsHttpOnly());
31   dict.Set("secure", cookie->SecureAttribute());
32   dict.Set("priority", CookiePriorityToString(cookie->Priority()));
33   dict.Set("same_site", CookieSameSiteToString(cookie->SameSite()));
34   dict.Set("is_persistent", cookie->IsPersistent());
35   dict.Set("sync_requested", sync_requested);
36   return dict;
37 }
38 
NetLogCookieMonsterCookieDeleted(const CanonicalCookie * cookie,CookieChangeCause cause,bool sync_requested,NetLogCaptureMode capture_mode)39 base::Value::Dict NetLogCookieMonsterCookieDeleted(
40     const CanonicalCookie* cookie,
41     CookieChangeCause cause,
42     bool sync_requested,
43     NetLogCaptureMode capture_mode) {
44   if (!NetLogCaptureIncludesSensitive(capture_mode))
45     return base::Value::Dict();
46 
47   base::Value::Dict dict;
48   dict.Set("name", cookie->Name());
49   dict.Set("value", cookie->Value());
50   dict.Set("domain", cookie->Domain());
51   dict.Set("path", cookie->Path());
52   dict.Set("is_persistent", cookie->IsPersistent());
53   dict.Set("deletion_cause", CookieChangeCauseToString(cause));
54   dict.Set("sync_requested", sync_requested);
55   return dict;
56 }
57 
NetLogCookieMonsterCookieRejectedSecure(const CanonicalCookie * old_cookie,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)58 base::Value::Dict NetLogCookieMonsterCookieRejectedSecure(
59     const CanonicalCookie* old_cookie,
60     const CanonicalCookie* new_cookie,
61     NetLogCaptureMode capture_mode) {
62   if (!NetLogCaptureIncludesSensitive(capture_mode))
63     return base::Value::Dict();
64   base::Value::Dict dict;
65   dict.Set("name", old_cookie->Name());
66   dict.Set("domain", old_cookie->Domain());
67   dict.Set("oldpath", old_cookie->Path());
68   dict.Set("newpath", new_cookie->Path());
69   dict.Set("oldvalue", old_cookie->Value());
70   dict.Set("newvalue", new_cookie->Value());
71   return dict;
72 }
73 
NetLogCookieMonsterCookieRejectedHttponly(const CanonicalCookie * old_cookie,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)74 base::Value::Dict NetLogCookieMonsterCookieRejectedHttponly(
75     const CanonicalCookie* old_cookie,
76     const CanonicalCookie* new_cookie,
77     NetLogCaptureMode capture_mode) {
78   if (!NetLogCaptureIncludesSensitive(capture_mode))
79     return base::Value::Dict();
80   base::Value::Dict dict;
81   dict.Set("name", old_cookie->Name());
82   dict.Set("domain", old_cookie->Domain());
83   dict.Set("path", old_cookie->Path());
84   dict.Set("oldvalue", old_cookie->Value());
85   dict.Set("newvalue", new_cookie->Value());
86   return dict;
87 }
88 
NetLogCookieMonsterCookiePreservedSkippedSecure(const CanonicalCookie * skipped_secure,const CanonicalCookie * preserved,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)89 base::Value::Dict NetLogCookieMonsterCookiePreservedSkippedSecure(
90     const CanonicalCookie* skipped_secure,
91     const CanonicalCookie* preserved,
92     const CanonicalCookie* new_cookie,
93     NetLogCaptureMode capture_mode) {
94   if (!NetLogCaptureIncludesSensitive(capture_mode))
95     return base::Value::Dict();
96   base::Value::Dict dict;
97   dict.Set("name", preserved->Name());
98   dict.Set("domain", preserved->Domain());
99   dict.Set("path", preserved->Path());
100   dict.Set("securecookiedomain", skipped_secure->Domain());
101   dict.Set("securecookiepath", skipped_secure->Path());
102   dict.Set("preservedvalue", preserved->Value());
103   dict.Set("discardedvalue", new_cookie->Value());
104   return dict;
105 }
106 
107 }  // namespace net
108