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_REQUEST_HANDLER_H_ | 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ |
6 #define EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ | 6 #define EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "extensions/renderer/bindings/api_binding_types.h" | 14 #include "extensions/renderer/bindings/api_binding_types.h" |
15 #include "extensions/renderer/bindings/api_last_error.h" | 15 #include "extensions/renderer/bindings/api_last_error.h" |
16 #include "third_party/WebKit/public/web/WebUserGestureToken.h" | 16 #include "third_party/WebKit/public/web/WebUserGestureToken.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 extensions { | 23 namespace extensions { |
24 class ExceptionHandler; | |
24 | 25 |
25 // A wrapper around a map for extension API calls. Contains all pending requests | 26 // A wrapper around a map for extension API calls. Contains all pending requests |
26 // and the associated context and callback. Designed to be used on a single | 27 // and the associated context and callback. Designed to be used on a single |
27 // thread, but amongst multiple contexts. | 28 // thread, but amongst multiple contexts. |
28 class APIRequestHandler { | 29 class APIRequestHandler { |
29 public: | 30 public: |
30 // TODO(devlin): We may want to coalesce this with the | 31 // TODO(devlin): We may want to coalesce this with the |
31 // ExtensionHostMsg_Request_Params IPC struct. | 32 // ExtensionHostMsg_Request_Params IPC struct. |
32 struct Request { | 33 struct Request { |
33 Request(); | 34 Request(); |
(...skipping 13 matching lines...) Expand all Loading... | |
47 using SendRequestMethod = | 48 using SendRequestMethod = |
48 base::Callback<void(std::unique_ptr<Request>, v8::Local<v8::Context>)>; | 49 base::Callback<void(std::unique_ptr<Request>, v8::Local<v8::Context>)>; |
49 | 50 |
50 using CallJSFunction = base::Callback<void(v8::Local<v8::Function>, | 51 using CallJSFunction = base::Callback<void(v8::Local<v8::Function>, |
51 v8::Local<v8::Context>, | 52 v8::Local<v8::Context>, |
52 int argc, | 53 int argc, |
53 v8::Local<v8::Value>[])>; | 54 v8::Local<v8::Value>[])>; |
54 | 55 |
55 APIRequestHandler(const SendRequestMethod& send_request, | 56 APIRequestHandler(const SendRequestMethod& send_request, |
56 const CallJSFunction& call_js, | 57 const CallJSFunction& call_js, |
57 APILastError last_error); | 58 APILastError last_error, |
59 ExceptionHandler* exception_handler); | |
58 ~APIRequestHandler(); | 60 ~APIRequestHandler(); |
59 | 61 |
60 // Begins the process of processing the request. Returns the identifier of the | 62 // Begins the process of processing the request. Returns the identifier of the |
61 // pending request, or -1 if no pending request was added (which can happen if | 63 // pending request, or -1 if no pending request was added (which can happen if |
62 // no callback was specified). | 64 // no callback was specified). |
63 int StartRequest(v8::Local<v8::Context> context, | 65 int StartRequest(v8::Local<v8::Context> context, |
64 const std::string& method, | 66 const std::string& method, |
65 std::unique_ptr<base::ListValue> arguments, | 67 std::unique_ptr<base::ListValue> arguments, |
66 v8::Local<v8::Function> callback, | 68 v8::Local<v8::Function> callback, |
67 v8::Local<v8::Function> custom_callback, | 69 v8::Local<v8::Function> custom_callback, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 SendRequestMethod send_request_; | 116 SendRequestMethod send_request_; |
115 | 117 |
116 // The method to call into a JS with specific arguments. We curry this in | 118 // The method to call into a JS with specific arguments. We curry this in |
117 // because the manner we want to do this is a unittest (e.g. | 119 // because the manner we want to do this is a unittest (e.g. |
118 // v8::Function::Call) can be significantly different than in production | 120 // v8::Function::Call) can be significantly different than in production |
119 // (where we have to deal with e.g. blocking javascript). | 121 // (where we have to deal with e.g. blocking javascript). |
120 CallJSFunction call_js_; | 122 CallJSFunction call_js_; |
121 | 123 |
122 APILastError last_error_; | 124 APILastError last_error_; |
123 | 125 |
126 ExceptionHandler* const exception_handler_; | |
lazyboy
2017/07/10 23:12:08
Comment about ownership
Devlin
2017/07/11 17:33:35
Done.
| |
127 | |
124 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); | 128 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); |
125 }; | 129 }; |
126 | 130 |
127 } // namespace extensions | 131 } // namespace extensions |
128 | 132 |
129 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ | 133 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ |
OLD | NEW |