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

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

Issue 354183002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments 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 | Annotate | Revision Log
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 if (i != header_value.end()) { // Cookies may have no value.
231 ++i; // Skip '='.
232 std::string::const_iterator cookie_value_beginning = i;
233 if (*i == '"') {
234 ++i; // Skip '"'.
235 while (i != header_value.end() && *i != '"') ++i;
236 if (i == header_value.end()) return;
237 ++i; // Skip '"'.
238 cookie_value = base::StringPiece(cookie_value_beginning, i);
239 // i points to character after '"', potentially a ';'
240 } else {
241 while (i != header_value.end() && *i != ';') ++i;
242 cookie_value = base::StringPiece(cookie_value_beginning, i);
243 // i points to ';' or end of string.
244 }
245 }
246 parsed_cookies->push_back(std::make_pair(cookie_name, cookie_value));
247 // Eat ';'
erikwright (departed) 2014/07/10 14:26:24 add '.'.
Marc Treib 2014/07/10 15:40:39 Done.
248 if (i != header_value.end()) ++i;
249 }
250 }
251
252 std::string SerializeRequestCookieLine(
253 const ParsedRequestCookies& parsed_cookies) {
254 std::string buffer;
255 for (ParsedRequestCookies::const_iterator i = parsed_cookies.begin();
256 i != parsed_cookies.end(); ++i) {
257 if (!buffer.empty())
258 buffer += "; ";
259 buffer += i->first.as_string() + "=" + i->second.as_string();
erikwright (departed) 2014/07/10 14:26:24 How about: buffer.append(i->first.begin(), i->fir
Marc Treib 2014/07/10 15:40:39 Done.
260 }
261 return buffer;
262 }
263
213 } // namespace cookie_utils 264 } // namespace cookie_utils
214 } // namespace net 265 } // namespace net
215 266
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698