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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.cc ('k') | ppapi/proxy/resource_message_params.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/resource_message_params.h
diff --git a/ppapi/proxy/resource_message_params.h b/ppapi/proxy/resource_message_params.h
new file mode 100644
index 0000000000000000000000000000000000000000..0245bff6ee94b8107efbd6f412c2e1efeb22ee4a
--- /dev/null
+++ b/ppapi/proxy/resource_message_params.h
@@ -0,0 +1,125 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
+#define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
+
+#include "ipc/ipc_message_utils.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+
+namespace ppapi {
+namespace proxy {
+
+// Message routing ID used for resource messages. These messages always have a
+// ResourceMessage[Call|Reply]Params as the first parameter.
+static const int kResourceMessageRoutingID = -1;
+
+class PPAPI_PROXY_EXPORT ResourceMessageParams {
+ public:
+ virtual ~ResourceMessageParams();
+
+ PP_Resource pp_resource() const { return pp_resource_; }
+ int32_t sequence() const { return sequence_; }
+
+ protected:
+ ResourceMessageParams();
+ ResourceMessageParams(PP_Resource resource, int32_t sequence);
+
+ virtual void Serialize(IPC::Message* msg) const;
+ virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter);
+
+ private:
+ PP_Resource pp_resource_;
+
+ // Identifier for this message. Sequence numbers are quasi-unique within a
+ // resource, but will overlap between different resource objects.
+ //
+ // If you send a lot of messages, the ID may wrap around. This is OK. All IDs
+ // are valid and 0 and -1 aren't special, so those cases won't confuse us.
+ // In practice, if you send more than 4 billion messages for a resource, the
+ // old ones will be long gone and there will be no collisions.
+ //
+ // If there is a malicious plugin (or exceptionally bad luck) that causes a
+ // wraparound and collision the worst that will happen is that we can get
+ // confused between different callbacks. But since these can only cause
+ // confusion within the plugin and within callbacks on the same resoruce,
+ // there shouldn't be a security problem.
+ int32_t sequence_;
+};
+
+class PPAPI_PROXY_EXPORT ResourceMessageCallParams
+ : public ResourceMessageParams {
+ public:
+ ResourceMessageCallParams();
+ ResourceMessageCallParams(PP_Resource resource, int32_t sequence);
+ virtual ~ResourceMessageCallParams();
+
+ void set_has_callback() { flags_ |= kFlagHasCallback; }
+ bool has_callback() const { return flags_ & kFlagHasCallback; }
+
+ virtual void Serialize(IPC::Message* msg) const OVERRIDE;
+ virtual bool Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) OVERRIDE;
+
+ private:
+ uint32 flags_;
+
+ // Values used in the |flags| bitfield of ResourceRequest message.
+ static const unsigned kFlagHasCallback = 1 << 0;
+};
+
+class PPAPI_PROXY_EXPORT ResourceMessageReplyParams
+ : public ResourceMessageParams {
+ public:
+ ResourceMessageReplyParams();
+ ResourceMessageReplyParams(PP_Resource resource, int32_t sequence);
+ virtual ~ResourceMessageReplyParams();
+
+ void set_result(int32_t r) { result_ = r; }
+ int32_t result() const { return result_; }
+
+ virtual void Serialize(IPC::Message* msg) const OVERRIDE;
+ virtual bool Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) OVERRIDE;
+
+ private:
+ // Pepper "result code" for the callback.
+ int32_t result_;
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+namespace IPC {
+
+template <> struct PPAPI_PROXY_EXPORT
+ParamTraits<ppapi::proxy::ResourceMessageCallParams> {
+ typedef ppapi::proxy::ResourceMessageCallParams param_type;
+ static void Write(Message* m, const param_type& p) {
+ p.Serialize(m);
+ }
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
+ return r->Deserialize(m, iter);
+ }
+ static void Log(const param_type& p, std::string* l) {
+ }
+};
+
+template <> struct PPAPI_PROXY_EXPORT
+ParamTraits<ppapi::proxy::ResourceMessageReplyParams> {
+ typedef ppapi::proxy::ResourceMessageReplyParams param_type;
+ static void Write(Message* m, const param_type& p) {
+ p.Serialize(m);
+ }
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
+ return r->Deserialize(m, iter);
+ }
+ static void Log(const param_type& p, std::string* l) {
+ }
+};
+
+} // namespace IPC
+
+#endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
« 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