Chromium Code Reviews| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 // catching it. | 203 // catching it. |
| 204 if (invalid_invocation) { | 204 if (invalid_invocation) { |
| 205 arguments->ThrowTypeError("Invalid invocation"); | 205 arguments->ThrowTypeError("Invalid invocation"); |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 | 208 |
| 209 { | 209 { |
| 210 v8::TryCatch try_catch(isolate); | 210 v8::TryCatch try_catch(isolate); |
| 211 APIBindingHooks::RequestResult hooks_result = | 211 APIBindingHooks::RequestResult hooks_result = |
| 212 APIBindingHooks::RequestResult::NOT_HANDLED; | 212 APIBindingHooks::RequestResult::NOT_HANDLED; |
| 213 v8::Local<v8::Value> return_value; | |
| 213 hooks_result = binding_hooks_->HandleRequest(api_name_, name, context, | 214 hooks_result = binding_hooks_->HandleRequest(api_name_, name, context, |
| 214 signature, &argument_list, | 215 signature, &argument_list, |
| 215 *type_refs_); | 216 *type_refs_, &return_value); |
| 216 | 217 |
| 217 switch (hooks_result) { | 218 switch (hooks_result) { |
| 218 case APIBindingHooks::RequestResult::INVALID_INVOCATION: | 219 case APIBindingHooks::RequestResult::INVALID_INVOCATION: |
| 219 invalid_invocation = true; | 220 invalid_invocation = true; |
| 220 // Throw a type error below so that it's not caught by our try-catch. | 221 // Throw a type error below so that it's not caught by our try-catch. |
| 221 break; | 222 break; |
| 222 case APIBindingHooks::RequestResult::THROWN: | 223 case APIBindingHooks::RequestResult::THROWN: |
| 223 DCHECK(try_catch.HasCaught()); | 224 DCHECK(try_catch.HasCaught()); |
| 224 try_catch.ReThrow(); | 225 try_catch.ReThrow(); |
| 225 return; | 226 return; |
| 226 case APIBindingHooks::RequestResult::HANDLED: | 227 case APIBindingHooks::RequestResult::HANDLED: |
| 228 if (!return_value.IsEmpty()) | |
|
jbroman
2017/01/02 20:05:46
Do we expect this to ever be IsEmpty is a case tha
Devlin
2017/01/04 18:38:07
In the case of a native (c++) handler hook without
| |
| 229 arguments->Return(return_value); | |
| 227 return; // Our work here is done. | 230 return; // Our work here is done. |
| 228 case APIBindingHooks::RequestResult::NOT_HANDLED: | 231 case APIBindingHooks::RequestResult::NOT_HANDLED: |
| 229 break; // Handle in the default manner. | 232 break; // Handle in the default manner. |
| 230 } | 233 } |
| 231 } | 234 } |
| 232 | 235 |
| 233 if (invalid_invocation) { | 236 if (invalid_invocation) { |
| 234 arguments->ThrowTypeError("Invalid invocation"); | 237 arguments->ThrowTypeError("Invalid invocation"); |
| 235 return; | 238 return; |
| 236 } | 239 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 252 arguments->ThrowTypeError("Invalid invocation"); | 255 arguments->ThrowTypeError("Invalid invocation"); |
| 253 return; | 256 return; |
| 254 } | 257 } |
| 255 | 258 |
| 256 DCHECK(converted_arguments); | 259 DCHECK(converted_arguments); |
| 257 method_callback_.Run(name, std::move(converted_arguments), isolate, context, | 260 method_callback_.Run(name, std::move(converted_arguments), isolate, context, |
| 258 callback); | 261 callback); |
| 259 } | 262 } |
| 260 | 263 |
| 261 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |