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

Side by Side Diff: extensions/renderer/api_binding.cc

Issue 2583273002: [Extensions Bindings] Allow for argument validation without conversion (Closed)
Patch Set: format Created 3 years, 12 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/api_binding.h" 5 #include "extensions/renderer/api_binding.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 const APISignature* signature, 177 const APISignature* signature,
178 gin::Arguments* arguments) { 178 gin::Arguments* arguments) {
179 std::string error; 179 std::string error;
180 v8::Isolate* isolate = arguments->isolate(); 180 v8::Isolate* isolate = arguments->isolate();
181 v8::HandleScope handle_scope(isolate); 181 v8::HandleScope handle_scope(isolate);
182 182
183 // Since this is called synchronously from the JS entry point, 183 // Since this is called synchronously from the JS entry point,
184 // GetCurrentContext() should always be correct. 184 // GetCurrentContext() should always be correct.
185 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 185 v8::Local<v8::Context> context = isolate->GetCurrentContext();
186 186
187 // Check for a custom hook to handle the method. 187 APIBindingHooks::RequestResult hooks_result =
188 if (binding_hooks_ && 188 APIBindingHooks::RequestResult::NOT_HANDLED;
189 binding_hooks_->HandleRequest(api_name_, name, context, 189 if (binding_hooks_) {
190 signature, arguments)) { 190 hooks_result = binding_hooks_->HandleRequest(
191 return; // Handled by a custom hook. 191 api_name_, name, context, signature, arguments, *type_refs_);
192 } 192 }
193 193
194 std::unique_ptr<base::ListValue> parsed_arguments; 194 switch (hooks_result) {
195 case APIBindingHooks::RequestResult::INVALID_INVOCATION:
196 arguments->ThrowTypeError("Invalid invocation");
197 return;
198 case APIBindingHooks::RequestResult::HANDLED:
199 return; // Our work here is done.
200 case APIBindingHooks::RequestResult::NOT_HANDLED:
201 break; // Handle in the default manner.
202 }
203
204 std::unique_ptr<base::ListValue> converted_arguments;
195 v8::Local<v8::Function> callback; 205 v8::Local<v8::Function> callback;
206 bool conversion_success = false;
196 { 207 {
197 v8::TryCatch try_catch(isolate); 208 v8::TryCatch try_catch(isolate);
198 parsed_arguments = 209 conversion_success = signature->ParseArgumentsToJSON(
199 signature->ParseArguments(arguments, *type_refs_, &callback, &error); 210 arguments, *type_refs_, &converted_arguments, &callback, &error);
200 if (try_catch.HasCaught()) { 211 if (try_catch.HasCaught()) {
201 DCHECK(!parsed_arguments); 212 DCHECK(!converted_arguments);
202 try_catch.ReThrow(); 213 try_catch.ReThrow();
203 return; 214 return;
204 } 215 }
205 } 216 }
206 if (!parsed_arguments) { 217 if (!conversion_success) {
207 arguments->ThrowTypeError("Invalid invocation"); 218 arguments->ThrowTypeError("Invalid invocation");
208 return; 219 return;
209 } 220 }
210 221
211 method_callback_.Run(name, std::move(parsed_arguments), isolate, 222 DCHECK(converted_arguments);
212 context, callback); 223 method_callback_.Run(name, std::move(converted_arguments), isolate, context,
224 callback);
213 } 225 }
214 226
215 } // namespace extensions 227 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | extensions/renderer/api_signature.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698