| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 |
| 13 namespace base { |
| 14 class ListValue; |
| 15 } |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 class ChromeV8Context; |
| 20 |
| 21 // A proxy that forwards pepper apps API calls through the Javascript API |
| 22 // bindings. |
| 23 class PepperRequestProxy { |
| 24 public: |
| 25 // A callback to be called with the result of an API call. If |success| is |
| 26 // true, |response| will contain the response value. Otherwise, |error| will |
| 27 // contain the error message. |
| 28 typedef base::Callback<void(bool success, |
| 29 const base::ListValue& response, |
| 30 const std::string& error)> ResponseCallback; |
| 31 |
| 32 explicit PepperRequestProxy(ChromeV8Context* context); |
| 33 ~PepperRequestProxy(); |
| 34 |
| 35 // Starts an API request. Returns whether the call was successful. On failure, |
| 36 // |error| will contain the error message. |callback| will only be called on |
| 37 // success. |
| 38 bool StartRequest(const ResponseCallback& callback, |
| 39 const std::string& request_name, |
| 40 const base::ListValue& args, |
| 41 std::string* error); |
| 42 |
| 43 void OnResponseReceived(int request_id, |
| 44 bool success, |
| 45 const base::ListValue& args, |
| 46 const std::string& error); |
| 47 |
| 48 private: |
| 49 typedef std::map<int, ResponseCallback> PendingRequestMap; |
| 50 |
| 51 // Non-owning pointer. |
| 52 ChromeV8Context* context_; |
| 53 PendingRequestMap pending_request_map_; |
| 54 int next_request_id_; |
| 55 }; |
| 56 |
| 57 } // namespace extensions |
| 58 |
| 59 #endif // CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |
| OLD | NEW |