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

Side by Side Diff: ppapi/proxy/resource_message_params.h

Issue 10544089: Implement the file chooser as a new resource "host" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.cc ('k') | ppapi/proxy/resource_message_params.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Message routing ID used for resource messages. These messages always have a
16 // ResourceMessage[Call|Reply]Params as the first parameter.
17 static const int kResourceMessageRoutingID = -1;
18
19 class PPAPI_PROXY_EXPORT ResourceMessageParams {
20 public:
21 virtual ~ResourceMessageParams();
22
23 PP_Resource pp_resource() const { return pp_resource_; }
24 int32_t sequence() const { return sequence_; }
25
26 protected:
27 ResourceMessageParams();
28 ResourceMessageParams(PP_Resource resource, int32_t sequence);
29
30 virtual void Serialize(IPC::Message* msg) const;
31 virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter);
32
33 private:
34 PP_Resource pp_resource_;
35
36 // Identifier for this message. Sequence numbers are quasi-unique within a
37 // resource, but will overlap between different resource objects.
38 //
39 // If you send a lot of messages, the ID may wrap around. This is OK. All IDs
40 // are valid and 0 and -1 aren't special, so those cases won't confuse us.
41 // In practice, if you send more than 4 billion messages for a resource, the
42 // old ones will be long gone and there will be no collisions.
43 //
44 // If there is a malicious plugin (or exceptionally bad luck) that causes a
45 // wraparound and collision the worst that will happen is that we can get
46 // confused between different callbacks. But since these can only cause
47 // confusion within the plugin and within callbacks on the same resoruce,
48 // there shouldn't be a security problem.
49 int32_t sequence_;
50 };
51
52 class PPAPI_PROXY_EXPORT ResourceMessageCallParams
53 : public ResourceMessageParams {
54 public:
55 ResourceMessageCallParams();
56 ResourceMessageCallParams(PP_Resource resource, int32_t sequence);
57 virtual ~ResourceMessageCallParams();
58
59 void set_has_callback() { flags_ |= kFlagHasCallback; }
60 bool has_callback() const { return flags_ & kFlagHasCallback; }
61
62 virtual void Serialize(IPC::Message* msg) const OVERRIDE;
63 virtual bool Deserialize(const IPC::Message* msg,
64 PickleIterator* iter) OVERRIDE;
65
66 private:
67 uint32 flags_;
68
69 // Values used in the |flags| bitfield of ResourceRequest message.
70 static const unsigned kFlagHasCallback = 1 << 0;
71 };
72
73 class PPAPI_PROXY_EXPORT ResourceMessageReplyParams
74 : public ResourceMessageParams {
75 public:
76 ResourceMessageReplyParams();
77 ResourceMessageReplyParams(PP_Resource resource, int32_t sequence);
78 virtual ~ResourceMessageReplyParams();
79
80 void set_result(int32_t r) { result_ = r; }
81 int32_t result() const { return result_; }
82
83 virtual void Serialize(IPC::Message* msg) const OVERRIDE;
84 virtual bool Deserialize(const IPC::Message* msg,
85 PickleIterator* iter) OVERRIDE;
86
87 private:
88 // Pepper "result code" for the callback.
89 int32_t result_;
90 };
91
92 } // namespace proxy
93 } // namespace ppapi
94
95 namespace IPC {
96
97 template <> struct PPAPI_PROXY_EXPORT
98 ParamTraits<ppapi::proxy::ResourceMessageCallParams> {
99 typedef ppapi::proxy::ResourceMessageCallParams param_type;
100 static void Write(Message* m, const param_type& p) {
101 p.Serialize(m);
102 }
103 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
104 return r->Deserialize(m, iter);
105 }
106 static void Log(const param_type& p, std::string* l) {
107 }
108 };
109
110 template <> struct PPAPI_PROXY_EXPORT
111 ParamTraits<ppapi::proxy::ResourceMessageReplyParams> {
112 typedef ppapi::proxy::ResourceMessageReplyParams param_type;
113 static void Write(Message* m, const param_type& p) {
114 p.Serialize(m);
115 }
116 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
117 return r->Deserialize(m, iter);
118 }
119 static void Log(const param_type& p, std::string* l) {
120 }
121 };
122
123 } // namespace IPC
124
125 #endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.cc ('k') | ppapi/proxy/resource_message_params.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698