OLD | NEW |
1 // Copyright (c) 2011 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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // Used to keep track of per-instance data. | 28 // Used to keep track of per-instance data. |
29 struct InstanceData { | 29 struct InstanceData { |
30 InstanceData() : fullscreen(PP_FALSE) {} | 30 InstanceData() : fullscreen(PP_FALSE) {} |
31 PP_Rect position; | 31 PP_Rect position; |
32 PP_Bool fullscreen; | 32 PP_Bool fullscreen; |
33 }; | 33 }; |
34 | 34 |
35 class PluginDispatcher : public Dispatcher { | 35 class PluginDispatcher : public Dispatcher { |
36 public: | 36 public: |
| 37 class PluginDelegate : public ProxyChannel::Delegate { |
| 38 public: |
| 39 // Returns the set used for globally uniquifying PP_Instances. This same |
| 40 // set must be returned for all channels. |
| 41 // |
| 42 // DEREFERENCE ONLY ON THE I/O THREAD. |
| 43 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; |
| 44 |
| 45 // Returns the WebKit forwarding object used to make calls into WebKit. |
| 46 // Necessary only on the plugin side. |
| 47 virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; |
| 48 |
| 49 // Posts the given task to the WebKit thread associated with this plugin |
| 50 // process. The WebKit thread should be lazily created if it does not |
| 51 // exist yet. |
| 52 virtual void PostToWebKitThread(const tracked_objects::Location& from_here, |
| 53 const base::Closure& task) = 0; |
| 54 |
| 55 // Sends the given message to the browser. Identical semantics to |
| 56 // IPC::Message::Sender interface. |
| 57 virtual bool SendToBrowser(IPC::Message* msg) = 0; |
| 58 }; |
| 59 |
37 // Constructor for the plugin side. The init and shutdown functions will be | 60 // Constructor for the plugin side. The init and shutdown functions will be |
38 // will be automatically called when requested by the renderer side. The | 61 // will be automatically called when requested by the renderer side. The |
39 // module ID will be set upon receipt of the InitializeModule message. | 62 // module ID will be set upon receipt of the InitializeModule message. |
40 // | 63 // |
41 // You must call InitPluginWithChannel after the constructor. | 64 // You must call InitPluginWithChannel after the constructor. |
42 PluginDispatcher(base::ProcessHandle remote_process_handle, | 65 PluginDispatcher(base::ProcessHandle remote_process_handle, |
43 GetInterfaceFunc get_interface); | 66 GetInterfaceFunc get_interface); |
44 virtual ~PluginDispatcher(); | 67 virtual ~PluginDispatcher(); |
45 | 68 |
46 // The plugin side maintains a mapping from PP_Instance to Dispatcher so | 69 // The plugin side maintains a mapping from PP_Instance to Dispatcher so |
47 // that we can send the messages to the right channel if there are multiple | 70 // that we can send the messages to the right channel if there are multiple |
48 // renderers sharing the same plugin. This mapping is maintained by | 71 // renderers sharing the same plugin. This mapping is maintained by |
49 // DidCreateInstance/DidDestroyInstance. | 72 // DidCreateInstance/DidDestroyInstance. |
50 static PluginDispatcher* GetForInstance(PP_Instance instance); | 73 static PluginDispatcher* GetForInstance(PP_Instance instance); |
51 | 74 |
52 static const void* GetInterfaceFromDispatcher(const char* interface); | 75 static const void* GetInterfaceFromDispatcher(const char* interface); |
53 | 76 |
54 // You must call this function before anything else. Returns true on success. | 77 // You must call this function before anything else. Returns true on success. |
55 // The delegate pointer must outlive this class, ownership is not | 78 // The delegate pointer must outlive this class, ownership is not |
56 // transferred. | 79 // transferred. |
57 virtual bool InitPluginWithChannel(Dispatcher::Delegate* delegate, | 80 bool InitPluginWithChannel(PluginDelegate* delegate, |
58 const IPC::ChannelHandle& channel_handle, | 81 const IPC::ChannelHandle& channel_handle, |
59 bool is_client); | 82 bool is_client); |
60 | 83 |
61 // Dispatcher overrides. | 84 // Dispatcher overrides. |
62 virtual bool IsPlugin() const; | 85 virtual bool IsPlugin() const; |
63 virtual bool Send(IPC::Message* msg); | 86 virtual bool Send(IPC::Message* msg); |
64 | 87 |
65 // IPC::Channel::Listener implementation. | 88 // IPC::Channel::Listener implementation. |
66 virtual bool OnMessageReceived(const IPC::Message& msg); | 89 virtual bool OnMessageReceived(const IPC::Message& msg); |
67 virtual void OnChannelError(); | 90 virtual void OnChannelError(); |
68 | 91 |
69 // Keeps track of which dispatcher to use for each instance, active instances | 92 // Keeps track of which dispatcher to use for each instance, active instances |
70 // and tracks associated data like the current size. | 93 // and tracks associated data like the current size. |
71 void DidCreateInstance(PP_Instance instance); | 94 void DidCreateInstance(PP_Instance instance); |
72 void DidDestroyInstance(PP_Instance instance); | 95 void DidDestroyInstance(PP_Instance instance); |
73 | 96 |
74 // Gets the data for an existing instance, or NULL if the instance id doesn't | 97 // Gets the data for an existing instance, or NULL if the instance id doesn't |
75 // correspond to a known instance. | 98 // correspond to a known instance. |
76 InstanceData* GetInstanceData(PP_Instance instance); | 99 InstanceData* GetInstanceData(PP_Instance instance); |
77 | 100 |
78 // Posts the given task to the WebKit thread. | 101 // Posts the given task to the WebKit thread. |
79 void PostToWebKitThread(const tracked_objects::Location& from_here, | 102 void PostToWebKitThread(const tracked_objects::Location& from_here, |
80 const base::Closure& task); | 103 const base::Closure& task); |
81 | 104 |
| 105 // Calls the PluginDelegate.SendToBrowser function. |
| 106 bool SendToBrowser(IPC::Message* msg); |
| 107 |
82 // Returns the WebKitForwarding object used to forward events to WebKit. | 108 // Returns the WebKitForwarding object used to forward events to WebKit. |
83 ppapi::WebKitForwarding* GetWebKitForwarding(); | 109 ppapi::WebKitForwarding* GetWebKitForwarding(); |
84 | 110 |
85 // Returns the "new-style" function API for the given interface ID, creating | 111 // Returns the "new-style" function API for the given interface ID, creating |
86 // it if necessary. | 112 // it if necessary. |
87 // TODO(brettw) this is in progress. It should be merged with the target | 113 // TODO(brettw) this is in progress. It should be merged with the target |
88 // proxies so there is one list to consult. | 114 // proxies so there is one list to consult. |
89 ppapi::FunctionGroupBase* GetFunctionAPI( | 115 ppapi::FunctionGroupBase* GetFunctionAPI( |
90 pp::proxy::InterfaceID id); | 116 pp::proxy::InterfaceID id); |
91 | 117 |
92 private: | 118 private: |
93 friend class PluginDispatcherTest; | 119 friend class PluginDispatcherTest; |
94 | 120 |
95 // Notifies all live instances that they're now closed. This is used when | 121 // Notifies all live instances that they're now closed. This is used when |
96 // a renderer crashes or some other error is received. | 122 // a renderer crashes or some other error is received. |
97 void ForceFreeAllInstances(); | 123 void ForceFreeAllInstances(); |
98 | 124 |
99 // IPC message handlers. | 125 // IPC message handlers. |
100 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); | 126 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); |
101 | 127 |
| 128 PluginDelegate* plugin_delegate_; |
| 129 |
102 // All target proxies currently created. These are ones that receive | 130 // All target proxies currently created. These are ones that receive |
103 // messages. | 131 // messages. |
104 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; | 132 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; |
105 | 133 |
106 // Function proxies created for "new-style" FunctionGroups. | 134 // Function proxies created for "new-style" FunctionGroups. |
107 // TODO(brettw) this is in progress. It should be merged with the target | 135 // TODO(brettw) this is in progress. It should be merged with the target |
108 // proxies so there is one list to consult. | 136 // proxies so there is one list to consult. |
109 scoped_ptr< ::ppapi::FunctionGroupBase > | 137 scoped_ptr< ::ppapi::FunctionGroupBase > |
110 function_proxies_[INTERFACE_ID_COUNT]; | 138 function_proxies_[INTERFACE_ID_COUNT]; |
111 | 139 |
112 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; | 140 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; |
113 InstanceDataMap instance_map_; | 141 InstanceDataMap instance_map_; |
114 | 142 |
115 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); | 143 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); |
116 }; | 144 }; |
117 | 145 |
118 } // namespace proxy | 146 } // namespace proxy |
119 } // namespace pp | 147 } // namespace pp |
120 | 148 |
121 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 149 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
OLD | NEW |