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

Unified Diff: extensions/renderer/api_binding_hooks.h

Issue 2552343006: [Extensions Binding] Allow for registering custom hooks (Closed)
Patch Set: jbroman Created 4 years 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
Index: extensions/renderer/api_binding_hooks.h
diff --git a/extensions/renderer/api_binding_hooks.h b/extensions/renderer/api_binding_hooks.h
new file mode 100644
index 0000000000000000000000000000000000000000..373d1a3333edab4df98643c3215583a05f90ccd5
--- /dev/null
+++ b/extensions/renderer/api_binding_hooks.h
@@ -0,0 +1,53 @@
+// Copyright 2016 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.
+
+#ifndef EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_
+#define EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "extensions/renderer/api_binding_types.h"
+#include "v8/include/v8.h"
+
+namespace gin {
+class Arguments;
+}
+
+namespace extensions {
+
+// A class to register custom hooks for given API calls that need different
+// handling. An instance exists for a single API, but can be used across
+// multiple contexts (but only on the same thread).
+// TODO(devlin): We have both C++ and JS custom bindings, but this only allows
+// for registration of C++ handlers. Add JS support.
+class APIBindingHooks {
+ public:
+ using HandleRequestHook =
jbroman 2016/12/09 15:53:08 Since I was confused, it might be helpful to descr
Devlin 2016/12/09 16:35:06 Unfortunately, there isn't a full standard for thi
+ base::Callback<void(const binding::APISignature*, gin::Arguments*)>;
+
+ APIBindingHooks();
+ ~APIBindingHooks();
+
+ // Register a custom binding to handle requests.
+ void RegisterHandleRequest(const std::string& method_name,
+ const HandleRequestHook& hook);
+
+ // Returns the custom hook for the given method, or a null callback if none
+ // exists.
+ HandleRequestHook GetHandleRequest(const std::string& method_name);
+
+ private:
+ // All registered request handlers.
+ std::map<std::string, HandleRequestHook> request_hooks_;
+
+ DISALLOW_COPY_AND_ASSIGN(APIBindingHooks);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_

Powered by Google App Engine
This is Rietveld 408576698