Chromium Code Reviews| 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..c7700fdbdb23357a328f6bc2c326220767fbbb3e |
| --- /dev/null |
| +++ b/extensions/renderer/api_binding_hooks.h |
| @@ -0,0 +1,56 @@ |
| +// 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 { |
|
jbroman
2016/12/08 16:58:56
Is this class expected to become more complicated
Devlin
2016/12/08 19:12:02
Yep, it will be more complicated. I actually star
|
| + public: |
| + using HandleRequestHook = |
| + base::Callback<void(const binding::APISignature*, gin::Arguments*)>; |
|
jbroman
2016/12/08 16:58:56
Is the APISignature* parameter useful here? I'd ha
Devlin
2016/12/08 19:12:02
In JS, we have a few different hooks. Specificall
jbroman
2016/12/09 15:53:08
Ah, I'd assumed the hook replaced the entire funct
Devlin
2016/12/09 16:35:06
Yeah, I'm hoping we can have the APIBinding/APIReq
|
| + |
| + explicit APIBindingHooks(const std::string& api_name); |
| + ~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: |
| + // The name of the API. |
| + std::string api_name_; |
|
jbroman
2016/12/08 16:58:56
This variable seems unused.
Devlin
2016/12/08 19:12:02
Ah, it is indeed now (leftover from when the JS im
|
| + |
| + // 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_ |