| 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 CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ | 5 #ifndef CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ |
| 6 #define CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ | 6 #define CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/scoped_native_library.h" | 15 #include "base/scoped_native_library.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "content/common/child_thread.h" | 17 #include "content/common/child_thread.h" |
| 18 #include "ppapi/c/pp_module.h" | 18 #include "ppapi/c/pp_module.h" |
| 19 #include "ppapi/c/trusted/ppp_broker.h" | 19 #include "ppapi/c/trusted/ppp_broker.h" |
| 20 #include "ppapi/proxy/plugin_dispatcher.h" | 20 #include "ppapi/proxy/plugin_dispatcher.h" |
| 21 | 21 |
| 22 class FilePath; | 22 class FilePath; |
| 23 class PpapiWebKitThread; | 23 class PpapiWebKitThread; |
| 24 | 24 |
| 25 namespace IPC { | 25 namespace IPC { |
| 26 struct ChannelHandle; | 26 struct ChannelHandle; |
| 27 } | 27 } |
| 28 | 28 |
| 29 class PpapiThread : public ChildThread, | 29 class PpapiThread : public ChildThread, |
| 30 public pp::proxy::PluginDispatcher::PluginDelegate { | 30 public ppapi::proxy::PluginDispatcher::PluginDelegate { |
| 31 public: | 31 public: |
| 32 explicit PpapiThread(bool is_broker); | 32 explicit PpapiThread(bool is_broker); |
| 33 virtual ~PpapiThread(); | 33 virtual ~PpapiThread(); |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // ChildThread overrides. | 36 // ChildThread overrides. |
| 37 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 37 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 38 | 38 |
| 39 // Dispatcher::Delegate implementation. | 39 // Dispatcher::Delegate implementation. |
| 40 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; | 40 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; |
| 41 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; | 41 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; |
| 42 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; | 42 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; |
| 43 virtual ppapi::WebKitForwarding* GetWebKitForwarding() OVERRIDE; | 43 virtual ppapi::WebKitForwarding* GetWebKitForwarding() OVERRIDE; |
| 44 virtual void PostToWebKitThread(const tracked_objects::Location& from_here, | 44 virtual void PostToWebKitThread(const tracked_objects::Location& from_here, |
| 45 const base::Closure& task) OVERRIDE; | 45 const base::Closure& task) OVERRIDE; |
| 46 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE; | 46 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE; |
| 47 virtual uint32 Register( | 47 virtual uint32 Register( |
| 48 pp::proxy::PluginDispatcher* plugin_dispatcher) OVERRIDE; | 48 ppapi::proxy::PluginDispatcher* plugin_dispatcher) OVERRIDE; |
| 49 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; | 49 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; |
| 50 | 50 |
| 51 // Message handlers. | 51 // Message handlers. |
| 52 void OnMsgLoadPlugin(const FilePath& path); | 52 void OnMsgLoadPlugin(const FilePath& path); |
| 53 void OnMsgCreateChannel(base::ProcessHandle host_process_handle, | 53 void OnMsgCreateChannel(base::ProcessHandle host_process_handle, |
| 54 int renderer_id); | 54 int renderer_id); |
| 55 void OnMsgSetNetworkState(bool online); | 55 void OnMsgSetNetworkState(bool online); |
| 56 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 56 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
| 57 | 57 |
| 58 // Sets up the channel to the given renderer. On success, returns true and | 58 // Sets up the channel to the given renderer. On success, returns true and |
| 59 // fills the given ChannelHandle with the information from the new channel. | 59 // fills the given ChannelHandle with the information from the new channel. |
| 60 bool SetupRendererChannel(base::ProcessHandle host_process_handle, | 60 bool SetupRendererChannel(base::ProcessHandle host_process_handle, |
| 61 int renderer_id, | 61 int renderer_id, |
| 62 IPC::ChannelHandle* handle); | 62 IPC::ChannelHandle* handle); |
| 63 | 63 |
| 64 // True if running in a broker process rather than a normal plugin process. | 64 // True if running in a broker process rather than a normal plugin process. |
| 65 bool is_broker_; | 65 bool is_broker_; |
| 66 | 66 |
| 67 base::ScopedNativeLibrary library_; | 67 base::ScopedNativeLibrary library_; |
| 68 | 68 |
| 69 pp::proxy::Dispatcher::GetInterfaceFunc get_plugin_interface_; | 69 ppapi::proxy::Dispatcher::GetInterfaceFunc get_plugin_interface_; |
| 70 | 70 |
| 71 // Callback to call when a new instance connects to the broker. | 71 // Callback to call when a new instance connects to the broker. |
| 72 // Used only when is_broker_. | 72 // Used only when is_broker_. |
| 73 PP_ConnectInstance_Func connect_instance_func_; | 73 PP_ConnectInstance_Func connect_instance_func_; |
| 74 | 74 |
| 75 // Local concept of the module ID. Some functions take this. It's necessary | 75 // Local concept of the module ID. Some functions take this. It's necessary |
| 76 // for the in-process PPAPI to handle this properly, but for proxied it's | 76 // for the in-process PPAPI to handle this properly, but for proxied it's |
| 77 // unnecessary. The proxy talking to multiple renderers means that each | 77 // unnecessary. The proxy talking to multiple renderers means that each |
| 78 // renderer has a different idea of what the module ID is for this plugin. | 78 // renderer has a different idea of what the module ID is for this plugin. |
| 79 // To force people to "do the right thing" we generate a random module ID | 79 // To force people to "do the right thing" we generate a random module ID |
| 80 // and pass it around as necessary. | 80 // and pass it around as necessary. |
| 81 PP_Module local_pp_module_; | 81 PP_Module local_pp_module_; |
| 82 | 82 |
| 83 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet. | 83 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet. |
| 84 std::set<PP_Instance> globally_seen_instance_ids_; | 84 std::set<PP_Instance> globally_seen_instance_ids_; |
| 85 | 85 |
| 86 // Lazily created by GetWebKitForwarding. | 86 // Lazily created by GetWebKitForwarding. |
| 87 scoped_ptr<ppapi::WebKitForwarding> webkit_forwarding_; | 87 scoped_ptr<ppapi::WebKitForwarding> webkit_forwarding_; |
| 88 | 88 |
| 89 scoped_ptr<PpapiWebKitThread> webkit_thread_; | 89 scoped_ptr<PpapiWebKitThread> webkit_thread_; |
| 90 | 90 |
| 91 // The PluginDispatcher instances contained in the map are not owned by it. | 91 // The PluginDispatcher instances contained in the map are not owned by it. |
| 92 std::map<uint32, pp::proxy::PluginDispatcher*> plugin_dispatchers_; | 92 std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_; |
| 93 uint32 next_plugin_dispatcher_id_; | 93 uint32 next_plugin_dispatcher_id_; |
| 94 | 94 |
| 95 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread); | 95 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ | 98 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ |
| OLD | NEW |