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

Unified Diff: content/browser/browsing_data/clear_site_data_throttle.cc

Issue 2929593002: Align `clear-site-data` syntax with the spec. (Closed)
Patch Set: Feedback. Created 3 years, 6 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 | content/browser/browsing_data/clear_site_data_throttle_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | content/browser/browsing_data/clear_site_data_throttle_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698