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

Unified Diff: extensions/renderer/api_binding_hooks_test_delegate.cc

Issue 2831453002: [Extensions Bindings] Move custom handling to APIBindingHooksDelegate (Closed)
Patch Set: . Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/api_binding_hooks_test_delegate.h ('k') | extensions/renderer/api_binding_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding_hooks_test_delegate.cc
diff --git a/extensions/renderer/api_binding_hooks_test_delegate.cc b/extensions/renderer/api_binding_hooks_test_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42cd3e76c496af4aed827189d6594bd8c2b32ece
--- /dev/null
+++ b/extensions/renderer/api_binding_hooks_test_delegate.cc
@@ -0,0 +1,48 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/renderer/api_binding_hooks_test_delegate.h"
+
+namespace extensions {
+
+APIBindingHooksTestDelegate::APIBindingHooksTestDelegate() {}
+APIBindingHooksTestDelegate::~APIBindingHooksTestDelegate() {}
+
+bool APIBindingHooksTestDelegate::CreateCustomEvent(
+ v8::Local<v8::Context> context,
+ const binding::RunJSFunctionSync& run_js_sync,
+ const std::string& event_name,
+ v8::Local<v8::Value>* event_out) {
+ if (!custom_event_.is_null()) {
+ *event_out = custom_event_.Run(context, run_js_sync, event_name);
+ return true;
+ }
+ return false;
+}
+
+void APIBindingHooksTestDelegate::AddHandler(base::StringPiece name,
+ const RequestHandler& handler) {
+ request_handlers_[name.as_string()] = handler;
+}
+
+void APIBindingHooksTestDelegate::SetCustomEvent(
+ const CustomEventFactory& custom_event) {
+ custom_event_ = custom_event;
+}
+
+APIBindingHooks::RequestResult APIBindingHooksTestDelegate::HandleRequest(
+ const std::string& method_name,
+ const APISignature* signature,
+ v8::Local<v8::Context> context,
+ std::vector<v8::Local<v8::Value>>* arguments,
+ const APITypeReferenceMap& refs) {
+ auto iter = request_handlers_.find(method_name);
+ if (iter == request_handlers_.end()) {
+ return APIBindingHooks::RequestResult(
+ APIBindingHooks::RequestResult::NOT_HANDLED);
+ }
+ return iter->second.Run(signature, context, arguments, refs);
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/renderer/api_binding_hooks_test_delegate.h ('k') | extensions/renderer/api_binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698