forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie_constants.cc
352 lines (331 loc) · 10.3 KB
/
cookie_constants.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/cookies/cookie_constants.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "url/url_constants.h"
namespace net {
const base::TimeDelta kLaxAllowUnsafeMaxAge = base::TimeDelta::FromMinutes(2);
const base::TimeDelta kShortLaxAllowUnsafeMaxAge =
base::TimeDelta::FromSeconds(10);
namespace {
const char kPriorityLow[] = "low";
const char kPriorityMedium[] = "medium";
const char kPriorityHigh[] = "high";
const char kSameSiteLax[] = "lax";
const char kSameSiteStrict[] = "strict";
const char kSameSiteNone[] = "none";
const char kSameSiteExtended[] = "extended";
const char kSameSiteUnspecified[] = "unspecified";
} // namespace
std::string CookiePriorityToString(CookiePriority priority) {
switch(priority) {
case COOKIE_PRIORITY_HIGH:
return kPriorityHigh;
case COOKIE_PRIORITY_MEDIUM:
return kPriorityMedium;
case COOKIE_PRIORITY_LOW:
return kPriorityLow;
default:
NOTREACHED();
}
return std::string();
}
CookiePriority StringToCookiePriority(const std::string& priority) {
std::string priority_comp = base::ToLowerASCII(priority);
if (priority_comp == kPriorityHigh)
return COOKIE_PRIORITY_HIGH;
if (priority_comp == kPriorityMedium)
return COOKIE_PRIORITY_MEDIUM;
if (priority_comp == kPriorityLow)
return COOKIE_PRIORITY_LOW;
return COOKIE_PRIORITY_DEFAULT;
}
std::string CookieSameSiteToString(CookieSameSite same_site) {
switch (same_site) {
case CookieSameSite::LAX_MODE:
return kSameSiteLax;
case CookieSameSite::STRICT_MODE:
return kSameSiteStrict;
case CookieSameSite::NO_RESTRICTION:
return kSameSiteNone;
case CookieSameSite::UNSPECIFIED:
return kSameSiteUnspecified;
}
}
CookieSameSite StringToCookieSameSite(const std::string& same_site,
CookieSameSiteString* samesite_string) {
// Put a value on the stack so that we can assign to |*samesite_string|
// instead of having to null-check it all the time.
CookieSameSiteString ignored = CookieSameSiteString::kUnspecified;
if (!samesite_string)
samesite_string = &ignored;
*samesite_string = CookieSameSiteString::kUnrecognized;
CookieSameSite samesite = CookieSameSite::UNSPECIFIED;
if (base::EqualsCaseInsensitiveASCII(same_site, kSameSiteNone)) {
samesite = CookieSameSite::NO_RESTRICTION;
*samesite_string = CookieSameSiteString::kNone;
} else if (base::EqualsCaseInsensitiveASCII(same_site, kSameSiteLax)) {
samesite = CookieSameSite::LAX_MODE;
*samesite_string = CookieSameSiteString::kLax;
} else if (base::EqualsCaseInsensitiveASCII(same_site, kSameSiteStrict)) {
samesite = CookieSameSite::STRICT_MODE;
*samesite_string = CookieSameSiteString::kStrict;
} else if (base::EqualsCaseInsensitiveASCII(same_site, kSameSiteExtended)) {
// Extended isn't supported anymore -- we just parse it for UMA stats.
*samesite_string = CookieSameSiteString::kExtended;
} else if (same_site == "") {
*samesite_string = CookieSameSiteString::kEmptyString;
}
return samesite;
}
void RecordCookieSameSiteAttributeValueHistogram(CookieSameSiteString value,
bool is_cookie_same_party) {
UMA_HISTOGRAM_ENUMERATION("Cookie.SameSiteAttributeValue", value);
if (is_cookie_same_party) {
base::UmaHistogramEnumeration(
"Cookie.SamePartyCookieSameSiteAttributeValue", value);
}
}
CookiePort ReducePortRangeForCookieHistogram(const int port) {
switch (port) {
case 80:
return CookiePort::k80;
case 81:
return CookiePort::k81;
case 82:
return CookiePort::k82;
case 83:
return CookiePort::k83;
case 84:
return CookiePort::k84;
case 85:
return CookiePort::k85;
case 443:
return CookiePort::k443;
case 444:
return CookiePort::k444;
case 445:
return CookiePort::k445;
case 446:
return CookiePort::k446;
case 447:
return CookiePort::k447;
case 448:
return CookiePort::k448;
case 3000:
return CookiePort::k3000;
case 3001:
return CookiePort::k3001;
case 3002:
return CookiePort::k3002;
case 3003:
return CookiePort::k3003;
case 3004:
return CookiePort::k3004;
case 3005:
return CookiePort::k3005;
case 4200:
return CookiePort::k4200;
case 4201:
return CookiePort::k4201;
case 4202:
return CookiePort::k4202;
case 4203:
return CookiePort::k4203;
case 4204:
return CookiePort::k4204;
case 4205:
return CookiePort::k4205;
case 5000:
return CookiePort::k5000;
case 5001:
return CookiePort::k5001;
case 5002:
return CookiePort::k5002;
case 5003:
return CookiePort::k5003;
case 5004:
return CookiePort::k5004;
case 5005:
return CookiePort::k5005;
case 7000:
return CookiePort::k7000;
case 7001:
return CookiePort::k7001;
case 7002:
return CookiePort::k7002;
case 7003:
return CookiePort::k7003;
case 7004:
return CookiePort::k7004;
case 7005:
return CookiePort::k7005;
case 8000:
return CookiePort::k8000;
case 8001:
return CookiePort::k8001;
case 8002:
return CookiePort::k8002;
case 8003:
return CookiePort::k8003;
case 8004:
return CookiePort::k8004;
case 8005:
return CookiePort::k8005;
case 8080:
return CookiePort::k8080;
case 8081:
return CookiePort::k8081;
case 8082:
return CookiePort::k8082;
case 8083:
return CookiePort::k8083;
case 8084:
return CookiePort::k8084;
case 8085:
return CookiePort::k8085;
case 8090:
return CookiePort::k8090;
case 8091:
return CookiePort::k8091;
case 8092:
return CookiePort::k8092;
case 8093:
return CookiePort::k8093;
case 8094:
return CookiePort::k8094;
case 8095:
return CookiePort::k8095;
case 8100:
return CookiePort::k8100;
case 8101:
return CookiePort::k8101;
case 8102:
return CookiePort::k8102;
case 8103:
return CookiePort::k8103;
case 8104:
return CookiePort::k8104;
case 8105:
return CookiePort::k8105;
case 8200:
return CookiePort::k8200;
case 8201:
return CookiePort::k8201;
case 8202:
return CookiePort::k8202;
case 8203:
return CookiePort::k8203;
case 8204:
return CookiePort::k8204;
case 8205:
return CookiePort::k8205;
case 8443:
return CookiePort::k8443;
case 8444:
return CookiePort::k8444;
case 8445:
return CookiePort::k8445;
case 8446:
return CookiePort::k8446;
case 8447:
return CookiePort::k8447;
case 8448:
return CookiePort::k8448;
case 8888:
return CookiePort::k8888;
case 8889:
return CookiePort::k8889;
case 8890:
return CookiePort::k8890;
case 8891:
return CookiePort::k8891;
case 8892:
return CookiePort::k8892;
case 8893:
return CookiePort::k8893;
case 9000:
return CookiePort::k9000;
case 9001:
return CookiePort::k9001;
case 9002:
return CookiePort::k9002;
case 9003:
return CookiePort::k9003;
case 9004:
return CookiePort::k9004;
case 9005:
return CookiePort::k9005;
case 9090:
return CookiePort::k9090;
case 9091:
return CookiePort::k9091;
case 9092:
return CookiePort::k9092;
case 9093:
return CookiePort::k9093;
case 9094:
return CookiePort::k9094;
case 9095:
return CookiePort::k9095;
default:
return CookiePort::kOther;
}
}
CookieSourceSchemeName GetSchemeNameEnum(const GURL& url) {
// The most likely schemes are first, to improve performance.
if (url.SchemeIs(url::kHttpsScheme)) {
return CookieSourceSchemeName::kHttpsScheme;
} else if (url.SchemeIs(url::kHttpScheme)) {
return CookieSourceSchemeName::kHttpScheme;
} else if (url.SchemeIs(url::kWssScheme)) {
return CookieSourceSchemeName::kWssScheme;
} else if (url.SchemeIs(url::kWsScheme)) {
return CookieSourceSchemeName::kWsScheme;
} else if (url.SchemeIs("chrome-extension")) {
return CookieSourceSchemeName::kChromeExtensionScheme;
} else if (url.SchemeIs(url::kFileScheme)) {
return CookieSourceSchemeName::kFileScheme;
}
// These all aren't marked as cookieable and so are much less likely to
// occur.
else if (url.SchemeIs(url::kAboutBlankURL)) {
return CookieSourceSchemeName::kAboutBlankURL;
} else if (url.SchemeIs(url::kAboutSrcdocURL)) {
return CookieSourceSchemeName::kAboutSrcdocURL;
} else if (url.SchemeIs(url::kAboutBlankPath)) {
return CookieSourceSchemeName::kAboutBlankPath;
} else if (url.SchemeIs(url::kAboutSrcdocPath)) {
return CookieSourceSchemeName::kAboutSrcdocPath;
} else if (url.SchemeIs(url::kAboutScheme)) {
return CookieSourceSchemeName::kAboutScheme;
} else if (url.SchemeIs(url::kBlobScheme)) {
return CookieSourceSchemeName::kBlobScheme;
} else if (url.SchemeIs(url::kContentScheme)) {
return CookieSourceSchemeName::kContentScheme;
} else if (url.SchemeIs(url::kContentIDScheme)) {
return CookieSourceSchemeName::kContentIDScheme;
} else if (url.SchemeIs(url::kDataScheme)) {
return CookieSourceSchemeName::kDataScheme;
} else if (url.SchemeIs(url::kFileSystemScheme)) {
return CookieSourceSchemeName::kFileSystemScheme;
} else if (url.SchemeIs(url::kFtpScheme)) {
return CookieSourceSchemeName::kFtpScheme;
} else if (url.SchemeIs(url::kJavaScriptScheme)) {
return CookieSourceSchemeName::kJavaScriptScheme;
} else if (url.SchemeIs(url::kMailToScheme)) {
return CookieSourceSchemeName::kMailToScheme;
} else if (url.SchemeIs(url::kQuicTransportScheme)) {
return CookieSourceSchemeName::kQuicTransportScheme;
} else if (url.SchemeIs(url::kTelScheme)) {
return CookieSourceSchemeName::kTelScheme;
} else if (url.SchemeIs(url::kUrnScheme)) {
return CookieSourceSchemeName::kUrnScheme;
}
return CookieSourceSchemeName::kOther;
}
} // namespace net