Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: net/cookies/cookie_constants.cc

Issue 1773133002: SameSite: Implement 'Strict'/'Lax' attribute parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios? Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cookies/cookie_constants.h" 5 #include "net/cookies/cookie_constants.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 namespace { 12 namespace {
13 const char kPriorityLow[] = "low"; 13 const char kPriorityLow[] = "low";
14 const char kPriorityMedium[] = "medium"; 14 const char kPriorityMedium[] = "medium";
15 const char kPriorityHigh[] = "high"; 15 const char kPriorityHigh[] = "high";
16
17 const char kSameSiteLax[] = "lax";
18 const char kSameSiteStrict[] = "strict";
16 } // namespace 19 } // namespace
mmenke 2016/03/11 18:08:30 nit: Add a blank line after the start / before th
Mike West 2016/03/14 10:18:53 Done.
17 20
18 NET_EXPORT const std::string CookiePriorityToString(CookiePriority priority) { 21 NET_EXPORT const std::string CookiePriorityToString(CookiePriority priority) {
19 switch(priority) { 22 switch(priority) {
20 case COOKIE_PRIORITY_HIGH: 23 case COOKIE_PRIORITY_HIGH:
21 return kPriorityHigh; 24 return kPriorityHigh;
22 case COOKIE_PRIORITY_MEDIUM: 25 case COOKIE_PRIORITY_MEDIUM:
23 return kPriorityMedium; 26 return kPriorityMedium;
24 case COOKIE_PRIORITY_LOW: 27 case COOKIE_PRIORITY_LOW:
25 return kPriorityLow; 28 return kPriorityLow;
26 default: 29 default:
27 NOTREACHED(); 30 NOTREACHED();
28 } 31 }
29 return std::string(); 32 return std::string();
30 } 33 }
31 34
32 NET_EXPORT CookiePriority StringToCookiePriority(const std::string& priority) { 35 NET_EXPORT CookiePriority StringToCookiePriority(const std::string& priority) {
33 std::string priority_comp = base::ToLowerASCII(priority); 36 std::string priority_comp = base::ToLowerASCII(priority);
34 37
35 if (priority_comp == kPriorityHigh) 38 if (priority_comp == kPriorityHigh)
36 return COOKIE_PRIORITY_HIGH; 39 return COOKIE_PRIORITY_HIGH;
37 if (priority_comp == kPriorityMedium) 40 if (priority_comp == kPriorityMedium)
38 return COOKIE_PRIORITY_MEDIUM; 41 return COOKIE_PRIORITY_MEDIUM;
39 if (priority_comp == kPriorityLow) 42 if (priority_comp == kPriorityLow)
40 return COOKIE_PRIORITY_LOW; 43 return COOKIE_PRIORITY_LOW;
41 44
42 return COOKIE_PRIORITY_DEFAULT; 45 return COOKIE_PRIORITY_DEFAULT;
43 } 46 }
44 47
48 NET_EXPORT const std::string CookieSameSiteToString(CookieSameSite samesite) {
mmenke 2016/03/11 18:08:30 This method isn't used anywhere (Neither is Cookie
mmenke 2016/03/11 18:08:30 Remove all NET_EXPORTs from this file... They sho
Mike West 2016/03/14 10:18:53 Hrm. You're right. I thought we needed both for se
49 switch (samesite) {
50 case COOKIE_SAME_SITE_NONE:
51 return std::string();
52 case COOKIE_SAME_SITE_LAX:
53 return kSameSiteLax;
54 case COOKIE_SAME_SITE_STRICT:
55 return kSameSiteStrict;
56 default:
57 NOTREACHED();
58 }
59 return std::string();
60 }
61
62 NET_EXPORT CookieSameSite StringToCookieSameSite(const std::string& samesite) {
63 std::string comp = base::ToLowerASCII(samesite);
mmenke 2016/03/11 18:08:30 comp seems to violate the Google style guide. I'd
Mike West 2016/03/14 10:18:53 Sure.
64
65 if (comp == kSameSiteLax)
66 return COOKIE_SAME_SITE_LAX;
67 if (comp == kSameSiteStrict)
68 return COOKIE_SAME_SITE_STRICT;
69 return COOKIE_SAME_SITE_DEFAULT;
70 }
71
45 } // namespace net 72 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698