| Index: content/browser/browsing_data/clear_site_data_throttle.cc
|
| diff --git a/content/browser/browsing_data/clear_site_data_throttle.cc b/content/browser/browsing_data/clear_site_data_throttle.cc
|
| index 651b9a11a676c9fbaa1d4cdda523d5af3cefaa7b..7240f3dd460b8f9eedd9d41eea809a15ac7b8da3 100644
|
| --- a/content/browser/browsing_data/clear_site_data_throttle.cc
|
| +++ b/content/browser/browsing_data/clear_site_data_throttle.cc
|
| @@ -37,8 +37,6 @@ const char kNameForLogging[] = "ClearSiteDataThrottle";
|
|
|
| const char kClearSiteDataHeader[] = "Clear-Site-Data";
|
|
|
| -const char kTypesKey[] = "types";
|
| -
|
| // Datatypes.
|
| const char kDatatypeCookies[] = "cookies";
|
| const char kDatatypeStorage[] = "storage";
|
| @@ -446,24 +444,22 @@ bool ClearSiteDataThrottle::ParseHeader(const std::string& header,
|
| return false;
|
| }
|
|
|
| - std::unique_ptr<base::Value> parsed_header = base::JSONReader::Read(header);
|
| + // Wrap |header| in `[` and `]`, then process it as a JSON array:
|
| + //
|
| + // TODO(mkwst): Drop the JSONReader bits in favor of a simpler parser.
|
| + std::string wrapped = "[" + header + "]";
|
| + std::unique_ptr<base::Value> parsed_header = base::JSONReader::Read(wrapped);
|
|
|
| if (!parsed_header) {
|
| - delegate->AddMessage(current_url, "Expected valid JSON.",
|
| - CONSOLE_MESSAGE_LEVEL_ERROR);
|
| - return false;
|
| - }
|
| -
|
| - const base::DictionaryValue* dictionary = nullptr;
|
| - const base::ListValue* types = nullptr;
|
| - if (!parsed_header->GetAsDictionary(&dictionary) ||
|
| - !dictionary->GetListWithoutPathExpansion(kTypesKey, &types)) {
|
| delegate->AddMessage(current_url,
|
| - "Expected a JSON dictionary with a 'types' field.",
|
| + "The header's value does not parse as valid JSON.",
|
| CONSOLE_MESSAGE_LEVEL_ERROR);
|
| return false;
|
| }
|
|
|
| + // Expecting a header in the format `"value1", "value2", "value3"`:
|
| + const base::ListValue* types = nullptr;
|
| + DCHECK(parsed_header->GetAsList(&types));
|
| DCHECK(types);
|
|
|
| *clear_cookies = false;
|
| @@ -473,16 +469,33 @@ bool ClearSiteDataThrottle::ParseHeader(const std::string& header,
|
| std::string type_names;
|
| for (const base::Value& value : *types) {
|
| std::string type;
|
| - value.GetAsString(&type);
|
| -
|
| - bool* data_type = nullptr;
|
| -
|
| - if (type == kDatatypeCookies) {
|
| - data_type = clear_cookies;
|
| - } else if (type == kDatatypeStorage) {
|
| - data_type = clear_storage;
|
| - } else if (type == kDatatypeCache) {
|
| - data_type = clear_cache;
|
| + if (value.is_string() && value.GetAsString(&type)) {
|
| + bool* data_type = nullptr;
|
| +
|
| + if (type == kDatatypeCookies) {
|
| + data_type = clear_cookies;
|
| + } else if (type == kDatatypeStorage) {
|
| + data_type = clear_storage;
|
| + } else if (type == kDatatypeCache) {
|
| + data_type = clear_cache;
|
| + } else {
|
| + delegate->AddMessage(
|
| + current_url,
|
| + base::StringPrintf("Unrecognized type: \"%s\".", type.c_str()),
|
| + CONSOLE_MESSAGE_LEVEL_ERROR);
|
| + continue;
|
| + }
|
| +
|
| + DCHECK(data_type);
|
| +
|
| + // Each data type should only be processed once.
|
| + if (*data_type)
|
| + continue;
|
| +
|
| + *data_type = true;
|
| + if (!type_names.empty())
|
| + type_names += kConsoleMessageDatatypeSeparator;
|
| + type_names += type;
|
| } else {
|
| std::string serialized_type;
|
| JSONStringValueSerializer serializer(&serialized_type);
|
| @@ -491,24 +504,11 @@ bool ClearSiteDataThrottle::ParseHeader(const std::string& header,
|
| current_url,
|
| base::StringPrintf("Unrecognized type: %s.", serialized_type.c_str()),
|
| CONSOLE_MESSAGE_LEVEL_ERROR);
|
| - continue;
|
| }
|
| -
|
| - DCHECK(data_type);
|
| -
|
| - // Each data type should only be processed once.
|
| - if (*data_type)
|
| - continue;
|
| -
|
| - *data_type = true;
|
| - if (!type_names.empty())
|
| - type_names += kConsoleMessageDatatypeSeparator;
|
| - type_names += type;
|
| }
|
|
|
| if (!*clear_cookies && !*clear_storage && !*clear_cache) {
|
| - delegate->AddMessage(current_url,
|
| - "No recognized types specified in the 'types' field.",
|
| + delegate->AddMessage(current_url, "No recognized types specified.",
|
| CONSOLE_MESSAGE_LEVEL_ERROR);
|
| return false;
|
| }
|
|
|