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

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

Issue 388823002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: rebase Created 6 years, 5 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
« no previous file with comments | « net/cookies/cookie_util.h ('k') | net/cookies/cookie_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_util.h" 5 #include "net/cookies/cookie_util.h"
6 6
7 #include <cstdio> 7 #include <cstdio>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 GURL CookieOriginToURL(const std::string& domain, bool is_https) { 204 GURL CookieOriginToURL(const std::string& domain, bool is_https) {
205 if (domain.empty()) 205 if (domain.empty())
206 return GURL(); 206 return GURL();
207 207
208 const std::string scheme = is_https ? "https" : "http"; 208 const std::string scheme = is_https ? "https" : "http";
209 const std::string host = domain[0] == '.' ? domain.substr(1) : domain; 209 const std::string host = domain[0] == '.' ? domain.substr(1) : domain;
210 return GURL(scheme + "://" + host); 210 return GURL(scheme + "://" + host);
211 } 211 }
212 212
213 void ParseRequestCookieLine(const std::string& header_value,
214 ParsedRequestCookies* parsed_cookies) {
215 std::string::const_iterator i = header_value.begin();
216 while (i != header_value.end()) {
217 // Here we are at the beginning of a cookie.
218
219 // Eat whitespace.
220 while (i != header_value.end() && *i == ' ') ++i;
221 if (i == header_value.end()) return;
222
223 // Find cookie name.
224 std::string::const_iterator cookie_name_beginning = i;
225 while (i != header_value.end() && *i != '=') ++i;
226 base::StringPiece cookie_name(cookie_name_beginning, i);
227
228 // Find cookie value.
229 base::StringPiece cookie_value;
230 // Cookies may have no value, in this case '=' may or may not be there.
231 if (i != header_value.end() && i + 1 != header_value.end()) {
232 ++i; // Skip '='.
233 std::string::const_iterator cookie_value_beginning = i;
234 if (*i == '"') {
235 ++i; // Skip '"'.
236 while (i != header_value.end() && *i != '"') ++i;
237 if (i == header_value.end()) return;
238 ++i; // Skip '"'.
239 cookie_value = base::StringPiece(cookie_value_beginning, i);
240 // i points to character after '"', potentially a ';'.
241 } else {
242 while (i != header_value.end() && *i != ';') ++i;
243 cookie_value = base::StringPiece(cookie_value_beginning, i);
244 // i points to ';' or end of string.
245 }
246 }
247 parsed_cookies->push_back(std::make_pair(cookie_name, cookie_value));
248 // Eat ';'.
249 if (i != header_value.end()) ++i;
250 }
251 }
252
253 std::string SerializeRequestCookieLine(
254 const ParsedRequestCookies& parsed_cookies) {
255 std::string buffer;
256 for (ParsedRequestCookies::const_iterator i = parsed_cookies.begin();
257 i != parsed_cookies.end(); ++i) {
258 if (!buffer.empty())
259 buffer.append("; ");
260 buffer.append(i->first.begin(), i->first.end());
261 buffer.push_back('=');
262 buffer.append(i->second.begin(), i->second.end());
263 }
264 return buffer;
265 }
266
213 } // namespace cookie_utils 267 } // namespace cookie_utils
214 } // namespace net 268 } // namespace net
215 269
OLDNEW
« no previous file with comments | « net/cookies/cookie_util.h ('k') | net/cookies/cookie_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698