| 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> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // with the given |response| arguments. | 78 // with the given |response| arguments. |
| 79 // Invalid ids are ignored. | 79 // Invalid ids are ignored. |
| 80 void CompleteRequest(int request_id, | 80 void CompleteRequest(int request_id, |
| 81 const base::ListValue& response, | 81 const base::ListValue& response, |
| 82 const std::string& error); | 82 const std::string& error); |
| 83 | 83 |
| 84 // Invalidates any requests that are associated with |context|. | 84 // Invalidates any requests that are associated with |context|. |
| 85 void InvalidateContext(v8::Local<v8::Context> context); | 85 void InvalidateContext(v8::Local<v8::Context> context); |
| 86 | 86 |
| 87 APILastError* last_error() { return &last_error_; } | 87 APILastError* last_error() { return &last_error_; } |
| 88 int last_sent_request_id() const { return last_sent_request_id_; } |
| 88 | 89 |
| 89 std::set<int> GetPendingRequestIdsForTesting() const; | 90 std::set<int> GetPendingRequestIdsForTesting() const; |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 struct PendingRequest { | 93 struct PendingRequest { |
| 93 PendingRequest(v8::Isolate* isolate, | 94 PendingRequest(v8::Isolate* isolate, |
| 94 v8::Local<v8::Function> callback, | 95 v8::Local<v8::Function> callback, |
| 95 v8::Local<v8::Context> context, | 96 v8::Local<v8::Context> context, |
| 96 const std::vector<v8::Local<v8::Value>>& callback_args); | 97 const std::vector<v8::Local<v8::Value>>& callback_args); |
| 97 ~PendingRequest(); | 98 ~PendingRequest(); |
| 98 PendingRequest(PendingRequest&&); | 99 PendingRequest(PendingRequest&&); |
| 99 PendingRequest& operator=(PendingRequest&&); | 100 PendingRequest& operator=(PendingRequest&&); |
| 100 | 101 |
| 101 v8::Isolate* isolate; | 102 v8::Isolate* isolate; |
| 102 v8::Global<v8::Context> context; | 103 v8::Global<v8::Context> context; |
| 103 v8::Global<v8::Function> callback; | 104 v8::Global<v8::Function> callback; |
| 104 std::vector<v8::Global<v8::Value>> callback_arguments; | 105 std::vector<v8::Global<v8::Value>> callback_arguments; |
| 105 blink::WebUserGestureToken user_gesture_token; | 106 blink::WebUserGestureToken user_gesture_token; |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 // The next available request identifier. | 109 // The next available request identifier. |
| 109 int next_request_id_ = 0; | 110 int next_request_id_ = 0; |
| 110 | 111 |
| 112 // The id of the last request we sent to the browser. This can be used as a |
| 113 // flag for whether or not a request was sent (if the last_sent_request_id_ |
| 114 // changes). |
| 115 int last_sent_request_id_ = -1; |
| 116 |
| 111 // A map of all pending requests. | 117 // A map of all pending requests. |
| 112 std::map<int, PendingRequest> pending_requests_; | 118 std::map<int, PendingRequest> pending_requests_; |
| 113 | 119 |
| 114 SendRequestMethod send_request_; | 120 SendRequestMethod send_request_; |
| 115 | 121 |
| 116 // The method to call into a JS with specific arguments. We curry this in | 122 // 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. | 123 // because the manner we want to do this is a unittest (e.g. |
| 118 // v8::Function::Call) can be significantly different than in production | 124 // v8::Function::Call) can be significantly different than in production |
| 119 // (where we have to deal with e.g. blocking javascript). | 125 // (where we have to deal with e.g. blocking javascript). |
| 120 CallJSFunction call_js_; | 126 CallJSFunction call_js_; |
| 121 | 127 |
| 122 APILastError last_error_; | 128 APILastError last_error_; |
| 123 | 129 |
| 124 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); | 130 DISALLOW_COPY_AND_ASSIGN(APIRequestHandler); |
| 125 }; | 131 }; |
| 126 | 132 |
| 127 } // namespace extensions | 133 } // namespace extensions |
| 128 | 134 |
| 129 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ | 135 #endif // EXTENSIONS_RENDERER_BINDINGS_API_REQUEST_HANDLER_H_ |
| OLD | NEW |