| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "extensions/renderer/api_binding_hooks_test_delegate.h" | |
| 6 | |
| 7 namespace extensions { | |
| 8 | |
| 9 APIBindingHooksTestDelegate::APIBindingHooksTestDelegate() {} | |
| 10 APIBindingHooksTestDelegate::~APIBindingHooksTestDelegate() {} | |
| 11 | |
| 12 bool APIBindingHooksTestDelegate::CreateCustomEvent( | |
| 13 v8::Local<v8::Context> context, | |
| 14 const binding::RunJSFunctionSync& run_js_sync, | |
| 15 const std::string& event_name, | |
| 16 v8::Local<v8::Value>* event_out) { | |
| 17 if (!custom_event_.is_null()) { | |
| 18 *event_out = custom_event_.Run(context, run_js_sync, event_name); | |
| 19 return true; | |
| 20 } | |
| 21 return false; | |
| 22 } | |
| 23 | |
| 24 void APIBindingHooksTestDelegate::AddHandler(base::StringPiece name, | |
| 25 const RequestHandler& handler) { | |
| 26 request_handlers_[name.as_string()] = handler; | |
| 27 } | |
| 28 | |
| 29 void APIBindingHooksTestDelegate::SetCustomEvent( | |
| 30 const CustomEventFactory& custom_event) { | |
| 31 custom_event_ = custom_event; | |
| 32 } | |
| 33 | |
| 34 void APIBindingHooksTestDelegate::SetTemplateInitializer( | |
| 35 const TemplateInitializer& initializer) { | |
| 36 template_initializer_ = initializer; | |
| 37 } | |
| 38 | |
| 39 APIBindingHooks::RequestResult APIBindingHooksTestDelegate::HandleRequest( | |
| 40 const std::string& method_name, | |
| 41 const APISignature* signature, | |
| 42 v8::Local<v8::Context> context, | |
| 43 std::vector<v8::Local<v8::Value>>* arguments, | |
| 44 const APITypeReferenceMap& refs) { | |
| 45 auto iter = request_handlers_.find(method_name); | |
| 46 if (iter == request_handlers_.end()) { | |
| 47 return APIBindingHooks::RequestResult( | |
| 48 APIBindingHooks::RequestResult::NOT_HANDLED); | |
| 49 } | |
| 50 return iter->second.Run(signature, context, arguments, refs); | |
| 51 } | |
| 52 | |
| 53 void APIBindingHooksTestDelegate::InitializeTemplate( | |
| 54 v8::Isolate* isolate, | |
| 55 v8::Local<v8::ObjectTemplate> object_template, | |
| 56 const APITypeReferenceMap& type_refs) { | |
| 57 if (template_initializer_) | |
| 58 template_initializer_.Run(isolate, object_template, type_refs); | |
| 59 } | |
| 60 | |
| 61 } // namespace extensions | |
| OLD | NEW |