OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
13 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
14 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
15 #include "ppapi/proxy/connection.h" | 15 #include "ppapi/proxy/connection.h" |
16 #include "ppapi/proxy/plugin_resource_callback.h" | 16 #include "ppapi/proxy/plugin_resource_callback.h" |
17 #include "ppapi/proxy/ppapi_message_utils.h" | 17 #include "ppapi/proxy/ppapi_message_utils.h" |
18 #include "ppapi/proxy/ppapi_proxy_export.h" | 18 #include "ppapi/proxy/ppapi_proxy_export.h" |
19 #include "ppapi/proxy/resource_message_params.h" | 19 #include "ppapi/proxy/resource_message_params.h" |
20 #include "ppapi/shared_impl/resource.h" | 20 #include "ppapi/shared_impl/resource.h" |
21 | 21 |
22 namespace ppapi { | 22 namespace ppapi { |
23 namespace proxy { | 23 namespace proxy { |
24 | 24 |
25 class PluginDispatcher; | 25 class PluginDispatcher; |
26 | 26 |
27 class PPAPI_PROXY_EXPORT PluginResource : public Resource { | 27 class PPAPI_PROXY_EXPORT PluginResource : public Resource { |
28 public: | 28 public: |
| 29 enum Destination { |
| 30 RENDERER = 0, |
| 31 BROWSER = 1 |
| 32 }; |
| 33 |
29 PluginResource(Connection connection, PP_Instance instance); | 34 PluginResource(Connection connection, PP_Instance instance); |
30 virtual ~PluginResource(); | 35 virtual ~PluginResource(); |
31 | 36 |
32 // Returns true if we've previously sent a create message to the browser | 37 // Returns true if we've previously sent a create message to the browser |
33 // or renderer. Generally resources will use these to tell if they should | 38 // or renderer. Generally resources will use these to tell if they should |
34 // lazily send create messages. | 39 // lazily send create messages. |
35 bool sent_create_to_browser() const { return sent_create_to_browser_; } | 40 bool sent_create_to_browser() const { return sent_create_to_browser_; } |
36 bool sent_create_to_renderer() const { return sent_create_to_renderer_; } | 41 bool sent_create_to_renderer() const { return sent_create_to_renderer_; } |
37 | 42 |
38 // This handles a reply to a resource call. It works by looking up the | 43 // This handles a reply to a resource call. It works by looking up the |
39 // callback that was registered when CallBrowser/CallRenderer was called | 44 // callback that was registered when CallBrowser/CallRenderer was called |
40 // and calling it with |params| and |msg|. | 45 // and calling it with |params| and |msg|. |
41 virtual void OnReplyReceived(const proxy::ResourceMessageReplyParams& params, | 46 virtual void OnReplyReceived(const proxy::ResourceMessageReplyParams& params, |
42 const IPC::Message& msg) OVERRIDE; | 47 const IPC::Message& msg) OVERRIDE; |
43 | 48 |
44 // Resource overrides. | 49 // Resource overrides. |
45 // Note: Subclasses shouldn't override these methods directly. Instead, they | 50 // Note: Subclasses shouldn't override these methods directly. Instead, they |
46 // should implement LastPluginRefWasDeleted() or InstanceWasDeleted() to get | 51 // should implement LastPluginRefWasDeleted() or InstanceWasDeleted() to get |
47 // notified. | 52 // notified. |
48 virtual void NotifyLastPluginRefWasDeleted() OVERRIDE; | 53 virtual void NotifyLastPluginRefWasDeleted() OVERRIDE; |
49 virtual void NotifyInstanceWasDeleted() OVERRIDE; | 54 virtual void NotifyInstanceWasDeleted() OVERRIDE; |
50 | 55 |
51 protected: | |
52 enum Destination { | |
53 RENDERER = 0, | |
54 BROWSER = 1 | |
55 }; | |
56 | |
57 IPC::Sender* GetSender(Destination dest) { | |
58 return dest == RENDERER ? connection_.renderer_sender : | |
59 connection_.browser_sender; | |
60 } | |
61 | 56 |
62 // Sends a create message to the browser or renderer for the current resource. | 57 // Sends a create message to the browser or renderer for the current resource. |
63 void SendCreate(Destination dest, const IPC::Message& msg); | 58 void SendCreate(Destination dest, const IPC::Message& msg); |
64 | 59 |
65 // Sends the given IPC message as a resource request to the host | 60 // Sends the given IPC message as a resource request to the host |
66 // corresponding to this resource object and does not expect a reply. | 61 // corresponding to this resource object and does not expect a reply. |
67 void Post(Destination dest, const IPC::Message& msg); | 62 void Post(Destination dest, const IPC::Message& msg); |
68 | 63 |
69 // Like Post() but expects a response. |callback| is a |base::Callback| that | 64 // Like Post() but expects a response. |callback| is a |base::Callback| that |
70 // will be run when a reply message with a sequence number matching that of | 65 // will be run when a reply message with a sequence number matching that of |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 template <class ReplyMsgClass, class A, class B, class C> | 113 template <class ReplyMsgClass, class A, class B, class C> |
119 int32_t SyncCall(Destination dest, const IPC::Message& msg, A* a, B* b, C* c); | 114 int32_t SyncCall(Destination dest, const IPC::Message& msg, A* a, B* b, C* c); |
120 template <class ReplyMsgClass, class A, class B, class C, class D> | 115 template <class ReplyMsgClass, class A, class B, class C, class D> |
121 int32_t SyncCall( | 116 int32_t SyncCall( |
122 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d); | 117 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d); |
123 template <class ReplyMsgClass, class A, class B, class C, class D, class E> | 118 template <class ReplyMsgClass, class A, class B, class C, class D, class E> |
124 int32_t SyncCall( | 119 int32_t SyncCall( |
125 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e); | 120 Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e); |
126 | 121 |
127 private: | 122 private: |
| 123 IPC::Sender* GetSender(Destination dest) { |
| 124 return dest == RENDERER ? connection_.renderer_sender : |
| 125 connection_.browser_sender; |
| 126 } |
| 127 |
128 // Helper function to send a |PpapiHostMsg_ResourceCall| to the given | 128 // Helper function to send a |PpapiHostMsg_ResourceCall| to the given |
129 // destination with |nested_msg| and |call_params|. | 129 // destination with |nested_msg| and |call_params|. |
130 bool SendResourceCall(Destination dest, | 130 bool SendResourceCall(Destination dest, |
131 const ResourceMessageCallParams& call_params, | 131 const ResourceMessageCallParams& call_params, |
132 const IPC::Message& nested_msg); | 132 const IPC::Message& nested_msg); |
133 | 133 |
134 int32_t GenericSyncCall(Destination dest, | 134 int32_t GenericSyncCall(Destination dest, |
135 const IPC::Message& msg, | 135 const IPC::Message& msg, |
136 IPC::Message* reply_msg); | 136 IPC::Message* reply_msg); |
137 | 137 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e)) | 226 if (UnpackMessage<ReplyMsgClass>(reply, a, b, c, d, e)) |
227 return result; | 227 return result; |
228 return PP_ERROR_FAILED; | 228 return PP_ERROR_FAILED; |
229 } | 229 } |
230 | 230 |
231 } // namespace proxy | 231 } // namespace proxy |
232 } // namespace ppapi | 232 } // namespace ppapi |
233 | 233 |
234 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 234 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
OLD | NEW |