OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
| 6 #define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
| 7 |
| 8 #include "ipc/ipc_message_utils.h" |
| 9 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 11 |
| 12 namespace ppapi { |
| 13 namespace proxy { |
| 14 |
| 15 // Common parameters for resource call and reply params structures below. |
| 16 class PPAPI_PROXY_EXPORT ResourceMessageParams { |
| 17 public: |
| 18 virtual ~ResourceMessageParams(); |
| 19 |
| 20 PP_Resource pp_resource() const { return pp_resource_; } |
| 21 int32_t sequence() const { return sequence_; } |
| 22 |
| 23 protected: |
| 24 ResourceMessageParams(); |
| 25 ResourceMessageParams(PP_Resource resource, int32_t sequence); |
| 26 |
| 27 virtual void Serialize(IPC::Message* msg) const; |
| 28 virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter); |
| 29 |
| 30 private: |
| 31 PP_Resource pp_resource_; |
| 32 |
| 33 // Identifier for this message. Sequence numbers are quasi-unique within a |
| 34 // resource, but will overlap between different resource objects. |
| 35 // |
| 36 // 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. |
| 38 // 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. |
| 40 // |
| 41 // 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 |
| 43 // confused between different callbacks. But since these can only cause |
| 44 // confusion within the plugin and within callbacks on the same resource, |
| 45 // there shouldn't be a security problem. |
| 46 int32_t sequence_; |
| 47 }; |
| 48 |
| 49 // Parameters common to all ResourceMessage "Call" requests. |
| 50 class PPAPI_PROXY_EXPORT ResourceMessageCallParams |
| 51 : public ResourceMessageParams { |
| 52 public: |
| 53 ResourceMessageCallParams(); |
| 54 ResourceMessageCallParams(PP_Resource resource, int32_t sequence); |
| 55 virtual ~ResourceMessageCallParams(); |
| 56 |
| 57 void set_has_callback() { has_callback_ = true; } |
| 58 bool has_callback() const { return has_callback_; } |
| 59 |
| 60 virtual void Serialize(IPC::Message* msg) const OVERRIDE; |
| 61 virtual bool Deserialize(const IPC::Message* msg, |
| 62 PickleIterator* iter) OVERRIDE; |
| 63 |
| 64 private: |
| 65 bool has_callback_; |
| 66 }; |
| 67 |
| 68 // Parameters common to all ResourceMessage "Reply" requests. |
| 69 class PPAPI_PROXY_EXPORT ResourceMessageReplyParams |
| 70 : public ResourceMessageParams { |
| 71 public: |
| 72 ResourceMessageReplyParams(); |
| 73 ResourceMessageReplyParams(PP_Resource resource, int32_t sequence); |
| 74 virtual ~ResourceMessageReplyParams(); |
| 75 |
| 76 void set_result(int32_t r) { result_ = r; } |
| 77 int32_t result() const { return result_; } |
| 78 |
| 79 virtual void Serialize(IPC::Message* msg) const OVERRIDE; |
| 80 virtual bool Deserialize(const IPC::Message* msg, |
| 81 PickleIterator* iter) OVERRIDE; |
| 82 |
| 83 private: |
| 84 // Pepper "result code" for the callback. |
| 85 int32_t result_; |
| 86 }; |
| 87 |
| 88 } // namespace proxy |
| 89 } // namespace ppapi |
| 90 |
| 91 namespace IPC { |
| 92 |
| 93 template <> struct PPAPI_PROXY_EXPORT |
| 94 ParamTraits<ppapi::proxy::ResourceMessageCallParams> { |
| 95 typedef ppapi::proxy::ResourceMessageCallParams param_type; |
| 96 static void Write(Message* m, const param_type& p) { |
| 97 p.Serialize(m); |
| 98 } |
| 99 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 100 return r->Deserialize(m, iter); |
| 101 } |
| 102 static void Log(const param_type& p, std::string* l) { |
| 103 } |
| 104 }; |
| 105 |
| 106 template <> struct PPAPI_PROXY_EXPORT |
| 107 ParamTraits<ppapi::proxy::ResourceMessageReplyParams> { |
| 108 typedef ppapi::proxy::ResourceMessageReplyParams param_type; |
| 109 static void Write(Message* m, const param_type& p) { |
| 110 p.Serialize(m); |
| 111 } |
| 112 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 113 return r->Deserialize(m, iter); |
| 114 } |
| 115 static void Log(const param_type& p, std::string* l) { |
| 116 } |
| 117 }; |
| 118 |
| 119 } // namespace IPC |
| 120 |
| 121 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_ |
OLD | NEW |