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

Unified Diff: chrome/browser/extensions/policy_handlers.cc

Issue 2495353003: chrome.webRequest support for ExtensionSettings (Closed)
Patch Set: Policy template translation doesn't like '&', switching to 'and'. Small fix to browser test. Created 3 years, 7 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
Index: chrome/browser/extensions/policy_handlers.cc
diff --git a/chrome/browser/extensions/policy_handlers.cc b/chrome/browser/extensions/policy_handlers.cc
index 0b0b2bf14865b4250a3f3b9a6f8f1abea8a76d66..da752a070ec8a75137136e562da924a14b13c954 100644
--- a/chrome/browser/extensions/policy_handlers.cc
+++ b/chrome/browser/extensions/policy_handlers.cc
@@ -286,6 +286,8 @@ bool ExtensionSettingsPolicyHandler::CheckPolicySettings(
const base::DictionaryValue* dict_value = NULL;
DCHECK(policy_value->IsType(base::Value::Type::DICTIONARY));
policy_value->GetAsDictionary(&dict_value);
+ const int extension_scheme_mask =
+ URLPattern::GetValidSchemeMaskForExtensions();
for (base::DictionaryValue::Iterator it(*dict_value); !it.IsAtEnd();
it.Advance()) {
@@ -321,6 +323,46 @@ bool ExtensionSettingsPolicyHandler::CheckPolicySettings(
}
}
}
+ const base::ListValue* unparsed_urls;
+ // Host keys that don't support user defined paths.
+ const std::string host_keys[] = {schema_constants::kRuntimeBlockedHosts,
+ schema_constants::kRuntimeAllowedHosts};
+ for (const auto& key : host_keys) {
+ if (sub_dict->GetList(key, &unparsed_urls)) {
+ for (size_t i = 0; i < unparsed_urls->GetSize(); ++i) {
+ std::string unparsed_url;
+ unparsed_urls->GetString(i, &unparsed_url);
+ URLPattern pattern = URLPattern(extension_scheme_mask);
+ URLPattern::ParseResult parse_result = pattern.Parse(
+ unparsed_url, URLPattern::ALLOW_WILDCARD_FOR_EFFECTIVE_TLD);
+ // These keys don't support paths due to how we track the initiator
+ // of a webRequest and cookie security policy. We expect a valid
+ // pattern to return a PARSE_ERROR_EMPTY_PATH.
+ if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) {
+ // Add a wildcard path to the URL as it should match any path.
+ parse_result =
+ pattern.Parse(unparsed_url + "/*",
+ URLPattern::ALLOW_WILDCARD_FOR_EFFECTIVE_TLD);
+ } else if (parse_result == URLPattern::PARSE_SUCCESS) {
+ // The user supplied a path, notify them that this is not supported.
+ if (unparsed_url != "<all_urls>") {
+ errors->AddError(
+ policy_name(), it.key(),
+ "Your URL pattern '" + unparsed_url + "' for attribute " +
+ key + " contains a path. Paths are not supported, " +
+ "please remove it and try again.");
+ return false;
+ }
+ }
+ // Any other issue with parsing the URL.
+ if (parse_result != URLPattern::PARSE_SUCCESS) {
+ errors->AddError(policy_name(), it.key(),
+ "Invalid URL pattern '" + unparsed_url +
+ "' for attribute " + key);
+ }
+ }
+ }
+ }
}
return true;

Powered by Google App Engine
This is Rietveld 408576698