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_RESOURCE_MESSAGE_PARAMS_H_ | 5 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
6 #define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ | 6 #define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "ipc/ipc_message_utils.h" | 10 #include "ipc/ipc_message_utils.h" |
9 #include "ppapi/c/pp_resource.h" | 11 #include "ppapi/c/pp_resource.h" |
10 #include "ppapi/proxy/ppapi_proxy_export.h" | 12 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 13 #include "ppapi/proxy/serialized_structs.h" |
11 | 14 |
12 namespace ppapi { | 15 namespace ppapi { |
13 namespace proxy { | 16 namespace proxy { |
14 | 17 |
15 // Common parameters for resource call and reply params structures below. | 18 // Common parameters for resource call and reply params structures below. |
16 class PPAPI_PROXY_EXPORT ResourceMessageParams { | 19 class PPAPI_PROXY_EXPORT ResourceMessageParams { |
17 public: | 20 public: |
18 virtual ~ResourceMessageParams(); | 21 virtual ~ResourceMessageParams(); |
19 | 22 |
20 PP_Resource pp_resource() const { return pp_resource_; } | 23 PP_Resource pp_resource() const { return pp_resource_; } |
21 int32_t sequence() const { return sequence_; } | 24 int32_t sequence() const { return sequence_; } |
22 | 25 |
| 26 const std::vector<SerializedHandle> handles() const { return handles_; } |
| 27 |
| 28 // Returns a pointer to the handle at the given index if it exists and is of |
| 29 // the given type. If the index doesn't exist or the handle isn't of the |
| 30 // given type, returns NULL. Note that the pointer will be into an internal |
| 31 // vector so will be invalidated if the params are mutated. |
| 32 const SerializedHandle* GetHandleOfTypeAtIndex( |
| 33 size_t index, |
| 34 SerializedHandle::Type type) const; |
| 35 |
| 36 // Helper functions to return shared memory handles passed in the params |
| 37 // struct. If the index has a valid handle of the given type, it will be |
| 38 // placed in the output parameter and the function will return true. If the |
| 39 // handle doesn't exist or is a different type, the functions will return |
| 40 // false and the output parameter will be untouched. |
| 41 // |
| 42 // Note that the handle could still be a "null" or invalid handle of |
| 43 // the right type and the functions will succeed. |
| 44 bool GetSharedMemoryHandleAtIndex(size_t index, |
| 45 base::SharedMemoryHandle* handle) const; |
| 46 bool GetSocketHandleAtIndex(size_t index, |
| 47 IPC::PlatformFileForTransit* handle) const; |
| 48 |
| 49 // Appends the given handle to the list of handles sent with the call or |
| 50 // reply. |
| 51 void AppendHandle(const SerializedHandle& handle); |
| 52 |
23 protected: | 53 protected: |
24 ResourceMessageParams(); | 54 ResourceMessageParams(); |
25 ResourceMessageParams(PP_Resource resource, int32_t sequence); | 55 ResourceMessageParams(PP_Resource resource, int32_t sequence); |
26 | 56 |
27 virtual void Serialize(IPC::Message* msg) const; | 57 virtual void Serialize(IPC::Message* msg) const; |
28 virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter); | 58 virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter); |
29 | 59 |
30 private: | 60 private: |
31 PP_Resource pp_resource_; | 61 PP_Resource pp_resource_; |
32 | 62 |
33 // Identifier for this message. Sequence numbers are quasi-unique within a | 63 // Identifier for this message. Sequence numbers are quasi-unique within a |
34 // resource, but will overlap between different resource objects. | 64 // resource, but will overlap between different resource objects. |
35 // | 65 // |
36 // If you send a lot of messages, the ID may wrap around. This is OK. All IDs | 66 // If you send a lot of messages, the ID may wrap around. This is OK. All IDs |
37 // are valid and 0 and -1 aren't special, so those cases won't confuse us. | 67 // are valid and 0 and -1 aren't special, so those cases won't confuse us. |
38 // In practice, if you send more than 4 billion messages for a resource, the | 68 // In practice, if you send more than 4 billion messages for a resource, the |
39 // old ones will be long gone and there will be no collisions. | 69 // old ones will be long gone and there will be no collisions. |
40 // | 70 // |
41 // If there is a malicious plugin (or exceptionally bad luck) that causes a | 71 // If there is a malicious plugin (or exceptionally bad luck) that causes a |
42 // wraparound and collision the worst that will happen is that we can get | 72 // wraparound and collision the worst that will happen is that we can get |
43 // confused between different callbacks. But since these can only cause | 73 // confused between different callbacks. But since these can only cause |
44 // confusion within the plugin and within callbacks on the same resource, | 74 // confusion within the plugin and within callbacks on the same resource, |
45 // there shouldn't be a security problem. | 75 // there shouldn't be a security problem. |
46 int32_t sequence_; | 76 int32_t sequence_; |
| 77 |
| 78 // A list of all handles transferred in the message. Handles go here so that |
| 79 // the NaCl adapter can extract them generally when it rewrites them to |
| 80 // go between Windows and NaCl (Posix) apps. |
| 81 std::vector<SerializedHandle> handles_; |
47 }; | 82 }; |
48 | 83 |
49 // Parameters common to all ResourceMessage "Call" requests. | 84 // Parameters common to all ResourceMessage "Call" requests. |
50 class PPAPI_PROXY_EXPORT ResourceMessageCallParams | 85 class PPAPI_PROXY_EXPORT ResourceMessageCallParams |
51 : public ResourceMessageParams { | 86 : public ResourceMessageParams { |
52 public: | 87 public: |
53 ResourceMessageCallParams(); | 88 ResourceMessageCallParams(); |
54 ResourceMessageCallParams(PP_Resource resource, int32_t sequence); | 89 ResourceMessageCallParams(PP_Resource resource, int32_t sequence); |
55 virtual ~ResourceMessageCallParams(); | 90 virtual ~ResourceMessageCallParams(); |
56 | 91 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 147 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
113 return r->Deserialize(m, iter); | 148 return r->Deserialize(m, iter); |
114 } | 149 } |
115 static void Log(const param_type& p, std::string* l) { | 150 static void Log(const param_type& p, std::string* l) { |
116 } | 151 } |
117 }; | 152 }; |
118 | 153 |
119 } // namespace IPC | 154 } // namespace IPC |
120 | 155 |
121 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ | 156 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
OLD | NEW |