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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 {
29 public:
30 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
31 base::Callback<void(const binding::APISignature*, gin::Arguments*)>;
32
33 APIBindingHooks();
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 // All registered request handlers.
46 std::map<std::string, HandleRequestHook> request_hooks_;
47
48 DISALLOW_COPY_AND_ASSIGN(APIBindingHooks);
49 };
50
51 } // namespace extensions
52
53 #endif // EXTENSIONS_RENDERER_API_BINDING_HOOKS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698