Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: chrome/plugin/plugin_thread.cc

Issue 6576020: Remove Gears from Chrome (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: ready to review Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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(USE_X11) 9 #if defined(USE_X11)
10 #include <gtk/gtk.h> 10 #include <gtk/gtk.h>
11 #elif defined(OS_MACOSX) 11 #elif defined(OS_MACOSX)
12 #include <CoreFoundation/CoreFoundation.h> 12 #include <CoreFoundation/CoreFoundation.h>
13 #endif 13 #endif
14 14
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/lazy_instance.h" 19 #include "base/lazy_instance.h"
20 #include "base/process_util.h" 20 #include "base/process_util.h"
21 #include "base/threading/thread_local.h" 21 #include "base/threading/thread_local.h"
22 #include "chrome/common/child_process.h" 22 #include "chrome/common/child_process.h"
23 #include "chrome/common/chrome_plugin_lib.h"
24 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/plugin_messages.h" 24 #include "chrome/common/plugin_messages.h"
26 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
27 #include "chrome/plugin/chrome_plugin_host.h"
28 #include "chrome/plugin/npobject_util.h" 26 #include "chrome/plugin/npobject_util.h"
29 #include "chrome/renderer/render_thread.h" 27 #include "chrome/renderer/render_thread.h"
30 #include "ipc/ipc_channel_handle.h" 28 #include "ipc/ipc_channel_handle.h"
31 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
32 #include "webkit/glue/webkit_glue.h" 30 #include "webkit/glue/webkit_glue.h"
33 #include "webkit/plugins/npapi/plugin_lib.h" 31 #include "webkit/plugins/npapi/plugin_lib.h"
34 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" 32 #include "webkit/plugins/npapi/webplugin_delegate_impl.h"
35 33
36 #if defined(TOOLKIT_USES_GTK) 34 #if defined(TOOLKIT_USES_GTK)
37 #include "ui/gfx/gtk_util.h" 35 #include "ui/gfx/gtk_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 75 }
78 76
79 ui::SetDefaultX11ErrorHandlers(); 77 ui::SetDefaultX11ErrorHandlers();
80 #endif 78 #endif
81 79
82 PatchNPNFunctions(); 80 PatchNPNFunctions();
83 81
84 // Preload the library to avoid loading, unloading then reloading 82 // Preload the library to avoid loading, unloading then reloading
85 preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_); 83 preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_);
86 84
87 ChromePluginLib::Create(plugin_path_, GetCPBrowserFuncsForPlugin());
88
89 scoped_refptr<webkit::npapi::PluginLib> plugin( 85 scoped_refptr<webkit::npapi::PluginLib> plugin(
90 webkit::npapi::PluginLib::CreatePluginLib(plugin_path_)); 86 webkit::npapi::PluginLib::CreatePluginLib(plugin_path_));
91 if (plugin.get()) { 87 if (plugin.get()) {
92 plugin->NP_Initialize(); 88 plugin->NP_Initialize();
93 89
94 #if defined(OS_MACOSX) 90 #if defined(OS_MACOSX)
95 base::mac::ScopedCFTypeRef<CFStringRef> plugin_name( 91 base::mac::ScopedCFTypeRef<CFStringRef> plugin_name(
96 base::SysUTF16ToCFStringRef(plugin->plugin_info().name)); 92 base::SysUTF16ToCFStringRef(plugin->plugin_info().name));
97 base::mac::ScopedCFTypeRef<CFStringRef> app_name( 93 base::mac::ScopedCFTypeRef<CFStringRef> app_name(
98 base::SysUTF16ToCFStringRef( 94 base::SysUTF16ToCFStringRef(
(...skipping 10 matching lines...) Expand all
109 message_loop()->set_exception_restoration(true); 105 message_loop()->set_exception_restoration(true);
110 } 106 }
111 107
112 PluginThread::~PluginThread() { 108 PluginThread::~PluginThread() {
113 if (preloaded_plugin_module_) { 109 if (preloaded_plugin_module_) {
114 base::UnloadNativeLibrary(preloaded_plugin_module_); 110 base::UnloadNativeLibrary(preloaded_plugin_module_);
115 preloaded_plugin_module_ = NULL; 111 preloaded_plugin_module_ = NULL;
116 } 112 }
117 PluginChannelBase::CleanupChannels(); 113 PluginChannelBase::CleanupChannels();
118 webkit::npapi::PluginLib::UnloadAllPlugins(); 114 webkit::npapi::PluginLib::UnloadAllPlugins();
119 ChromePluginLib::UnloadAllPlugins();
120 115
121 if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) 116 if (webkit_glue::ShouldForcefullyTerminatePluginProcess())
122 base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false); 117 base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false);
123 118
124 lazy_tls.Pointer()->Set(NULL); 119 lazy_tls.Pointer()->Set(NULL);
125 } 120 }
126 121
127 PluginThread* PluginThread::current() { 122 PluginThread* PluginThread::current() {
128 return lazy_tls.Pointer()->Get(); 123 return lazy_tls.Pointer()->Get();
129 } 124 }
130 125
131 bool PluginThread::OnControlMessageReceived(const IPC::Message& msg) { 126 bool PluginThread::OnControlMessageReceived(const IPC::Message& msg) {
132 bool handled = true; 127 bool handled = true;
133 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) 128 IPC_BEGIN_MESSAGE_MAP(PluginThread, msg)
134 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) 129 IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel)
135 IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage)
136 IPC_MESSAGE_HANDLER(PluginProcessMsg_NotifyRenderersOfPendingShutdown, 130 IPC_MESSAGE_HANDLER(PluginProcessMsg_NotifyRenderersOfPendingShutdown,
137 OnNotifyRenderersOfPendingShutdown) 131 OnNotifyRenderersOfPendingShutdown)
138 IPC_MESSAGE_UNHANDLED(handled = false) 132 IPC_MESSAGE_UNHANDLED(handled = false)
139 IPC_END_MESSAGE_MAP() 133 IPC_END_MESSAGE_MAP()
140 return handled; 134 return handled;
141 } 135 }
142 136
143 void PluginThread::OnCreateChannel(int renderer_id, 137 void PluginThread::OnCreateChannel(int renderer_id,
144 bool off_the_record) { 138 bool off_the_record) {
145 scoped_refptr<PluginChannel> channel(PluginChannel::GetPluginChannel( 139 scoped_refptr<PluginChannel> channel(PluginChannel::GetPluginChannel(
146 renderer_id, ChildProcess::current()->io_message_loop())); 140 renderer_id, ChildProcess::current()->io_message_loop()));
147 IPC::ChannelHandle channel_handle; 141 IPC::ChannelHandle channel_handle;
148 if (channel.get()) { 142 if (channel.get()) {
149 channel_handle.name = channel->channel_handle().name; 143 channel_handle.name = channel->channel_handle().name;
150 #if defined(OS_POSIX) 144 #if defined(OS_POSIX)
151 // On POSIX, pass the renderer-side FD. 145 // On POSIX, pass the renderer-side FD.
152 channel_handle.socket = base::FileDescriptor(channel->renderer_fd(), false); 146 channel_handle.socket = base::FileDescriptor(channel->renderer_fd(), false);
153 #endif 147 #endif
154 channel->set_off_the_record(off_the_record); 148 channel->set_off_the_record(off_the_record);
155 } 149 }
156 150
157 Send(new PluginProcessHostMsg_ChannelCreated(channel_handle)); 151 Send(new PluginProcessHostMsg_ChannelCreated(channel_handle));
158 } 152 }
159 153
160 void PluginThread::OnPluginMessage(const std::vector<unsigned char> &data) {
161 // We Add/Release ref here to ensure that something will trigger the
162 // shutdown mechanism for processes started in the absence of renderer's
163 // opening a plugin channel.
164 ChildProcess::current()->AddRefProcess();
165 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path_);
166 if (chrome_plugin) {
167 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0]));
168 uint32 data_len = static_cast<uint32>(data.size());
169 chrome_plugin->functions().on_message(data_ptr, data_len);
170 }
171 ChildProcess::current()->ReleaseProcess();
172 }
173
174 void PluginThread::OnNotifyRenderersOfPendingShutdown() { 154 void PluginThread::OnNotifyRenderersOfPendingShutdown() {
175 PluginChannel::NotifyRenderersOfPendingShutdown(); 155 PluginChannel::NotifyRenderersOfPendingShutdown();
176 } 156 }
177 157
178 namespace webkit_glue { 158 namespace webkit_glue {
179 159
180 #if defined(OS_WIN) 160 #if defined(OS_WIN)
181 bool DownloadUrl(const std::string& url, HWND caller_window) { 161 bool DownloadUrl(const std::string& url, HWND caller_window) {
182 PluginThread* plugin_thread = PluginThread::current(); 162 PluginThread* plugin_thread = PluginThread::current();
183 if (!plugin_thread) { 163 if (!plugin_thread) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 209 }
230 210
231 if (!result || net_error != net::OK) 211 if (!result || net_error != net::OK)
232 return false; 212 return false;
233 213
234 *proxy_list = proxy_result; 214 *proxy_list = proxy_result;
235 return true; 215 return true;
236 } 216 }
237 217
238 } // namespace webkit_glue 218 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698