diff options
Diffstat (limited to 'chrome/plugin/plugin_thread.cc')
-rw-r--r-- | chrome/plugin/plugin_thread.cc | 146 |
1 files changed, 52 insertions, 94 deletions
diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index d37edf4..671e977 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -7,84 +7,63 @@ #include "chrome/plugin/plugin_thread.h" +#include "base/command_line.h" #include "chrome/common/chrome_plugin_lib.h" -#include "chrome/common/ipc_logging.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/plugin_messages.h" +#include "chrome/common/render_messages.h" #include "chrome/plugin/chrome_plugin_host.h" #include "chrome/plugin/npobject_util.h" #include "chrome/plugin/plugin_process.h" +#include "chrome/renderer/render_thread.h" #include "net/base/net_errors.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/webkit_glue.h" -PluginThread* PluginThread::plugin_thread_; - -PluginThread::PluginThread(PluginProcess* process, - const std::wstring& channel_name) - : plugin_process_(process), - channel_name_(channel_name), - owner_loop_(MessageLoop::current()), - preloaded_plugin_module_(NULL), - Thread("Chrome_PluginThread") { - DCHECK(plugin_process_); - DCHECK(owner_loop_); - DCHECK(!plugin_thread_); - plugin_thread_ = this; - - // We need to run a UI message loop to support plugin execution. - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_UI; - StartWithOptions(options); + +PluginThread::PluginThread() + : ChildThread(base::Thread::Options(MessageLoop::TYPE_UI, 0)), + preloaded_plugin_module_(NULL) { + plugin_path_ = FilePath::FromWStringHack( + CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kPluginPath)); } PluginThread::~PluginThread() { - Stop(); - plugin_thread_ = NULL; } -void PluginThread::OnChannelError() { - owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); +PluginThread* PluginThread::current() { + DCHECK(IsPluginProcess()); + return static_cast<PluginThread*>(ChildThread::current()); } -bool PluginThread::Send(IPC::Message* msg) { - return channel_.get() ? channel_->Send(msg) : false; -} +void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { + // Resource responses are sent to the resource dispatcher. + if (resource_dispatcher_->OnMessageReceived(msg)) + return; -void PluginThread::OnMessageReceived(const IPC::Message& msg) { - if (msg.routing_id() == MSG_ROUTING_CONTROL) { - // Resource responses are sent to the resource dispatcher. - if (resource_dispatcher_->OnMessageReceived(msg)) - return; - IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) - IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) - IPC_MESSAGE_HANDLER(PluginProcessMsg_ShutdownResponse, OnShutdownResponse) - IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) - IPC_MESSAGE_HANDLER(PluginProcessMsg_BrowserShutdown, OnBrowserShutdown) - IPC_END_MESSAGE_MAP() - } else { - NOTREACHED() << "Only control messages should reach PluginThread."; - } + IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) + IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) + IPC_MESSAGE_HANDLER(PluginProcessMsg_ShutdownResponse, OnShutdownResponse) + IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) + IPC_MESSAGE_HANDLER(PluginProcessMsg_BrowserShutdown, OnBrowserShutdown) + IPC_END_MESSAGE_MAP() } void PluginThread::Init() { + ChildThread::Init(); PatchNPNFunctions(); CoInitialize(NULL); - channel_.reset(new IPC::SyncChannel(channel_name_, - IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true, - PluginProcess::GetShutDownEvent())); notification_service_.reset(new NotificationService); resource_dispatcher_ = new ResourceDispatcher(this); // Preload the library to avoid loading, unloading then reloading - preloaded_plugin_module_ = NPAPI::PluginLib::LoadNativeLibrary( - plugin_process_->plugin_path()); + preloaded_plugin_module_ = NPAPI::PluginLib::LoadNativeLibrary(plugin_path_); - ChromePluginLib::Create(plugin_process_->plugin_path(), - GetCPBrowserFuncsForPlugin()); + ChromePluginLib::Create(plugin_path_, GetCPBrowserFuncsForPlugin()); scoped_refptr<NPAPI::PluginLib> plugin = - NPAPI::PluginLib::CreatePluginLib(plugin_process_->plugin_path()); + NPAPI::PluginLib::CreatePluginLib(plugin_path_); if (plugin.get()) { plugin->NP_Initialize(); } @@ -92,23 +71,14 @@ void PluginThread::Init() { // Certain plugins, such as flash, steal the unhandled exception filter // thus we never get crash reports when they fault. This call fixes it. message_loop()->set_exception_restoration(true); - -#ifdef IPC_MESSAGE_LOG_ENABLED - IPC::Logging::current()->SetIPCSender(this); -#endif } void PluginThread::CleanUp() { -#ifdef IPC_MESSAGE_LOG_ENABLED - IPC::Logging::current()->SetIPCSender(NULL); -#endif + ChildThread::CleanUp(); if (preloaded_plugin_module_) { FreeLibrary(preloaded_plugin_module_); preloaded_plugin_module_ = NULL; } - // Need to destruct the SyncChannel to the browser before we go away because - // it caches a pointer to this thread. - channel_.reset(); PluginChannelBase::CleanupChannels(); NPAPI::PluginLib::UnloadAllPlugins(); ChromePluginLib::UnloadAllPlugins(); @@ -118,13 +88,12 @@ void PluginThread::CleanUp() { if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) TerminateProcess(GetCurrentProcess(), 0); - } -void PluginThread::OnCreateChannel(int process_id, HANDLE renderer_handle) { +void PluginThread::OnCreateChannel(int process_id, HANDLE renderer) { std::wstring channel_name; scoped_refptr<PluginChannel> channel = - PluginChannel::GetPluginChannel(process_id, renderer_handle, owner_loop_); + PluginChannel::GetPluginChannel(process_id, renderer, owner_loop()); if (channel.get()) channel_name = channel->channel_name(); @@ -132,32 +101,32 @@ void PluginThread::OnCreateChannel(int process_id, HANDLE renderer_handle) { } void PluginThread::OnShutdownResponse(bool ok_to_shutdown) { - PluginProcess::ShutdownProcessResponse(ok_to_shutdown); + if (ok_to_shutdown) + PluginProcess::current()->Shutdown(); } void PluginThread::OnBrowserShutdown() { - PluginProcess::BrowserShutdown(); + PluginProcess::current()->Shutdown(); } void PluginThread::OnPluginMessage(const std::vector<unsigned char> &data) { // We Add/Release ref here to ensure that something will trigger the // shutdown mechanism for processes started in the absence of renderer's // opening a plugin channel. - PluginProcess::AddRefProcess(); - ChromePluginLib *chrome_plugin = - ChromePluginLib::Find(plugin_process_->plugin_path()); + PluginProcess::current()->AddRefProcess(); + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path_); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); chrome_plugin->functions().on_message(data_ptr, data_len); } - PluginProcess::ReleaseProcess(); + PluginProcess::current()->ReleaseProcess(); } namespace webkit_glue { bool DownloadUrl(const std::string& url, HWND caller_window) { - PluginThread* plugin_thread = PluginThread::GetPluginThread(); + PluginThread* plugin_thread = PluginThread::current(); if (!plugin_thread) { return false; } @@ -175,10 +144,9 @@ bool GetPluginFinderURL(std::string* plugin_finder_url) { return false; } - PluginThread* plugin_thread = PluginThread::GetPluginThread(); - if (!plugin_thread) { + PluginThread* plugin_thread = PluginThread::current(); + if (!plugin_thread) return false; - } plugin_thread->Send( new PluginProcessHostMsg_GetPluginFinderUrl(plugin_finder_url)); @@ -190,36 +158,26 @@ bool IsDefaultPluginEnabled() { return true; } -static int ResolveProxyFromPluginThread(const GURL& url, - std::string* proxy_result) { - int net_error; - bool ipc_ok = PluginThread::GetPluginThread()->Send( - new PluginProcessHostMsg_ResolveProxy(url, &net_error, proxy_result)); - return ipc_ok ? net_error : net::ERR_UNEXPECTED; -} - -extern int ResolveProxyFromRenderThread(const GURL&, std::string*); // Dispatch the resolve proxy resquest to the right code, depending on which // process the plugin is running in {renderer, browser, plugin}. -// -// TODO(eroman): Find a better place to put this; plugin_thread.cc isn't really -// correct since this depends on the renderer thread. One solution is to save -// the function pointers into a table during initialization. bool FindProxyForUrl(const GURL& url, std::string* proxy_list) { int net_error; std::string proxy_result; - if (PluginThread::GetPluginThread()) - net_error = ResolveProxyFromPluginThread(url, &proxy_result); - else - net_error = ResolveProxyFromRenderThread(url, &proxy_result); - - if (net_error == net::OK) { - *proxy_list = proxy_result; - return true; // Success. + bool result; + if (IsPluginProcess()) { + result = PluginThread::current()->Send( + new PluginProcessHostMsg_ResolveProxy(url, &net_error, &proxy_result)); + } else { + result = RenderThread::current()->Send( + new ViewHostMsg_ResolveProxy(url, &net_error, &proxy_result)); } - return false; // Fail. + + if (!result || net_error != net::OK) + return false; + + *proxy_list = proxy_result; + return true; } } // namespace webkit_glue - |