Chromium Code Reviews| Index: chrome/renderer/extensions/pepper_request_proxy.h |
| diff --git a/chrome/renderer/extensions/pepper_request_proxy.h b/chrome/renderer/extensions/pepper_request_proxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f637b30a5cc7dc17ebf0c52a5a6d0d5637cbe18a |
| --- /dev/null |
| +++ b/chrome/renderer/extensions/pepper_request_proxy.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |
| +#define CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +namespace base { |
| +class ListValue; |
| +} |
| + |
| +namespace extensions { |
| + |
| +class ChromeV8Context; |
| + |
| +// A proxy that forwards pepper apps API calls through the Javascript API |
| +// bindings. |
| +class PepperRequestProxy { |
| + public: |
| + class Source { |
| + public: |
| + virtual ~Source() {} |
| + |
| + // Called with the result of an API call. If |success| is true, |response| |
| + // will contain the response value. Otherwise, |error| will contain the |
| + // error message. |
| + virtual void OnResponseReceived(int request_id, |
| + bool success, |
| + const base::ListValue& response, |
| + const std::string& error) = 0; |
| + }; |
| + |
| + explicit PepperRequestProxy(ChromeV8Context* context); |
| + ~PepperRequestProxy(); |
| + |
| + // Starts an API request. Returns whether the call was successful. If the call |
| + // was successful, |request_id| will contain the request ID that will be |
| + // passed to the OnResponseReceived method of |source| when the response is |
| + // received. Otherwise, |error| will contain the error message. |
| + // OnResponseReceived will only be called if |has_callback| is true. |
|
yzshen1
2013/11/26 19:33:11
Will it be called if |has_callback| is true but th
Sam McNally
2013/11/27 23:40:26
Done.
|
| + bool StartRequest(Source* source, |
|
yzshen1
2013/11/26 19:33:11
Is it better to use a base::Callback instead of |s
Sam McNally
2013/11/27 23:40:26
Done.
|
| + const std::string& request_name, |
| + bool has_callback, |
| + base::ListValue& args, |
| + int* request_id, |
| + std::string* error); |
| + |
| + void OnResponse(int request_id, |
|
yzshen1
2013/11/26 19:33:11
nit: OnResponseReceived might sound better.
Sam McNally
2013/11/27 23:40:26
Done.
|
| + bool success, |
| + const base::ListValue& args, |
| + const std::string& error); |
| + |
| + // Invalidates all API calls in-flight for a source. This should be called |
| + // when a Source is destroyed. |
| + void InvalidateSource(Source* source); |
| + |
| + private: |
| + typedef std::map<int, Source*> PendingRequestMap; |
| + ChromeV8Context* context_; |
|
yzshen1
2013/11/26 19:33:11
Please comment about the ownership/lifespan of con
Sam McNally
2013/11/27 23:40:26
Done.
|
| + PendingRequestMap pending_request_map_; |
| + int next_request_id_; |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_ |