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.
5 #ifndef CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_
6 #define CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_
11 #include "base/callback.h"
21 namespace extensions
{
23 class ChromeV8Context
;
25 // A proxy that forwards pepper apps API calls through the Javascript API
27 class PepperRequestProxy
{
29 // A callback to be called with the result of an API call. If |success| is
30 // true, |response| will contain the response value. Otherwise, |error| will
31 // contain the error message.
32 typedef base::Callback
<void(bool success
,
33 const base::ListValue
& response
,
34 const std::string
& error
)> ResponseCallback
;
36 explicit PepperRequestProxy(ChromeV8Context
* context
);
37 ~PepperRequestProxy();
39 // Starts an API request. Returns whether the call was successful. On failure,
40 // |error| will contain the error message. |callback| will only be called on
42 bool StartRequest(const ResponseCallback
& callback
,
43 const std::string
& request_name
,
44 const base::ListValue
& args
,
47 void OnResponseReceived(int request_id
,
49 const base::ListValue
& args
,
50 const std::string
& error
);
53 typedef std::map
<int, ResponseCallback
> PendingRequestMap
;
55 // Non-owning pointer.
56 ChromeV8Context
* context_
;
57 // Non-owning pointer.
58 v8::Isolate
* isolate_
;
59 PendingRequestMap pending_request_map_
;
63 } // namespace extensions
65 #endif // CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_