OLD | NEW |
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_BINDINGS_API_BINDING_H_ | 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_API_BINDING_H_ |
6 #define EXTENSIONS_RENDERER_BINDINGS_API_BINDING_H_ | 6 #define EXTENSIONS_RENDERER_BINDINGS_API_BINDING_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // This object is designed to be one-per-isolate, but used across separate | 45 // This object is designed to be one-per-isolate, but used across separate |
46 // contexts. | 46 // contexts. |
47 class APIBinding { | 47 class APIBinding { |
48 public: | 48 public: |
49 using CreateCustomType = base::Callback<v8::Local<v8::Object>( | 49 using CreateCustomType = base::Callback<v8::Local<v8::Object>( |
50 v8::Isolate* isolate, | 50 v8::Isolate* isolate, |
51 const std::string& type_name, | 51 const std::string& type_name, |
52 const std::string& property_name, | 52 const std::string& property_name, |
53 const base::ListValue* property_values)>; | 53 const base::ListValue* property_values)>; |
54 | 54 |
| 55 // Called when a request is handled without notifying the browser. |
| 56 using OnSilentRequest = |
| 57 base::Callback<void(v8::Local<v8::Context>, |
| 58 const std::string& name, |
| 59 const std::vector<v8::Local<v8::Value>>& arguments)>; |
| 60 |
55 // The callback type for handling an API call. | 61 // The callback type for handling an API call. |
56 using HandlerCallback = base::Callback<void(gin::Arguments*)>; | 62 using HandlerCallback = base::Callback<void(gin::Arguments*)>; |
57 | 63 |
58 // The APITypeReferenceMap is required to outlive this object. | 64 // The APITypeReferenceMap is required to outlive this object. |
59 // |function_definitions|, |type_definitions| and |event_definitions| | 65 // |function_definitions|, |type_definitions| and |event_definitions| |
60 // may be null if the API does not specify any of that category. | 66 // may be null if the API does not specify any of that category. |
61 APIBinding(const std::string& name, | 67 APIBinding(const std::string& name, |
62 const base::ListValue* function_definitions, | 68 const base::ListValue* function_definitions, |
63 const base::ListValue* type_definitions, | 69 const base::ListValue* type_definitions, |
64 const base::ListValue* event_definitions, | 70 const base::ListValue* event_definitions, |
65 const base::DictionaryValue* property_definitions, | 71 const base::DictionaryValue* property_definitions, |
66 const CreateCustomType& create_custom_type, | 72 const CreateCustomType& create_custom_type, |
| 73 const OnSilentRequest& on_silent_request, |
67 std::unique_ptr<APIBindingHooks> binding_hooks, | 74 std::unique_ptr<APIBindingHooks> binding_hooks, |
68 APITypeReferenceMap* type_refs, | 75 APITypeReferenceMap* type_refs, |
69 APIRequestHandler* request_handler, | 76 APIRequestHandler* request_handler, |
70 APIEventHandler* event_handler, | 77 APIEventHandler* event_handler, |
71 BindingAccessChecker* access_checker); | 78 BindingAccessChecker* access_checker); |
72 ~APIBinding(); | 79 ~APIBinding(); |
73 | 80 |
74 // Returns a new v8::Object for the API this APIBinding represents. | 81 // Returns a new v8::Object for the API this APIBinding represents. |
75 v8::Local<v8::Object> CreateInstance(v8::Local<v8::Context> context); | 82 v8::Local<v8::Object> CreateInstance(v8::Local<v8::Context> context); |
76 | 83 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 using EnumEntry = std::pair<std::string, std::string>; | 131 using EnumEntry = std::pair<std::string, std::string>; |
125 // A map of <name, values> for the enums on this API. | 132 // A map of <name, values> for the enums on this API. |
126 std::map<std::string, std::vector<EnumEntry>> enums_; | 133 std::map<std::string, std::vector<EnumEntry>> enums_; |
127 | 134 |
128 // The associated properties of the API, if any. | 135 // The associated properties of the API, if any. |
129 const base::DictionaryValue* property_definitions_; | 136 const base::DictionaryValue* property_definitions_; |
130 | 137 |
131 // The callback for constructing a custom type. | 138 // The callback for constructing a custom type. |
132 CreateCustomType create_custom_type_; | 139 CreateCustomType create_custom_type_; |
133 | 140 |
| 141 OnSilentRequest on_silent_request_; |
| 142 |
134 // The registered hooks for this API. | 143 // The registered hooks for this API. |
135 std::unique_ptr<APIBindingHooks> binding_hooks_; | 144 std::unique_ptr<APIBindingHooks> binding_hooks_; |
136 | 145 |
137 // The reference map for all known types; required to outlive this object. | 146 // The reference map for all known types; required to outlive this object. |
138 APITypeReferenceMap* type_refs_; | 147 APITypeReferenceMap* type_refs_; |
139 | 148 |
140 // The associated request handler, shared between this and other bindings. | 149 // The associated request handler, shared between this and other bindings. |
141 // Required to outlive this object. | 150 // Required to outlive this object. |
142 APIRequestHandler* request_handler_; | 151 APIRequestHandler* request_handler_; |
143 | 152 |
(...skipping 10 matching lines...) Expand all Loading... |
154 v8::Eternal<v8::ObjectTemplate> object_template_; | 163 v8::Eternal<v8::ObjectTemplate> object_template_; |
155 | 164 |
156 base::WeakPtrFactory<APIBinding> weak_factory_; | 165 base::WeakPtrFactory<APIBinding> weak_factory_; |
157 | 166 |
158 DISALLOW_COPY_AND_ASSIGN(APIBinding); | 167 DISALLOW_COPY_AND_ASSIGN(APIBinding); |
159 }; | 168 }; |
160 | 169 |
161 } // namespace extensions | 170 } // namespace extensions |
162 | 171 |
163 #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDING_H_ | 172 #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDING_H_ |
OLD | NEW |