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

Unified Diff: chrome/browser/extensions/api/web_request/web_request_api_helpers.cc

Issue 354183002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert string_util.h change 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/net/chrome_network_delegate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
diff --git a/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc b/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
index ed89368b754311f19991b94ba0770e220351267d..5961c653549ab1318cc8c1e93acafea5658f1f1b 100644
--- a/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
+++ b/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
@@ -34,14 +34,13 @@
using base::Time;
using content::ResourceType;
using extensions::ExtensionWarning;
+using net::cookie_util::ParsedRequestCookie;
+using net::cookie_util::ParsedRequestCookies;
namespace extension_web_request_api_helpers {
namespace {
-// A ParsedRequestCookie consists of the key and value of the cookie.
-typedef std::pair<base::StringPiece, base::StringPiece> ParsedRequestCookie;
-typedef std::vector<ParsedRequestCookie> ParsedRequestCookies;
typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
static const char* kResourceTypeStrings[] = {
@@ -483,67 +482,6 @@ void MergeOnBeforeRequestResponses(
MergeRedirectUrlOfResponses(deltas, new_url, conflicting_extensions, net_log);
}
-// Assumes that |header_value| is the cookie header value of a HTTP Request
-// following the cookie-string schema of RFC 6265, section 4.2.1, and returns
-// cookie name/value pairs. If cookie values are presented in double quotes,
-// these will appear in |parsed| as well. We can assume that the cookie header
-// is written by Chromium and therefore, well-formed.
-static void ParseRequestCookieLine(
- const std::string& header_value,
- ParsedRequestCookies* parsed_cookies) {
- std::string::const_iterator i = header_value.begin();
- while (i != header_value.end()) {
- // Here we are at the beginning of a cookie.
-
- // Eat whitespace.
- while (i != header_value.end() && *i == ' ') ++i;
- if (i == header_value.end()) return;
-
- // Find cookie name.
- std::string::const_iterator cookie_name_beginning = i;
- while (i != header_value.end() && *i != '=') ++i;
- base::StringPiece cookie_name(cookie_name_beginning, i);
-
- // Find cookie value.
- base::StringPiece cookie_value;
- if (i != header_value.end()) { // Cookies may have no value.
- ++i; // Skip '='.
- std::string::const_iterator cookie_value_beginning = i;
- if (*i == '"') {
- ++i; // Skip '"'.
- while (i != header_value.end() && *i != '"') ++i;
- if (i == header_value.end()) return;
- ++i; // Skip '"'.
- cookie_value = base::StringPiece(cookie_value_beginning, i);
- // i points to character after '"', potentially a ';'
- } else {
- while (i != header_value.end() && *i != ';') ++i;
- cookie_value = base::StringPiece(cookie_value_beginning, i);
- // i points to ';' or end of string.
- }
- }
- parsed_cookies->push_back(make_pair(cookie_name, cookie_value));
- // Eat ';'
- if (i != header_value.end()) ++i;
- }
-}
-
-// Writes all cookies of |parsed_cookies| into a HTTP Request header value
-// that belongs to the "Cookie" header.
-static std::string SerializeRequestCookieLine(
- const ParsedRequestCookies& parsed_cookies) {
- std::string buffer;
- for (ParsedRequestCookies::const_iterator i = parsed_cookies.begin();
- i != parsed_cookies.end(); ++i) {
- if (!buffer.empty())
- buffer += "; ";
- buffer += i->first.as_string();
- if (!i->second.empty())
- buffer += "=" + i->second.as_string();
- }
- return buffer;
-}
-
static bool DoesRequestCookieMatchFilter(
const ParsedRequestCookie& cookie,
RequestCookie* filter) {
@@ -681,7 +619,7 @@ void MergeCookiesInOnBeforeSendHeadersResponses(
std::string cookie_header;
request_headers->GetHeader(net::HttpRequestHeaders::kCookie, &cookie_header);
ParsedRequestCookies cookies;
- ParseRequestCookieLine(cookie_header, &cookies);
+ net::cookie_util::ParseRequestCookieLine(cookie_header, &cookies);
// Modify cookies.
bool modified = false;
@@ -691,7 +629,8 @@ void MergeCookiesInOnBeforeSendHeadersResponses(
// Reassemble and store new cookie line.
if (modified) {
- std::string new_cookie_header = SerializeRequestCookieLine(cookies);
+ std::string new_cookie_header =
+ net::cookie_util::SerializeRequestCookieLine(cookies);
request_headers->SetHeader(net::HttpRequestHeaders::kCookie,
new_cookie_header);
}
« no previous file with comments | « no previous file | chrome/browser/net/chrome_network_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698