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" |
| 6 |
| 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_WIN) |
5 #include <windows.h> | 10 #include <windows.h> |
6 #include <objbase.h> | 11 #include <objbase.h> |
7 | 12 #endif |
8 #include "chrome/plugin/plugin_thread.h" | |
9 | 13 |
10 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/process_util.h" |
11 #include "chrome/common/child_process.h" | 16 #include "chrome/common/child_process.h" |
12 #include "chrome/common/chrome_plugin_lib.h" | 17 #include "chrome/common/chrome_plugin_lib.h" |
13 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
15 #include "chrome/common/plugin_messages.h" | 20 #include "chrome/common/plugin_messages.h" |
16 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
17 #include "chrome/plugin/chrome_plugin_host.h" | 22 #include "chrome/plugin/chrome_plugin_host.h" |
18 #include "chrome/plugin/npobject_util.h" | 23 #include "chrome/plugin/npobject_util.h" |
19 #include "chrome/renderer/render_thread.h" | 24 #include "chrome/renderer/render_thread.h" |
20 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
(...skipping 18 matching lines...) Expand all Loading... |
39 | 44 |
40 void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { | 45 void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { |
41 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) | 46 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) |
42 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) | 47 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) |
43 IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) | 48 IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) |
44 IPC_END_MESSAGE_MAP() | 49 IPC_END_MESSAGE_MAP() |
45 } | 50 } |
46 | 51 |
47 void PluginThread::Init() { | 52 void PluginThread::Init() { |
48 ChildThread::Init(); | 53 ChildThread::Init(); |
| 54 |
49 PatchNPNFunctions(); | 55 PatchNPNFunctions(); |
| 56 #if defined(OS_WIN) |
50 CoInitialize(NULL); | 57 CoInitialize(NULL); |
| 58 #endif |
| 59 |
51 notification_service_.reset(new NotificationService); | 60 notification_service_.reset(new NotificationService); |
52 | 61 |
53 // Preload the library to avoid loading, unloading then reloading | 62 // Preload the library to avoid loading, unloading then reloading |
54 preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_); | 63 preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_); |
55 | 64 |
56 ChromePluginLib::Create(plugin_path_, GetCPBrowserFuncsForPlugin()); | 65 ChromePluginLib::Create(plugin_path_, GetCPBrowserFuncsForPlugin()); |
57 | 66 |
58 scoped_refptr<NPAPI::PluginLib> plugin = | 67 scoped_refptr<NPAPI::PluginLib> plugin = |
59 NPAPI::PluginLib::CreatePluginLib(plugin_path_); | 68 NPAPI::PluginLib::CreatePluginLib(plugin_path_); |
60 if (plugin.get()) { | 69 if (plugin.get()) { |
61 plugin->NP_Initialize(); | 70 plugin->NP_Initialize(); |
62 } | 71 } |
63 | 72 |
64 // Certain plugins, such as flash, steal the unhandled exception filter | 73 // Certain plugins, such as flash, steal the unhandled exception filter |
65 // thus we never get crash reports when they fault. This call fixes it. | 74 // thus we never get crash reports when they fault. This call fixes it. |
66 message_loop()->set_exception_restoration(true); | 75 message_loop()->set_exception_restoration(true); |
67 } | 76 } |
68 | 77 |
69 void PluginThread::CleanUp() { | 78 void PluginThread::CleanUp() { |
70 if (preloaded_plugin_module_) { | 79 if (preloaded_plugin_module_) { |
71 FreeLibrary(preloaded_plugin_module_); | 80 base::UnloadNativeLibrary(preloaded_plugin_module_); |
72 preloaded_plugin_module_ = NULL; | 81 preloaded_plugin_module_ = NULL; |
73 } | 82 } |
74 PluginChannelBase::CleanupChannels(); | 83 PluginChannelBase::CleanupChannels(); |
75 NPAPI::PluginLib::UnloadAllPlugins(); | 84 NPAPI::PluginLib::UnloadAllPlugins(); |
76 ChromePluginLib::UnloadAllPlugins(); | 85 ChromePluginLib::UnloadAllPlugins(); |
77 notification_service_.reset(); | 86 notification_service_.reset(); |
| 87 #if defined(OS_WIN) |
78 CoUninitialize(); | 88 CoUninitialize(); |
| 89 #endif |
79 | 90 |
80 if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) | 91 if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) |
81 TerminateProcess(GetCurrentProcess(), 0); | 92 base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false); |
82 | 93 |
83 // Call this last because it deletes the ResourceDispatcher, which is used | 94 // Call this last because it deletes the ResourceDispatcher, which is used |
84 // in some of the above cleanup. | 95 // in some of the above cleanup. |
85 // See http://code.google.com/p/chromium/issues/detail?id=8980 | 96 // See http://code.google.com/p/chromium/issues/detail?id=8980 |
86 ChildThread::CleanUp(); | 97 ChildThread::CleanUp(); |
87 } | 98 } |
88 | 99 |
89 void PluginThread::OnCreateChannel(bool off_the_record) { | 100 void PluginThread::OnCreateChannel(bool off_the_record) { |
90 std::wstring channel_name; | 101 std::wstring channel_name; |
91 scoped_refptr<PluginChannel> channel = | 102 scoped_refptr<PluginChannel> channel = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (!plugin_thread) | 150 if (!plugin_thread) |
140 return false; | 151 return false; |
141 | 152 |
142 plugin_thread->Send( | 153 plugin_thread->Send( |
143 new PluginProcessHostMsg_GetPluginFinderUrl(plugin_finder_url)); | 154 new PluginProcessHostMsg_GetPluginFinderUrl(plugin_finder_url)); |
144 DCHECK(!plugin_finder_url->empty()); | 155 DCHECK(!plugin_finder_url->empty()); |
145 return true; | 156 return true; |
146 } | 157 } |
147 | 158 |
148 bool IsDefaultPluginEnabled() { | 159 bool IsDefaultPluginEnabled() { |
| 160 #if defined(OS_WIN) |
149 return true; | 161 return true; |
| 162 #else |
| 163 NOTIMPLEMENTED(); |
| 164 return false; |
| 165 #endif |
150 } | 166 } |
151 | 167 |
152 // Dispatch the resolve proxy resquest to the right code, depending on which | 168 // Dispatch the resolve proxy resquest to the right code, depending on which |
153 // process the plugin is running in {renderer, browser, plugin}. | 169 // process the plugin is running in {renderer, browser, plugin}. |
154 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) { | 170 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) { |
155 int net_error; | 171 int net_error; |
156 std::string proxy_result; | 172 std::string proxy_result; |
157 | 173 |
158 bool result; | 174 bool result; |
159 if (IsPluginProcess()) { | 175 if (IsPluginProcess()) { |
160 result = PluginThread::current()->Send( | 176 result = PluginThread::current()->Send( |
161 new PluginProcessHostMsg_ResolveProxy(url, &net_error, &proxy_result)); | 177 new PluginProcessHostMsg_ResolveProxy(url, &net_error, &proxy_result)); |
162 } else { | 178 } else { |
163 result = RenderThread::current()->Send( | 179 result = RenderThread::current()->Send( |
164 new ViewHostMsg_ResolveProxy(url, &net_error, &proxy_result)); | 180 new ViewHostMsg_ResolveProxy(url, &net_error, &proxy_result)); |
165 } | 181 } |
166 | 182 |
167 if (!result || net_error != net::OK) | 183 if (!result || net_error != net::OK) |
168 return false; | 184 return false; |
169 | 185 |
170 *proxy_list = proxy_result; | 186 *proxy_list = proxy_result; |
171 return true; | 187 return true; |
172 } | 188 } |
173 | 189 |
174 } // namespace webkit_glue | 190 } // namespace webkit_glue |
OLD | NEW |