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

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

Issue 2933083002: Revert of Align `clear-site-data` syntax with the spec. (Closed)
Patch Set: 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 7240f3dd460b8f9eedd9d41eea809a15ac7b8da3..651b9a11a676c9fbaa1d4cdda523d5af3cefaa7b 100644
--- a/content/browser/browsing_data/clear_site_data_throttle.cc
+++ b/content/browser/browsing_data/clear_site_data_throttle.cc
@@ -37,6 +37,8 @@
const char kClearSiteDataHeader[] = "Clear-Site-Data";
+const char kTypesKey[] = "types";
+
// Datatypes.
const char kDatatypeCookies[] = "cookies";
const char kDatatypeStorage[] = "storage";
@@ -444,22 +446,24 @@
return false;
}
- // 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);
+ std::unique_ptr<base::Value> parsed_header = base::JSONReader::Read(header);
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,
- "The header's value does not parse as valid JSON.",
+ "Expected a JSON dictionary with a 'types' field.",
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;
@@ -469,33 +473,16 @@
std::string type_names;
for (const base::Value& value : *types) {
std::string type;
- 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;
+ 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 {
std::string serialized_type;
JSONStringValueSerializer serializer(&serialized_type);
@@ -504,11 +491,24 @@
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.",
+ delegate->AddMessage(current_url,
+ "No recognized types specified in the 'types' field.",
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