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

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

Issue 2609553003: [Extensions Bindings] Allow custom hooks to return values, throw (Closed)
Patch Set: jbroman Created 3 years, 11 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 std::vector<v8::Local<v8::Value>> argument_list; 191 std::vector<v8::Local<v8::Value>> argument_list;
192 if (arguments->Length() > 0) { 192 if (arguments->Length() > 0) {
193 // Just copying handles should never fail. 193 // Just copying handles should never fail.
194 CHECK(arguments->GetRemaining(&argument_list)); 194 CHECK(arguments->GetRemaining(&argument_list));
195 } 195 }
196 196
197 bool invalid_invocation = false; 197 bool invalid_invocation = false;
198 { 198 {
199 v8::TryCatch try_catch(isolate); 199 v8::TryCatch try_catch(isolate);
200 APIBindingHooks::RequestResult hooks_result = 200 APIBindingHooks::RequestResult hooks_result =
201 APIBindingHooks::RequestResult::NOT_HANDLED; 201 binding_hooks_->HandleRequest(api_name_, name, context,
202 hooks_result = binding_hooks_->HandleRequest(api_name_, name, context, 202 signature, &argument_list, *type_refs_);
203 signature, &argument_list,
204 *type_refs_);
205 203
206 switch (hooks_result) { 204 switch (hooks_result.code) {
207 case APIBindingHooks::RequestResult::INVALID_INVOCATION: 205 case APIBindingHooks::RequestResult::INVALID_INVOCATION:
208 invalid_invocation = true; 206 invalid_invocation = true;
209 // Throw a type error below so that it's not caught by our try-catch. 207 // Throw a type error below so that it's not caught by our try-catch.
210 break; 208 break;
211 case APIBindingHooks::RequestResult::THROWN: 209 case APIBindingHooks::RequestResult::THROWN:
212 DCHECK(try_catch.HasCaught()); 210 DCHECK(try_catch.HasCaught());
213 try_catch.ReThrow(); 211 try_catch.ReThrow();
214 return; 212 return;
215 case APIBindingHooks::RequestResult::HANDLED: 213 case APIBindingHooks::RequestResult::HANDLED:
214 if (!hooks_result.return_value.IsEmpty())
215 arguments->Return(hooks_result.return_value);
216 return; // Our work here is done. 216 return; // Our work here is done.
217 case APIBindingHooks::RequestResult::NOT_HANDLED: 217 case APIBindingHooks::RequestResult::NOT_HANDLED:
218 break; // Handle in the default manner. 218 break; // Handle in the default manner.
219 } 219 }
220 } 220 }
221 221
222 if (invalid_invocation) { 222 if (invalid_invocation) {
223 arguments->ThrowTypeError("Invalid invocation"); 223 arguments->ThrowTypeError("Invalid invocation");
224 return; 224 return;
225 } 225 }
(...skipping 15 matching lines...) Expand all
241 arguments->ThrowTypeError("Invalid invocation"); 241 arguments->ThrowTypeError("Invalid invocation");
242 return; 242 return;
243 } 243 }
244 244
245 DCHECK(converted_arguments); 245 DCHECK(converted_arguments);
246 method_callback_.Run(name, std::move(converted_arguments), isolate, context, 246 method_callback_.Run(name, std::move(converted_arguments), isolate, context,
247 callback); 247 callback);
248 } 248 }
249 249
250 } // namespace extensions 250 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | extensions/renderer/api_binding_hooks.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698