Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_ | |
| 6 #define EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "extensions/renderer/api_binding_types.h" | |
| 15 #include "v8/include/v8.h" | |
| 16 | |
| 17 namespace gin { | |
| 18 class Arguments; | |
| 19 } | |
| 20 | |
| 21 namespace extensions { | |
| 22 | |
| 23 // A class to register custom hooks for given API calls that need different | |
| 24 // handling. An instance exists for a single API, but can be used across | |
| 25 // multiple contexts (but only on the same thread). | |
| 26 // TODO(devlin): We have both C++ and JS custom bindings, but this only allows | |
| 27 // for registration of C++ handlers. Add JS support. | |
| 28 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
| |
| 29 public: | |
| 30 using HandleRequestHook = | |
| 31 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
| |
| 32 | |
| 33 explicit APIBindingHooks(const std::string& api_name); | |
| 34 ~APIBindingHooks(); | |
| 35 | |
| 36 // Register a custom binding to handle requests. | |
| 37 void RegisterHandleRequest(const std::string& method_name, | |
| 38 const HandleRequestHook& hook); | |
| 39 | |
| 40 // Returns the custom hook for the given method, or a null callback if none | |
| 41 // exists. | |
| 42 HandleRequestHook GetHandleRequest(const std::string& method_name); | |
| 43 | |
| 44 private: | |
| 45 // The name of the API. | |
| 46 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
| |
| 47 | |
| 48 // All registered request handlers. | |
| 49 std::map<std::string, HandleRequestHook> request_hooks_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(APIBindingHooks); | |
| 52 }; | |
| 53 | |
| 54 } // namespace extensions | |
| 55 | |
| 56 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_ | |
| OLD | NEW |