| 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_MESSAGE_HANDLER_H_ | 
| 6 #define PPAPI_HOST_RESOURCE_HOST_H_ | 6 #define PPAPI_HOST_RESOURCE_MESSAGE_HANDLER_H_ | 
| 7 | 7 | 
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" | 
| 9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_stdint.h" | 
| 10 #include "ppapi/host/ppapi_host_export.h" | 10 #include "ppapi/host/ppapi_host_export.h" | 
| 11 #include "ppapi/shared_impl/host_resource.h" |  | 
| 12 | 11 | 
| 13 namespace IPC { | 12 namespace IPC { | 
| 14 class Message; | 13 class Message; | 
| 15 } | 14 } | 
| 16 | 15 | 
| 17 namespace ppapi { | 16 namespace ppapi { | 
| 18 namespace host { | 17 namespace host { | 
| 19 | 18 | 
| 20 struct HostMessageContext; | 19 struct HostMessageContext; | 
| 21 class PpapiHost; | 20 struct ReplyMessageContext; | 
| 22 | 21 | 
| 23 // Some (but not all) resources have a corresponding object in the host side | 22 // This is the base class of classes that can handle resource messages. It | 
| 24 // that is kept alive as long as the resource in the plugin is alive. This is | 23 // mainly exists at present to share code for checking replies to resource | 
| 25 // the base class for such objects. | 24 // messages are valid. | 
| 26 class PPAPI_HOST_EXPORT ResourceHost { | 25 class PPAPI_HOST_EXPORT ResourceMessageHandler { | 
| 27  public: | 26  public: | 
| 28   ResourceHost(PpapiHost* host, PP_Instance instance, PP_Resource resource); | 27   ResourceMessageHandler(); | 
| 29   virtual ~ResourceHost(); | 28   virtual ~ResourceMessageHandler(); | 
| 30 | 29 | 
| 31   PpapiHost* host() { return host_; } | 30   // Called when this handler should handle a particular message. This should | 
| 32   PP_Instance pp_instance() const { return pp_instance_; } | 31   // call into the the message handler implemented by subclasses (i.e. | 
| 33   PP_Resource pp_resource() const { return pp_resource_; } | 32   // |OnResourceMessageReceived|) and perform any additional work necessary to | 
|  | 33   // handle the message (e.g. checking resource replies are valid). True is | 
|  | 34   // returned if the message is handled and false otherwise. | 
|  | 35   virtual bool HandleMessage(const IPC::Message& msg, | 
|  | 36                              HostMessageContext* context) = 0; | 
|  | 37 | 
|  | 38   // Send a resource reply message. | 
|  | 39   virtual void SendReply(const ReplyMessageContext& context, | 
|  | 40                          const IPC::Message& msg) = 0; | 
|  | 41 | 
|  | 42  protected: | 
|  | 43   // Runs the message handler and checks that a reply was sent if necessary. | 
|  | 44   void RunMessageHandlerAndReply(const IPC::Message& msg, | 
|  | 45                                  HostMessageContext* context); | 
| 34 | 46 | 
| 35   // Handles messages associated with a given resource object. If the flags | 47   // Handles messages associated with a given resource object. If the flags | 
| 36   // indicate that a response is required, the return value of this function | 48   // indicate that a response is required, the return value of this function | 
| 37   // will be sent as a resource message "response" along with the message | 49   // will be sent as a resource message "response" along with the message | 
| 38   // specified in the reply of the context. | 50   // specified in the reply of the context. | 
| 39   // | 51   // | 
| 40   // You can do a response asynchronously by returning PP_OK_COMPLETIONPENDING. | 52   // You can do a response asynchronously by returning PP_OK_COMPLETIONPENDING. | 
| 41   // This will cause the reply to be skipped, and the class implementing this | 53   // This will cause the reply to be skipped, and the class implementing this | 
| 42   // function will take responsibility for issuing the callback. The callback | 54   // function will take responsibility for issuing the callback. The callback | 
| 43   // can be issued inside OnResourceMessageReceived before it returns, or at | 55   // can be issued inside OnResourceMessageReceived before it returns, or at | 
| 44   // a future time. | 56   // a future time. | 
| 45   // | 57   // | 
| 46   // If you don't have a particular reply message, you can just ignore | 58   // If you don't have a particular reply message, you can just ignore | 
| 47   // the reply in the message context. However, if you have a reply more than | 59   // the reply in the message context. However, if you have a reply more than | 
| 48   // just the int32_t result code, set the reply to be the message of your | 60   // just the int32_t result code, set the reply to be the message of your | 
| 49   // choosing. | 61   // choosing. | 
| 50   // | 62   // | 
| 51   // The default implementation just returns PP_ERROR_NOTSUPPORTED. | 63   // The default implementation just returns PP_ERROR_NOTSUPPORTED. | 
| 52   virtual int32_t OnResourceMessageReceived(const IPC::Message& msg, | 64   virtual int32_t OnResourceMessageReceived(const IPC::Message& msg, | 
| 53                                             HostMessageContext* context); | 65                                             HostMessageContext* context); | 
| 54 | 66 | 
| 55  private: | 67  private: | 
| 56   // The host that owns this object. | 68   DISALLOW_COPY_AND_ASSIGN(ResourceMessageHandler); | 
| 57   PpapiHost* host_; |  | 
| 58 |  | 
| 59   PP_Instance pp_instance_; |  | 
| 60   PP_Resource pp_resource_; |  | 
| 61 |  | 
| 62   DISALLOW_COPY_AND_ASSIGN(ResourceHost); |  | 
| 63 }; | 69 }; | 
| 64 | 70 | 
| 65 }  // namespace host | 71 }  // namespace host | 
| 66 }  // namespace ppapi | 72 }  // namespace ppapi | 
| 67 | 73 | 
| 68 #endif  // PPAPI_HOST_RESOURCE_HOST_H_ | 74 #endif  // PPAPI_HOST_RESOURCE_MESSAGE_HANDLER_H_ | 
| OLD | NEW | 
|---|