OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PROXY_PLUGIN_DISPATCHER_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
6 #define PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 6 #define PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/process.h" | 11 #include "base/process.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "build/build_config.h" |
13 #include "ppapi/c/pp_rect.h" | 14 #include "ppapi/c/pp_rect.h" |
14 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
15 #include "ppapi/proxy/dispatcher.h" | 16 #include "ppapi/proxy/dispatcher.h" |
16 | 17 |
17 class MessageLoop; | 18 class MessageLoop; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class WaitableEvent; | 21 class WaitableEvent; |
21 } | 22 } |
22 | 23 |
23 namespace pp { | 24 namespace pp { |
24 namespace proxy { | 25 namespace proxy { |
25 | 26 |
26 // Used to keep track of per-instance data. | 27 // Used to keep track of per-instance data. |
27 struct InstanceData { | 28 struct InstanceData { |
28 PP_Rect position; | 29 PP_Rect position; |
29 }; | 30 }; |
30 | 31 |
31 class PluginDispatcher : public Dispatcher { | 32 class PluginDispatcher : public Dispatcher { |
32 public: | 33 public: |
33 // Constructor for the plugin side. The init and shutdown functions will be | 34 // Constructor for the plugin side. The init and shutdown functions will be |
34 // will be automatically called when requested by the renderer side. The | 35 // will be automatically called when requested by the renderer side. The |
35 // module ID will be set upon receipt of the InitializeModule message. | 36 // module ID will be set upon receipt of the InitializeModule message. |
36 // | 37 // |
37 // You must call Dispatcher::InitWithChannel after the constructor. | 38 // You must call Dispatcher::InitWithChannel after the constructor. |
38 PluginDispatcher(base::ProcessHandle remote_process_handle, | 39 PluginDispatcher(base::ProcessHandle remote_process_handle, |
39 GetInterfaceFunc get_interface, | 40 GetInterfaceFunc get_interface); |
40 InitModuleFunc init_module, | |
41 ShutdownModuleFunc shutdown_module); | |
42 ~PluginDispatcher(); | 41 ~PluginDispatcher(); |
43 | 42 |
44 // The plugin side maintains a mapping from PP_Instance to Dispatcher so | 43 // The plugin side maintains a mapping from PP_Instance to Dispatcher so |
45 // that we can send the messages to the right channel if there are multiple | 44 // that we can send the messages to the right channel if there are multiple |
46 // renderers sharing the same plugin. This mapping is maintained by | 45 // renderers sharing the same plugin. This mapping is maintained by |
47 // DidCreateInstance/DidDestroyInstance. | 46 // DidCreateInstance/DidDestroyInstance. |
48 static PluginDispatcher* GetForInstance(PP_Instance instance); | 47 static PluginDispatcher* GetForInstance(PP_Instance instance); |
49 | 48 |
| 49 static const void* GetInterfaceFromDispatcher(const char* interface); |
| 50 |
50 // Dispatcher overrides. | 51 // Dispatcher overrides. |
51 virtual bool IsPlugin() const; | 52 virtual bool IsPlugin() const; |
52 | 53 |
53 // IPC::Channel::Listener implementation. | 54 // IPC::Channel::Listener implementation. |
54 virtual bool OnMessageReceived(const IPC::Message& msg); | 55 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 56 virtual void OnChannelError(); |
55 | 57 |
56 // Keeps track of which dispatcher to use for each instance, active instances | 58 // Keeps track of which dispatcher to use for each instance, active instances |
57 // and tracks associated data like the current size. | 59 // and tracks associated data like the current size. |
58 void DidCreateInstance(PP_Instance instance); | 60 void DidCreateInstance(PP_Instance instance); |
59 void DidDestroyInstance(PP_Instance instance); | 61 void DidDestroyInstance(PP_Instance instance); |
60 | 62 |
61 // Gets the data for an existing instance, or NULL if the instance id doesn't | 63 // Gets the data for an existing instance, or NULL if the instance id doesn't |
62 // correspond to a known instance. | 64 // correspond to a known instance. |
63 InstanceData* GetInstanceData(PP_Instance instance); | 65 InstanceData* GetInstanceData(PP_Instance instance); |
64 | 66 |
| 67 #if defined(OS_POSIX) |
| 68 // See renderer_fd_ below. |
| 69 int GetRendererFD(); |
| 70 void CloseRendererFD(); |
| 71 #endif |
| 72 |
65 private: | 73 private: |
66 friend class PluginDispatcherTest; | 74 friend class PluginDispatcherTest; |
67 | 75 |
| 76 // Notifies all live instances that they're now closed. This is used when |
| 77 // a renderer crashes or some other error is received. |
| 78 void ForceFreeAllInstances(); |
| 79 |
68 // IPC message handlers. | 80 // IPC message handlers. |
69 void OnMsgInitializeModule(PP_Module pp_module, bool* result); | |
70 void OnMsgShutdown(); | |
71 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); | 81 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); |
72 | 82 |
73 InitModuleFunc init_module_; | 83 #if defined(OS_POSIX) |
74 ShutdownModuleFunc shutdown_module_; | 84 // FD for the renderer end of the socket. It is closed when the IPC layer |
| 85 // indicates that the channel is connected, proving that the renderer has |
| 86 // access to its side of the socket. |
| 87 int renderer_fd_; |
| 88 #endif |
75 | 89 |
76 // All target proxies currently created. These are ones that receive | 90 // All target proxies currently created. These are ones that receive |
77 // messages. | 91 // messages. |
78 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; | 92 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; |
79 | 93 |
80 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; | 94 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; |
81 InstanceDataMap instance_map_; | 95 InstanceDataMap instance_map_; |
82 | 96 |
83 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); | 97 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); |
84 }; | 98 }; |
85 | 99 |
86 } // namespace proxy | 100 } // namespace proxy |
87 } // namespace pp | 101 } // namespace pp |
88 | 102 |
89 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 103 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
OLD | NEW |