| 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_PPAPI_HOST_H_ | 5 #ifndef PPAPI_HOST_PPAPI_HOST_H_ |
| 6 #define PPAPI_HOST_PPAPI_HOST_H_ | 6 #define PPAPI_HOST_PPAPI_HOST_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/observer_list.h" |
| 12 #include "ipc/ipc_listener.h" | 13 #include "ipc/ipc_listener.h" |
| 13 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
| 14 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
| 15 #include "ppapi/c/pp_resource.h" | 16 #include "ppapi/c/pp_resource.h" |
| 16 #include "ppapi/host/ppapi_host_export.h" | 17 #include "ppapi/host/ppapi_host_export.h" |
| 17 #include "ppapi/shared_impl/ppapi_permissions.h" | 18 #include "ppapi/shared_impl/ppapi_permissions.h" |
| 18 | 19 |
| 19 namespace ppapi { | 20 namespace ppapi { |
| 20 | 21 |
| 21 namespace proxy { | 22 namespace proxy { |
| 22 class ResourceMessageCallParams; | 23 class ResourceMessageCallParams; |
| 23 class ResourceMessageReplyParams; | 24 class ResourceMessageReplyParams; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace host { | 27 namespace host { |
| 27 | 28 |
| 28 class HostFactory; | 29 class HostFactory; |
| 30 class InstanceMessageFilter; |
| 29 class ResourceHost; | 31 class ResourceHost; |
| 30 | 32 |
| 31 // The host provides routing and tracking for resource message calls that | 33 // The host provides routing and tracking for resource message calls that |
| 32 // come from the plugin to the host (browser or renderer), and the | 34 // come from the plugin to the host (browser or renderer), and the |
| 33 // corresponding replies. | 35 // corresponding replies. |
| 34 class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener { | 36 class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener { |
| 35 public: | 37 public: |
| 36 // The sender is the channel to the plugin for outgoing messages. The factory | 38 // The sender is the channel to the plugin for outgoing messages. The factory |
| 37 // will be used to receive resource creation messages from the plugin. Both | 39 // will be used to receive resource creation messages from the plugin. Both |
| 38 // pointers are owned by the caller and must outlive this class. | 40 // pointers are owned by the caller and must outlive this class. |
| 39 PpapiHost(IPC::Sender* sender, | 41 PpapiHost(IPC::Sender* sender, |
| 40 HostFactory* host_factory, | 42 HostFactory* host_factory, |
| 41 const PpapiPermissions& perms); | 43 const PpapiPermissions& perms); |
| 42 virtual ~PpapiHost(); | 44 virtual ~PpapiHost(); |
| 43 | 45 |
| 44 const PpapiPermissions& permissions() const { return permissions_; } | 46 const PpapiPermissions& permissions() const { return permissions_; } |
| 45 | 47 |
| 46 // Sender implementation. Forwards to the sender_. | 48 // Sender implementation. Forwards to the sender_. |
| 47 virtual bool Send(IPC::Message* msg) OVERRIDE; | 49 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 48 | 50 |
| 49 // Listener implementation. | 51 // Listener implementation. |
| 50 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 52 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 51 | 53 |
| 52 // Sends the given reply message to the plugin. | 54 // Sends the given reply message to the plugin. |
| 53 void SendReply(const proxy::ResourceMessageReplyParams& params, | 55 void SendReply(const proxy::ResourceMessageReplyParams& params, |
| 54 const IPC::Message& msg); | 56 const IPC::Message& msg); |
| 55 | 57 |
| 56 private: | 58 private: |
| 59 friend class InstanceMessageFilter; |
| 60 |
| 61 void AddInstanceMessageFilter(InstanceMessageFilter* filter); |
| 62 void RemoveInstanceMessageFilter(InstanceMessageFilter* filter); |
| 63 |
| 57 // Message handlers. | 64 // Message handlers. |
| 58 void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params, | 65 void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params, |
| 59 const IPC::Message& nested_msg); | 66 const IPC::Message& nested_msg); |
| 60 void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param, | 67 void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param, |
| 61 PP_Instance instance, | 68 PP_Instance instance, |
| 62 const IPC::Message& nested_msg); | 69 const IPC::Message& nested_msg); |
| 63 void OnHostMsgResourceDestroyed(PP_Resource resource); | 70 void OnHostMsgResourceDestroyed(PP_Resource resource); |
| 64 | 71 |
| 65 // Returns null if the resource doesn't exist. | 72 // Returns null if the resource doesn't exist. |
| 66 host::ResourceHost* GetResourceHost(PP_Resource resource); | 73 host::ResourceHost* GetResourceHost(PP_Resource resource); |
| 67 | 74 |
| 68 // Non-owning pointer. | 75 // Non-owning pointer. |
| 69 IPC::Sender* sender_; | 76 IPC::Sender* sender_; |
| 70 | 77 |
| 71 // Non-owning pointer. | 78 // Non-owning pointer. |
| 72 HostFactory* host_factory_; | 79 HostFactory* host_factory_; |
| 73 | 80 |
| 74 PpapiPermissions permissions_; | 81 PpapiPermissions permissions_; |
| 75 | 82 |
| 83 // Filters for instance messages. Non-owning pointers. |
| 84 ObserverList<InstanceMessageFilter> instance_message_filters_; |
| 85 |
| 76 typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap; | 86 typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap; |
| 77 ResourceMap resources_; | 87 ResourceMap resources_; |
| 78 | 88 |
| 79 DISALLOW_COPY_AND_ASSIGN(PpapiHost); | 89 DISALLOW_COPY_AND_ASSIGN(PpapiHost); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 } // namespace host | 92 } // namespace host |
| 83 } // namespace ppapi | 93 } // namespace ppapi |
| 84 | 94 |
| 85 #endif // PPAPI_HOST_PPAPIE_HOST_H_ | 95 #endif // PPAPI_HOST_PPAPIE_HOST_H_ |
| OLD | NEW |