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->IsSecure());
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 dict.Set("same_party", cookie->IsSameParty());
37 return dict;
38 }
39
NetLogCookieMonsterCookieDeleted(const CanonicalCookie * cookie,CookieChangeCause cause,bool sync_requested,NetLogCaptureMode capture_mode)40 base::Value::Dict NetLogCookieMonsterCookieDeleted(
41 const CanonicalCookie* cookie,
42 CookieChangeCause cause,
43 bool sync_requested,
44 NetLogCaptureMode capture_mode) {
45 if (!NetLogCaptureIncludesSensitive(capture_mode))
46 return base::Value::Dict();
47
48 base::Value::Dict dict;
49 dict.Set("name", cookie->Name());
50 dict.Set("value", cookie->Value());
51 dict.Set("domain", cookie->Domain());
52 dict.Set("path", cookie->Path());
53 dict.Set("is_persistent", cookie->IsPersistent());
54 dict.Set("deletion_cause", CookieChangeCauseToString(cause));
55 dict.Set("sync_requested", sync_requested);
56 return dict;
57 }
58
NetLogCookieMonsterCookieRejectedSecure(const CanonicalCookie * old_cookie,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)59 base::Value::Dict NetLogCookieMonsterCookieRejectedSecure(
60 const CanonicalCookie* old_cookie,
61 const CanonicalCookie* new_cookie,
62 NetLogCaptureMode capture_mode) {
63 if (!NetLogCaptureIncludesSensitive(capture_mode))
64 return base::Value::Dict();
65 base::Value::Dict dict;
66 dict.Set("name", old_cookie->Name());
67 dict.Set("domain", old_cookie->Domain());
68 dict.Set("oldpath", old_cookie->Path());
69 dict.Set("newpath", new_cookie->Path());
70 dict.Set("oldvalue", old_cookie->Value());
71 dict.Set("newvalue", new_cookie->Value());
72 return dict;
73 }
74
NetLogCookieMonsterCookieRejectedHttponly(const CanonicalCookie * old_cookie,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)75 base::Value::Dict NetLogCookieMonsterCookieRejectedHttponly(
76 const CanonicalCookie* old_cookie,
77 const CanonicalCookie* new_cookie,
78 NetLogCaptureMode capture_mode) {
79 if (!NetLogCaptureIncludesSensitive(capture_mode))
80 return base::Value::Dict();
81 base::Value::Dict dict;
82 dict.Set("name", old_cookie->Name());
83 dict.Set("domain", old_cookie->Domain());
84 dict.Set("path", old_cookie->Path());
85 dict.Set("oldvalue", old_cookie->Value());
86 dict.Set("newvalue", new_cookie->Value());
87 return dict;
88 }
89
NetLogCookieMonsterCookiePreservedSkippedSecure(const CanonicalCookie * skipped_secure,const CanonicalCookie * preserved,const CanonicalCookie * new_cookie,NetLogCaptureMode capture_mode)90 base::Value::Dict NetLogCookieMonsterCookiePreservedSkippedSecure(
91 const CanonicalCookie* skipped_secure,
92 const CanonicalCookie* preserved,
93 const CanonicalCookie* new_cookie,
94 NetLogCaptureMode capture_mode) {
95 if (!NetLogCaptureIncludesSensitive(capture_mode))
96 return base::Value::Dict();
97 base::Value::Dict dict;
98 dict.Set("name", preserved->Name());
99 dict.Set("domain", preserved->Domain());
100 dict.Set("path", preserved->Path());
101 dict.Set("securecookiedomain", skipped_secure->Domain());
102 dict.Set("securecookiepath", skipped_secure->Path());
103 dict.Set("preservedvalue", preserved->Value());
104 dict.Set("discardedvalue", new_cookie->Value());
105 return dict;
106 }
107
108 } // namespace net
109