| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 SendRequestMethod send_request_; | 122 SendRequestMethod send_request_; |
| 121 | 123 |
| 122 // The method to call into a JS with specific arguments. We curry this in | 124 // The method to call into a JS with specific arguments. We curry this in |
| 123 // because the manner we want to do this is a unittest (e.g. | 125 // because the manner we want to do this is a unittest (e.g. |
| 124 // v8::Function::Call) can be significantly different than in production | 126 // v8::Function::Call) can be significantly different than in production |
| 125 // (where we have to deal with e.g. blocking javascript). | 127 // (where we have to deal with e.g. blocking javascript). |
| 126 CallJSFunction call_js_; | 128 CallJSFunction call_js_; |
| 127 | 129 |
| 128 APILastError last_error_; | 130 APILastError last_error_; |
| 129 | 131 |
| 132 // The exception handler for the bindings system; guaranteed to be valid |
| 133 // during this object's lifetime. |
| 134 ExceptionHandler* const exception_handler_; |
| 135 |
| 130 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); | 136 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); |
| 131 }; | 137 }; |
| 132 | 138 |
| 133 } // namespace extensions | 139 } // namespace extensions |
| 134 | 140 |
| 135 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ | 141 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ |
| OLD | NEW |