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 #include "chrome/ppapi_plugin/ppapi_thread.h" | 5 #include "chrome/ppapi_plugin/ppapi_thread.h" |
6 | 6 |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "chrome/common/child_process.h" | 8 #include "chrome/common/child_process.h" |
9 #include "ipc/ipc_channel_handle.h" | 9 #include "ipc/ipc_channel_handle.h" |
10 #include "ipc/ipc_sync_channel.h" | 10 #include "ipc/ipc_sync_channel.h" |
11 #include "ppapi/c/ppp.h" | 11 #include "ppapi/c/ppp.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
14 | 14 |
15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
16 #include "base/eintr_wrapper.h" | 16 #include "base/eintr_wrapper.h" |
17 #include "ipc/ipc_channel_posix.h" | 17 #include "ipc/ipc_channel_posix.h" |
18 #endif | 18 #endif |
19 | 19 |
20 PpapiThread::PpapiThread() | 20 PpapiThread::PpapiThread() |
21 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
22 : renderer_fd_(-1) | 22 : renderer_fd_(-1) |
23 #endif | 23 #endif |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
27 PpapiThread::~PpapiThread() { | 27 PpapiThread::~PpapiThread() { |
28 pp::proxy::PluginDispatcher::SetGlobal(NULL); | |
29 } | 28 } |
30 | 29 |
31 // The "regular" ChildThread implements this function and does some standard | 30 // The "regular" ChildThread implements this function and does some standard |
32 // dispatching, then uses the message router. We don't actually need any of | 31 // dispatching, then uses the message router. We don't actually need any of |
33 // this so this function just overrides that one. | 32 // this so this function just overrides that one. |
34 // | 33 // |
35 // Note that this function is called only for messages from the channel to the | 34 // Note that this function is called only for messages from the channel to the |
36 // browser process. Messages from the renderer process are sent via a different | 35 // browser process. Messages from the renderer process are sent via a different |
37 // channel that ends up at Dispatcher::OnMessageReceived. | 36 // channel that ends up at Dispatcher::OnMessageReceived. |
38 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { | 37 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { |
39 IPC_BEGIN_MESSAGE_MAP(PpapiThread, msg) | 38 IPC_BEGIN_MESSAGE_MAP(PpapiThread, msg) |
40 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnMsgLoadPlugin) | 39 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnMsgLoadPlugin) |
41 | |
42 // The rest of the messages go to the dispatcher. | |
43 /*IPC_MESSAGE_UNHANDLED( | |
44 if (dispatcher_.get()) | |
45 dispatcher_->OnMessageReceived(msg) | |
46 )*/ | |
47 IPC_END_MESSAGE_MAP() | 40 IPC_END_MESSAGE_MAP() |
48 return true; | 41 return true; |
49 } | 42 } |
50 | 43 |
51 void PpapiThread::OnMsgLoadPlugin(base::ProcessHandle host_process_handle, | 44 void PpapiThread::OnMsgLoadPlugin(base::ProcessHandle host_process_handle, |
52 const FilePath& path, | 45 const FilePath& path, |
53 int renderer_id) { | 46 int renderer_id) { |
54 IPC::ChannelHandle channel_handle; | 47 IPC::ChannelHandle channel_handle; |
55 if (!LoadPluginLib(host_process_handle, path) || | 48 if (!LoadPluginLib(host_process_handle, path) || |
56 !SetupRendererChannel(renderer_id, &channel_handle)) { | 49 !SetupRendererChannel(renderer_id, &channel_handle)) { |
(...skipping 30 matching lines...) Expand all Loading... |
87 } | 80 } |
88 | 81 |
89 // Get the ShutdownModule function (optional). | 82 // Get the ShutdownModule function (optional). |
90 pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module = | 83 pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module = |
91 reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( | 84 reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( |
92 library.GetFunctionPointer("PPP_ShutdownModule")); | 85 library.GetFunctionPointer("PPP_ShutdownModule")); |
93 | 86 |
94 library_.Reset(library.Release()); | 87 library_.Reset(library.Release()); |
95 dispatcher_.reset(new pp::proxy::PluginDispatcher( | 88 dispatcher_.reset(new pp::proxy::PluginDispatcher( |
96 host_process_handle, get_interface, init_module, shutdown_module)); | 89 host_process_handle, get_interface, init_module, shutdown_module)); |
97 pp::proxy::PluginDispatcher::SetGlobal(dispatcher_.get()); | |
98 return true; | 90 return true; |
99 } | 91 } |
100 | 92 |
101 bool PpapiThread::SetupRendererChannel(int renderer_id, | 93 bool PpapiThread::SetupRendererChannel(int renderer_id, |
102 IPC::ChannelHandle* handle) { | 94 IPC::ChannelHandle* handle) { |
103 IPC::ChannelHandle plugin_handle; | 95 IPC::ChannelHandle plugin_handle; |
104 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(), | 96 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(), |
105 renderer_id); | 97 renderer_id); |
106 if (!dispatcher_->InitWithChannel( | 98 if (!dispatcher_->InitWithChannel( |
107 ChildProcess::current()->io_message_loop(), | 99 ChildProcess::current()->io_message_loop(), |
(...skipping 12 matching lines...) Expand all Loading... |
120 | 112 |
121 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
122 void PpapiThread::CloseRendererFD() { | 114 void PpapiThread::CloseRendererFD() { |
123 if (renderer_fd_ != -1) { | 115 if (renderer_fd_ != -1) { |
124 if (HANDLE_EINTR(close(renderer_fd_)) < 0) | 116 if (HANDLE_EINTR(close(renderer_fd_)) < 0) |
125 PLOG(ERROR) << "close"; | 117 PLOG(ERROR) << "close"; |
126 renderer_fd_ = -1; | 118 renderer_fd_ = -1; |
127 } | 119 } |
128 } | 120 } |
129 #endif | 121 #endif |
OLD | NEW |