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

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

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

Powered by Google App Engine
This is Rietveld 408576698