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

Side by Side Diff: extensions/renderer/api_binding.h

Issue 2552343006: [Extensions Binding] Allow for registering custom hooks (Closed)
Patch Set: . 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
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/api_binding.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_RENDERER_API_BINDING_H_ 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_H_
6 #define EXTENSIONS_RENDERER_API_BINDING_H_ 6 #define EXTENSIONS_RENDERER_API_BINDING_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
16 #include "extensions/renderer/argument_spec.h" 16 #include "extensions/renderer/argument_spec.h"
17 #include "v8/include/v8.h" 17 #include "v8/include/v8.h"
18 18
19 namespace base { 19 namespace base {
20 class ListValue; 20 class ListValue;
21 } 21 }
22 22
23 namespace gin { 23 namespace gin {
24 class Arguments; 24 class Arguments;
25 } 25 }
26 26
27 namespace extensions { 27 namespace extensions {
28 class APIBindingHooks;
28 class APIEventHandler; 29 class APIEventHandler;
29 30
30 // A class that vends v8::Objects for extension APIs. These APIs have function 31 // A class that vends v8::Objects for extension APIs. These APIs have function
31 // interceptors for all exposed methods, which call back into the APIBinding. 32 // interceptors for all exposed methods, which call back into the APIBinding.
32 // The APIBinding then matches the calling arguments against an expected method 33 // The APIBinding then matches the calling arguments against an expected method
33 // signature, throwing an error if they don't match. 34 // signature, throwing an error if they don't match.
34 // There should only need to be a single APIBinding object for each API, and 35 // There should only need to be a single APIBinding object for each API, and
35 // each can vend multiple v8::Objects for different contexts. 36 // each can vend multiple v8::Objects for different contexts.
36 // TODO(devlin): What's the lifetime of this object? 37 // TODO(devlin): What's the lifetime of this object?
37 class APIBinding { 38 class APIBinding {
(...skipping 17 matching lines...) Expand all
55 using HandlerCallback = base::Callback<void(gin::Arguments*)>; 56 using HandlerCallback = base::Callback<void(gin::Arguments*)>;
56 57
57 // The ArgumentSpec::RefMap is required to outlive this object. 58 // The ArgumentSpec::RefMap is required to outlive this object.
58 // |type_definitions| and |event_definitions| may be null if the API does not 59 // |type_definitions| and |event_definitions| may be null if the API does not
59 // specify any types or events. 60 // specify any types or events.
60 APIBinding(const std::string& name, 61 APIBinding(const std::string& name,
61 const base::ListValue& function_definitions, 62 const base::ListValue& function_definitions,
62 const base::ListValue* type_definitions, 63 const base::ListValue* type_definitions,
63 const base::ListValue* event_definitions, 64 const base::ListValue* event_definitions,
64 const APIMethodCallback& callback, 65 const APIMethodCallback& callback,
66 std::unique_ptr<APIBindingHooks> binding_hooks,
65 ArgumentSpec::RefMap* type_refs); 67 ArgumentSpec::RefMap* type_refs);
66 ~APIBinding(); 68 ~APIBinding();
67 69
68 // Returns a new v8::Object for the API this APIBinding represents. 70 // Returns a new v8::Object for the API this APIBinding represents.
69 v8::Local<v8::Object> CreateInstance( 71 v8::Local<v8::Object> CreateInstance(
70 v8::Local<v8::Context> context, 72 v8::Local<v8::Context> context,
71 v8::Isolate* isolate, 73 v8::Isolate* isolate,
72 APIEventHandler* event_handler, 74 APIEventHandler* event_handler,
73 const AvailabilityCallback& is_available); 75 const AvailabilityCallback& is_available);
74 76
(...skipping 11 matching lines...) Expand all
86 88
87 // A map from method name to expected signature. 89 // A map from method name to expected signature.
88 std::map<std::string, std::unique_ptr<APISignature>> signatures_; 90 std::map<std::string, std::unique_ptr<APISignature>> signatures_;
89 91
90 // The names of all events associated with this API. 92 // The names of all events associated with this API.
91 std::vector<std::string> event_names_; 93 std::vector<std::string> event_names_;
92 94
93 // The callback to use when an API is invoked with valid arguments. 95 // The callback to use when an API is invoked with valid arguments.
94 APIMethodCallback method_callback_; 96 APIMethodCallback method_callback_;
95 97
98 // The registered hooks for this API. Null if there are no registered custom
99 // hooks.
100 std::unique_ptr<APIBindingHooks> binding_hooks_;
101
96 // The reference map for all known types; required to outlive this object. 102 // The reference map for all known types; required to outlive this object.
97 const ArgumentSpec::RefMap* type_refs_; 103 const ArgumentSpec::RefMap* type_refs_;
98 104
99 base::WeakPtrFactory<APIBinding> weak_factory_; 105 base::WeakPtrFactory<APIBinding> weak_factory_;
100 106
101 DISALLOW_COPY_AND_ASSIGN(APIBinding); 107 DISALLOW_COPY_AND_ASSIGN(APIBinding);
102 }; 108 };
103 109
104 } // namespace extensions 110 } // namespace extensions
105 111
106 #endif // EXTENSIONS_RENDERER_API_BINDING_H_ 112 #endif // EXTENSIONS_RENDERER_API_BINDING_H_
OLDNEW
« no previous file with comments | « extensions/renderer/BUILD.gn ('k') | extensions/renderer/api_binding.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698