| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/plugin/plugin_thread.h" | 5 #include "chrome/plugin/plugin_thread.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <objbase.h> | 11 #include <objbase.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/lazy_instance.h" |
| 15 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 17 #include "base/thread_local.h" |
| 16 #include "chrome/common/child_process.h" | 18 #include "chrome/common/child_process.h" |
| 17 #include "chrome/common/chrome_plugin_lib.h" | 19 #include "chrome/common/chrome_plugin_lib.h" |
| 18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/plugin_messages.h" | 22 #include "chrome/common/plugin_messages.h" |
| 21 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| 22 #include "chrome/plugin/chrome_plugin_host.h" | 24 #include "chrome/plugin/chrome_plugin_host.h" |
| 23 #include "chrome/plugin/npobject_util.h" | 25 #include "chrome/plugin/npobject_util.h" |
| 24 #include "chrome/renderer/render_thread.h" | 26 #include "chrome/renderer/render_thread.h" |
| 25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 26 #include "webkit/glue/plugins/plugin_lib.h" | 28 #include "webkit/glue/plugins/plugin_lib.h" |
| 27 #include "webkit/glue/webkit_glue.h" | 29 #include "webkit/glue/webkit_glue.h" |
| 28 | 30 |
| 31 static base::LazyInstance<base::ThreadLocalPointer<PluginThread> > lazy_tls( |
| 32 base::LINKER_INITIALIZED); |
| 29 | 33 |
| 30 PluginThread::PluginThread() | 34 PluginThread::PluginThread() |
| 31 : ChildThread(base::Thread::Options(MessageLoop::TYPE_UI, 0)), | 35 : ChildThread(base::Thread::Options(MessageLoop::TYPE_UI, 0)), |
| 32 preloaded_plugin_module_(NULL) { | 36 preloaded_plugin_module_(NULL) { |
| 33 plugin_path_ = FilePath::FromWStringHack( | 37 plugin_path_ = FilePath::FromWStringHack( |
| 34 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kPluginPath)); | 38 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kPluginPath)); |
| 35 } | 39 } |
| 36 | 40 |
| 37 PluginThread::~PluginThread() { | 41 PluginThread::~PluginThread() { |
| 38 } | 42 } |
| 39 | 43 |
| 40 PluginThread* PluginThread::current() { | 44 PluginThread* PluginThread::current() { |
| 41 DCHECK(IsPluginProcess()); | 45 return lazy_tls.Pointer()->Get(); |
| 42 return static_cast<PluginThread*>(ChildThread::current()); | |
| 43 } | 46 } |
| 44 | 47 |
| 45 void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { | 48 void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { |
| 46 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) | 49 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) |
| 47 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) | 50 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) |
| 48 IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) | 51 IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) |
| 49 IPC_END_MESSAGE_MAP() | 52 IPC_END_MESSAGE_MAP() |
| 50 } | 53 } |
| 51 | 54 |
| 52 void PluginThread::Init() { | 55 void PluginThread::Init() { |
| 56 lazy_tls.Pointer()->Set(this); |
| 53 ChildThread::Init(); | 57 ChildThread::Init(); |
| 54 | 58 |
| 55 PatchNPNFunctions(); | 59 PatchNPNFunctions(); |
| 56 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 57 CoInitialize(NULL); | 61 CoInitialize(NULL); |
| 58 #endif | 62 #endif |
| 59 | 63 |
| 60 notification_service_.reset(new NotificationService); | 64 notification_service_.reset(new NotificationService); |
| 61 | 65 |
| 62 // Preload the library to avoid loading, unloading then reloading | 66 // Preload the library to avoid loading, unloading then reloading |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 CoUninitialize(); | 92 CoUninitialize(); |
| 89 #endif | 93 #endif |
| 90 | 94 |
| 91 if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) | 95 if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) |
| 92 base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false); | 96 base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false); |
| 93 | 97 |
| 94 // Call this last because it deletes the ResourceDispatcher, which is used | 98 // Call this last because it deletes the ResourceDispatcher, which is used |
| 95 // in some of the above cleanup. | 99 // in some of the above cleanup. |
| 96 // See http://code.google.com/p/chromium/issues/detail?id=8980 | 100 // See http://code.google.com/p/chromium/issues/detail?id=8980 |
| 97 ChildThread::CleanUp(); | 101 ChildThread::CleanUp(); |
| 102 lazy_tls.Pointer()->Set(NULL); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void PluginThread::OnCreateChannel(int process_id, bool off_the_record) { | 105 void PluginThread::OnCreateChannel(int process_id, bool off_the_record) { |
| 101 std::string channel_name; | 106 std::string channel_name; |
| 102 scoped_refptr<PluginChannel> channel = | 107 scoped_refptr<PluginChannel> channel = |
| 103 PluginChannel::GetPluginChannel(process_id, owner_loop()); | 108 PluginChannel::GetPluginChannel(process_id, owner_loop()); |
| 104 if (channel.get()) { | 109 if (channel.get()) { |
| 105 channel_name = channel->channel_name(); | 110 channel_name = channel->channel_name(); |
| 106 channel->set_off_the_record(off_the_record); | 111 channel->set_off_the_record(off_the_record); |
| 107 } | 112 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 189 } |
| 185 | 190 |
| 186 if (!result || net_error != net::OK) | 191 if (!result || net_error != net::OK) |
| 187 return false; | 192 return false; |
| 188 | 193 |
| 189 *proxy_list = proxy_result; | 194 *proxy_list = proxy_result; |
| 190 return true; | 195 return true; |
| 191 } | 196 } |
| 192 | 197 |
| 193 } // namespace webkit_glue | 198 } // namespace webkit_glue |
| OLD | NEW |