Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: chrome/renderer/extensions/pepper_request_proxy.h

Issue 61383003: Pass pepper apps API calls through the existing js apps API bindings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(int request_id,
29 bool success,
30 const base::ListValue& response,
31 const std::string& error)> ResponseCallback;
32
33 explicit PepperRequestProxy(ChromeV8Context* context);
34 ~PepperRequestProxy();
35
36 // Starts an API request. Returns whether the call was successful. If the call
37 // was successful, |request_id| will contain the request ID that will be
38 // passed to |callback| when the response is received. Otherwise, |error| will
39 // contain the error message. |callback| will only be called on success.
40 bool StartCall(const ResponseCallback& callback,
41 const std::string& request_name,
42 const base::ListValue& args,
43 int* request_id,
44 std::string* error);
45
46 // Starts an API request that does not expect a response. Returns whether the
47 // call was successful. On failure, |error| will contain the error message.
48 bool StartPost(const std::string& request_name,
49 const base::ListValue& args,
50 std::string* error);
51
52 void OnResponseReceived(int request_id,
53 bool success,
54 const base::ListValue& args,
55 const std::string& error);
56
57 private:
58 typedef std::map<int, ResponseCallback> PendingRequestMap;
59
60 bool StartRequest(const std::string& request_name,
61 const std::string& method_name,
62 base::ListValue* args,
63 std::string* error);
64
65 // Non-owning pointer.
66 ChromeV8Context* context_;
67 PendingRequestMap pending_request_map_;
68 int next_request_id_;
69 };
70
71 } // namespace extensions
72
73 #endif // CHROME_RENDERER_EXTENSIONS_PEPPER_REQUEST_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698