chore: modernize base::Value usage in WebRequest (#34667)

This commit is contained in:
Jeremy Rose 2022-06-22 01:11:27 -07:00 committed by GitHub
parent 140c8d0d0a
commit ad7aab8338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,13 +115,12 @@ bool MatchesFilterCondition(extensions::WebRequestInfo* info,
// to pass the original keys.
v8::Local<v8::Value> HttpResponseHeadersToV8(
net::HttpResponseHeaders* headers) {
base::DictionaryValue response_headers;
base::Value::Dict response_headers;
if (headers) {
size_t iter = 0;
std::string key;
std::string value;
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
base::Value* values = response_headers.FindListKey(key);
// Note that Web servers not developed with nodejs allow non-utf8
// characters in content-disposition's filename field. Use Chromium's
// HttpContentDisposition class to decode the correct encoding instead of
@ -138,12 +137,14 @@ v8::Local<v8::Value> HttpResponseHeadersToV8(
std::string filename = "\"" + header.filename() + "\"";
value = decodedFilename + "; filename=" + filename;
}
base::Value::List* values = response_headers.FindList(key);
if (!values)
values = response_headers.SetKey(key, base::ListValue());
values->Append(value);
values = &response_headers.Set(key, base::Value::List())->GetList();
values->Append(base::Value(value));
}
}
return gin::ConvertToV8(v8::Isolate::GetCurrent(), response_headers);
return gin::ConvertToV8(v8::Isolate::GetCurrent(),
base::Value(std::move(response_headers)));
}
// Overloaded by multiple types to fill the |details| object.