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

Unified Diff: extensions/renderer/content_setting.cc

Issue 2903803004: [Extensions Bindings] Fix content settings validation (Closed)
Patch Set: . 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
« no previous file with comments | « chrome/test/data/extensions/api_test/native_bindings/extension/background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/content_setting.cc
diff --git a/extensions/renderer/content_setting.cc b/extensions/renderer/content_setting.cc
index ffa085822e094c5f4aaf56c769a8194df6b55966..b21f729a7f6641ce892e97d4bc7a7c116a4cef49 100644
--- a/extensions/renderer/content_setting.cc
+++ b/extensions/renderer/content_setting.cc
@@ -109,20 +109,6 @@ void ContentSetting::Get(gin::Arguments* arguments) {
}
void ContentSetting::Set(gin::Arguments* arguments) {
- v8::Isolate* isolate = arguments->isolate();
- v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Context> context = arguments->GetHolderCreationContext();
-
- v8::Local<v8::Value> value = arguments->PeekNext();
- // The set schema included in the Schema object is generic, since it varies
- // per-setting. However, this is only ever for a single setting, so we can
- // enforce the types more thoroughly.
- std::string error;
- if (!value.IsEmpty() && !argument_spec_.ParseArgument(
- context, value, *type_refs_, nullptr, &error)) {
- arguments->ThrowTypeError("Invalid invocation");
- return;
- }
HandleFunction("set", arguments);
}
@@ -149,7 +135,7 @@ void ContentSetting::HandleFunction(const std::string& method_name,
if (!type_refs_->GetTypeMethodSignature(full_name)->ParseArgumentsToJSON(
context, argument_list, *type_refs_, &converted_arguments, &callback,
&error)) {
- arguments->ThrowTypeError("Invalid invocation");
+ arguments->ThrowTypeError("Invalid invocation: " + error);
return;
}
@@ -178,6 +164,21 @@ void ContentSetting::HandleFunction(const std::string& method_name,
return;
}
+ if (method_name == "set") {
+ v8::Local<v8::Value> value = argument_list[0];
+ // The set schema included in the Schema object is generic, since it varies
+ // per-setting. However, this is only ever for a single setting, so we can
+ // enforce the types more thoroughly.
+ // Note: we do this *after* checking if the setting is deprecated, since
+ // this validation will fail for deprecated settings.
+ std::string error;
+ if (!value.IsEmpty() && !argument_spec_.ParseArgument(
+ context, value, *type_refs_, nullptr, &error)) {
+ arguments->ThrowTypeError("Invalid invocation: " + error);
+ return;
+ }
+ }
+
converted_arguments->Insert(0u, base::MakeUnique<base::Value>(pref_name_));
request_handler_->StartRequest(
context, "contentSettings." + method_name, std::move(converted_arguments),
« no previous file with comments | « chrome/test/data/extensions/api_test/native_bindings/extension/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698