| 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_HOST_RESOURCE_HOST_H_ | 5 #ifndef PPAPI_HOST_RESOURCE_HOST_H_ |
| 6 #define PPAPI_HOST_RESOURCE_HOST_H_ | 6 #define PPAPI_HOST_RESOURCE_HOST_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" |
| 9 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/host/ppapi_host_export.h" | 13 #include "ppapi/host/ppapi_host_export.h" |
| 14 #include "ppapi/host/resource_message_handler.h" |
| 11 #include "ppapi/shared_impl/host_resource.h" | 15 #include "ppapi/shared_impl/host_resource.h" |
| 12 | 16 |
| 13 namespace IPC { | 17 namespace IPC { |
| 14 class Message; | 18 class Message; |
| 15 } | 19 } |
| 16 | 20 |
| 17 namespace ppapi { | 21 namespace ppapi { |
| 18 namespace host { | 22 namespace host { |
| 19 | 23 |
| 24 class ResourceMessageFilter; |
| 20 struct HostMessageContext; | 25 struct HostMessageContext; |
| 21 class PpapiHost; | 26 class PpapiHost; |
| 22 | 27 |
| 23 // Some (but not all) resources have a corresponding object in the host side | 28 // Some (but not all) resources have a corresponding object in the host side |
| 24 // that is kept alive as long as the resource in the plugin is alive. This is | 29 // that is kept alive as long as the resource in the plugin is alive. This is |
| 25 // the base class for such objects. | 30 // the base class for such objects. |
| 26 class PPAPI_HOST_EXPORT ResourceHost { | 31 class PPAPI_HOST_EXPORT ResourceHost : public ResourceMessageHandler { |
| 27 public: | 32 public: |
| 28 ResourceHost(PpapiHost* host, PP_Instance instance, PP_Resource resource); | 33 ResourceHost(PpapiHost* host, PP_Instance instance, PP_Resource resource); |
| 29 virtual ~ResourceHost(); | 34 virtual ~ResourceHost(); |
| 30 | 35 |
| 31 PpapiHost* host() { return host_; } | 36 PpapiHost* host() { return host_; } |
| 32 PP_Instance pp_instance() const { return pp_instance_; } | 37 PP_Instance pp_instance() const { return pp_instance_; } |
| 33 PP_Resource pp_resource() const { return pp_resource_; } | 38 PP_Resource pp_resource() const { return pp_resource_; } |
| 34 | 39 |
| 35 // Handles messages associated with a given resource object. If the flags | 40 // This runs any message filters in |message_filters_|. If the message is not |
| 36 // indicate that a response is required, the return value of this function | 41 // handled by these filters then the hosts own message handler is run. True is |
| 37 // will be sent as a resource message "response" along with the message | 42 // always returned (the message will always be handled in some way). |
| 38 // specified in the reply of the context. | 43 virtual bool HandleMessage(const IPC::Message& msg, |
| 39 // | 44 HostMessageContext* context) OVERRIDE; |
| 40 // You can do a response asynchronously by returning PP_OK_COMPLETIONPENDING. | 45 |
| 41 // This will cause the reply to be skipped, and the class implementing this | 46 virtual void SendReply(const ReplyMessageContext& context, |
| 42 // function will take responsibility for issuing the callback. The callback | 47 const IPC::Message& msg) OVERRIDE; |
| 43 // can be issued inside OnResourceMessageReceived before it returns, or at | 48 |
| 44 // a future time. | 49 protected: |
| 45 // | 50 // Adds a ResourceMessageFilter to handle resource messages. Incoming |
| 46 // If you don't have a particular reply message, you can just ignore | 51 // messages will be passed to the handlers of these filters before being |
| 47 // the reply in the message context. However, if you have a reply more than | 52 // handled by the resource hosts own message handler. This allows |
| 48 // just the int32_t result code, set the reply to be the message of your | 53 // ResourceHosts to easily handle messages on other threads. |
| 49 // choosing. | 54 void AddFilter(scoped_refptr<ResourceMessageFilter> filter); |
| 50 // | |
| 51 // The default implementation just returns PP_ERROR_NOTSUPPORTED. | |
| 52 virtual int32_t OnResourceMessageReceived(const IPC::Message& msg, | |
| 53 HostMessageContext* context); | |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 // The host that owns this object. | 57 // The host that owns this object. |
| 57 PpapiHost* host_; | 58 PpapiHost* host_; |
| 58 | 59 |
| 59 PP_Instance pp_instance_; | 60 PP_Instance pp_instance_; |
| 60 PP_Resource pp_resource_; | 61 PP_Resource pp_resource_; |
| 61 | 62 |
| 63 // A vector of message filters which the host will forward incoming resource |
| 64 // messages to. |
| 65 std::vector<scoped_refptr<ResourceMessageFilter> > message_filters_; |
| 66 |
| 62 DISALLOW_COPY_AND_ASSIGN(ResourceHost); | 67 DISALLOW_COPY_AND_ASSIGN(ResourceHost); |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 } // namespace host | 70 } // namespace host |
| 66 } // namespace ppapi | 71 } // namespace ppapi |
| 67 | 72 |
| 68 #endif // PPAPI_HOST_RESOURCE_HOST_H_ | 73 #endif // PPAPI_HOST_RESOURCE_HOST_H_ |
| OLD | NEW |