| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/process.h" | 13 #include "base/process.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "ppapi/c/pp_rect.h" | 15 #include "ppapi/c/pp_rect.h" |
| 16 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/proxy/dispatcher.h" | 17 #include "ppapi/proxy/dispatcher.h" |
| 18 #include "ppapi/shared_impl/function_group_base.h" | 18 #include "ppapi/shared_impl/function_group_base.h" |
| 19 #include "ppapi/shared_impl/ppapi_preferences.h" | 19 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 20 | 20 |
| 21 class MessageLoop; | 21 class MessageLoop; |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 class WaitableEvent; | 24 class WaitableEvent; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ppapi { | 27 namespace ppapi { |
| 28 |
| 28 struct Preferences; | 29 struct Preferences; |
| 29 class Resource; | 30 class Resource; |
| 30 } | |
| 31 | 31 |
| 32 namespace pp { | |
| 33 namespace proxy { | 32 namespace proxy { |
| 34 | 33 |
| 35 // Used to keep track of per-instance data. | 34 // Used to keep track of per-instance data. |
| 36 struct InstanceData { | 35 struct InstanceData { |
| 37 InstanceData() : fullscreen(PP_FALSE) {} | 36 InstanceData() : fullscreen(PP_FALSE) {} |
| 38 PP_Rect position; | 37 PP_Rect position; |
| 39 PP_Bool fullscreen; | 38 PP_Bool fullscreen; |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 class PluginDispatcher : public Dispatcher { | 41 class PluginDispatcher : public Dispatcher { |
| 43 public: | 42 public: |
| 44 class PluginDelegate : public ProxyChannel::Delegate { | 43 class PluginDelegate : public ProxyChannel::Delegate { |
| 45 public: | 44 public: |
| 46 // Returns the set used for globally uniquifying PP_Instances. This same | 45 // Returns the set used for globally uniquifying PP_Instances. This same |
| 47 // set must be returned for all channels. | 46 // set must be returned for all channels. |
| 48 // | 47 // |
| 49 // DEREFERENCE ONLY ON THE I/O THREAD. | 48 // DEREFERENCE ONLY ON THE I/O THREAD. |
| 50 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; | 49 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() = 0; |
| 51 | 50 |
| 52 // Returns the WebKit forwarding object used to make calls into WebKit. | 51 // Returns the WebKit forwarding object used to make calls into WebKit. |
| 53 // Necessary only on the plugin side. | 52 // Necessary only on the plugin side. |
| 54 virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; | 53 virtual WebKitForwarding* GetWebKitForwarding() = 0; |
| 55 | 54 |
| 56 // Posts the given task to the WebKit thread associated with this plugin | 55 // Posts the given task to the WebKit thread associated with this plugin |
| 57 // process. The WebKit thread should be lazily created if it does not | 56 // process. The WebKit thread should be lazily created if it does not |
| 58 // exist yet. | 57 // exist yet. |
| 59 virtual void PostToWebKitThread(const tracked_objects::Location& from_here, | 58 virtual void PostToWebKitThread(const tracked_objects::Location& from_here, |
| 60 const base::Closure& task) = 0; | 59 const base::Closure& task) = 0; |
| 61 | 60 |
| 62 // Sends the given message to the browser. Identical semantics to | 61 // Sends the given message to the browser. Identical semantics to |
| 63 // IPC::Message::Sender interface. | 62 // IPC::Message::Sender interface. |
| 64 virtual bool SendToBrowser(IPC::Message* msg) = 0; | 63 virtual bool SendToBrowser(IPC::Message* msg) = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 virtual ~PluginDispatcher(); | 79 virtual ~PluginDispatcher(); |
| 81 | 80 |
| 82 // The plugin side maintains a mapping from PP_Instance to Dispatcher so | 81 // The plugin side maintains a mapping from PP_Instance to Dispatcher so |
| 83 // that we can send the messages to the right channel if there are multiple | 82 // that we can send the messages to the right channel if there are multiple |
| 84 // renderers sharing the same plugin. This mapping is maintained by | 83 // renderers sharing the same plugin. This mapping is maintained by |
| 85 // DidCreateInstance/DidDestroyInstance. | 84 // DidCreateInstance/DidDestroyInstance. |
| 86 static PluginDispatcher* GetForInstance(PP_Instance instance); | 85 static PluginDispatcher* GetForInstance(PP_Instance instance); |
| 87 | 86 |
| 88 // Same as GetForInstance but retrieves the instance from the given resource | 87 // Same as GetForInstance but retrieves the instance from the given resource |
| 89 // object as a convenience. Returns NULL on failure. | 88 // object as a convenience. Returns NULL on failure. |
| 90 static PluginDispatcher* GetForResource(const ppapi::Resource* resource); | 89 static PluginDispatcher* GetForResource(const Resource* resource); |
| 91 | 90 |
| 92 static const void* GetInterfaceFromDispatcher(const char* interface); | 91 static const void* GetInterfaceFromDispatcher(const char* interface); |
| 93 | 92 |
| 94 // You must call this function before anything else. Returns true on success. | 93 // You must call this function before anything else. Returns true on success. |
| 95 // The delegate pointer must outlive this class, ownership is not | 94 // The delegate pointer must outlive this class, ownership is not |
| 96 // transferred. | 95 // transferred. |
| 97 bool InitPluginWithChannel(PluginDelegate* delegate, | 96 bool InitPluginWithChannel(PluginDelegate* delegate, |
| 98 const IPC::ChannelHandle& channel_handle, | 97 const IPC::ChannelHandle& channel_handle, |
| 99 bool is_client); | 98 bool is_client); |
| 100 | 99 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 InstanceData* GetInstanceData(PP_Instance instance); | 115 InstanceData* GetInstanceData(PP_Instance instance); |
| 117 | 116 |
| 118 // Posts the given task to the WebKit thread. | 117 // Posts the given task to the WebKit thread. |
| 119 void PostToWebKitThread(const tracked_objects::Location& from_here, | 118 void PostToWebKitThread(const tracked_objects::Location& from_here, |
| 120 const base::Closure& task); | 119 const base::Closure& task); |
| 121 | 120 |
| 122 // Calls the PluginDelegate.SendToBrowser function. | 121 // Calls the PluginDelegate.SendToBrowser function. |
| 123 bool SendToBrowser(IPC::Message* msg); | 122 bool SendToBrowser(IPC::Message* msg); |
| 124 | 123 |
| 125 // Returns the WebKitForwarding object used to forward events to WebKit. | 124 // Returns the WebKitForwarding object used to forward events to WebKit. |
| 126 ppapi::WebKitForwarding* GetWebKitForwarding(); | 125 WebKitForwarding* GetWebKitForwarding(); |
| 127 | 126 |
| 128 // Returns the Preferences. | 127 // Returns the Preferences. |
| 129 const ppapi::Preferences& preferences() const { return preferences_; } | 128 const Preferences& preferences() const { return preferences_; } |
| 130 | 129 |
| 131 // Returns the "new-style" function API for the given interface ID, creating | 130 // Returns the "new-style" function API for the given interface ID, creating |
| 132 // it if necessary. | 131 // it if necessary. |
| 133 // TODO(brettw) this is in progress. It should be merged with the target | 132 // TODO(brettw) this is in progress. It should be merged with the target |
| 134 // proxies so there is one list to consult. | 133 // proxies so there is one list to consult. |
| 135 ppapi::FunctionGroupBase* GetFunctionAPI( | 134 FunctionGroupBase* GetFunctionAPI(InterfaceID id); |
| 136 pp::proxy::InterfaceID id); | |
| 137 | 135 |
| 138 uint32 plugin_dispatcher_id() const { return plugin_dispatcher_id_; } | 136 uint32 plugin_dispatcher_id() const { return plugin_dispatcher_id_; } |
| 139 | 137 |
| 140 private: | 138 private: |
| 141 friend class PluginDispatcherTest; | 139 friend class PluginDispatcherTest; |
| 142 | 140 |
| 143 // Notifies all live instances that they're now closed. This is used when | 141 // Notifies all live instances that they're now closed. This is used when |
| 144 // a renderer crashes or some other error is received. | 142 // a renderer crashes or some other error is received. |
| 145 void ForceFreeAllInstances(); | 143 void ForceFreeAllInstances(); |
| 146 | 144 |
| 147 // IPC message handlers. | 145 // IPC message handlers. |
| 148 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); | 146 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); |
| 149 void OnMsgSetPreferences(const ::ppapi::Preferences& prefs); | 147 void OnMsgSetPreferences(const Preferences& prefs); |
| 150 | 148 |
| 151 PluginDelegate* plugin_delegate_; | 149 PluginDelegate* plugin_delegate_; |
| 152 | 150 |
| 153 // All target proxies currently created. These are ones that receive | 151 // All target proxies currently created. These are ones that receive |
| 154 // messages. | 152 // messages. |
| 155 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; | 153 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; |
| 156 | 154 |
| 157 // Function proxies created for "new-style" FunctionGroups. | 155 // Function proxies created for "new-style" FunctionGroups. |
| 158 // TODO(brettw) this is in progress. It should be merged with the target | 156 // TODO(brettw) this is in progress. It should be merged with the target |
| 159 // proxies so there is one list to consult. | 157 // proxies so there is one list to consult. |
| 160 scoped_ptr< ::ppapi::FunctionGroupBase > | 158 scoped_ptr<FunctionGroupBase> function_proxies_[INTERFACE_ID_COUNT]; |
| 161 function_proxies_[INTERFACE_ID_COUNT]; | |
| 162 | 159 |
| 163 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; | 160 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; |
| 164 InstanceDataMap instance_map_; | 161 InstanceDataMap instance_map_; |
| 165 | 162 |
| 166 // The preferences sent from the host. We only want to set this once, which | 163 // The preferences sent from the host. We only want to set this once, which |
| 167 // is what the received_preferences_ indicates. See OnMsgSetPreferences. | 164 // is what the received_preferences_ indicates. See OnMsgSetPreferences. |
| 168 bool received_preferences_; | 165 bool received_preferences_; |
| 169 ppapi::Preferences preferences_; | 166 Preferences preferences_; |
| 170 | 167 |
| 171 uint32 plugin_dispatcher_id_; | 168 uint32 plugin_dispatcher_id_; |
| 172 | 169 |
| 173 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); | 170 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); |
| 174 }; | 171 }; |
| 175 | 172 |
| 176 } // namespace proxy | 173 } // namespace proxy |
| 177 } // namespace pp | 174 } // namespace ppapi |
| 178 | 175 |
| 179 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 176 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
| OLD | NEW |