OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |