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

Side by Side Diff: content/browser/plugin_process_host.cc

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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) 2011 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 "content/browser/plugin_process_host.h" 5 #include "content/browser/plugin_process_host.h"
6 6
7 #if defined(OS_WIN) && !defined(USE_AURA) 7 #if defined(OS_WIN) && !defined(USE_AURA)
8 #include <windows.h> 8 #include <windows.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <utility> // for pair<> 10 #include <utility> // for pair<>
11 #endif 11 #endif
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/base_switches.h" 15 #include "base/base_switches.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/file_path.h" 18 #include "base/file_path.h"
19 #include "base/file_util.h" 19 #include "base/file_util.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "content/browser/plugin_service.h" 24 #include "content/browser/plugin_service.h"
25 #include "content/common/child_process_host.h"
25 #include "content/common/plugin_messages.h" 26 #include "content/common/plugin_messages.h"
26 #include "content/common/resource_messages.h" 27 #include "content/common/resource_messages.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/content_browser_client.h" 29 #include "content/public/browser/content_browser_client.h"
29 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
30 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
31 #include "content/public/common/process_type.h" 32 #include "content/public/common/process_type.h"
32 #include "ipc/ipc_switches.h" 33 #include "ipc/ipc_switches.h"
33 #include "ui/base/ui_base_switches.h" 34 #include "ui/base/ui_base_switches.h"
34 #include "ui/gfx/gl/gl_switches.h" 35 #include "ui/gfx/gl/gl_switches.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return; 79 return;
79 80
80 plugin_parent_windows_set_.erase(window_index); 81 plugin_parent_windows_set_.erase(window_index);
81 PostMessage(parent, WM_CLOSE, 0, 0); 82 PostMessage(parent, WM_CLOSE, 0, 0);
82 } 83 }
83 84
84 void PluginProcessHost::AddWindow(HWND window) { 85 void PluginProcessHost::AddWindow(HWND window) {
85 plugin_parent_windows_set_.insert(window); 86 plugin_parent_windows_set_.insert(window);
86 } 87 }
87 88
89 void PluginProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
90 child_process_host()->AddFilter(filter);
91 }
92
88 void PluginProcessHost::OnReparentPluginWindow(HWND window, HWND parent) { 93 void PluginProcessHost::OnReparentPluginWindow(HWND window, HWND parent) {
89 // Reparent only from the plugin process to our process. 94 // Reparent only from the plugin process to our process.
90 DWORD process_id = 0; 95 DWORD process_id = 0;
91 ::GetWindowThreadProcessId(window, &process_id); 96 ::GetWindowThreadProcessId(window, &process_id);
92 if (process_id != ::GetProcessId(GetChildProcessHandle())) 97 if (process_id != ::GetProcessId(GetChildProcessHandle()))
93 return; 98 return;
94 ::GetWindowThreadProcessId(parent, &process_id); 99 ::GetWindowThreadProcessId(parent, &process_id);
95 if (process_id != ::GetCurrentProcessId()) 100 if (process_id != ::GetCurrentProcessId())
96 return; 101 return;
97 102
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #endif 165 #endif
161 // Cancel all pending and sent requests. 166 // Cancel all pending and sent requests.
162 CancelRequests(); 167 CancelRequests();
163 } 168 }
164 169
165 bool PluginProcessHost::Init(const webkit::WebPluginInfo& info, 170 bool PluginProcessHost::Init(const webkit::WebPluginInfo& info,
166 const std::string& locale) { 171 const std::string& locale) {
167 info_ = info; 172 info_ = info;
168 set_name(info_.name); 173 set_name(info_.name);
169 174
170 if (!CreateChannel()) 175 if (!child_process_host()->CreateChannel())
171 return false; 176 return false;
172 177
173 // Build command line for plugin. When we have a plugin launcher, we can't 178 // Build command line for plugin. When we have a plugin launcher, we can't
174 // allow "self" on linux and we need the real file path. 179 // allow "self" on linux and we need the real file path.
175 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 180 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
176 CommandLine::StringType plugin_launcher = 181 CommandLine::StringType plugin_launcher =
177 browser_command_line.GetSwitchValueNative(switches::kPluginLauncher); 182 browser_command_line.GetSwitchValueNative(switches::kPluginLauncher);
178 183
179 #if defined(OS_MACOSX) 184 #if defined(OS_MACOSX)
180 // Run the plug-in process in a mode tolerant of heap execution without 185 // Run the plug-in process in a mode tolerant of heap execution without
181 // explicit mprotect calls. Some plug-ins still rely on this quaint and 186 // explicit mprotect calls. Some plug-ins still rely on this quaint and
182 // archaic "feature." See http://crbug.com/93551. 187 // archaic "feature." See http://crbug.com/93551.
183 int flags = CHILD_ALLOW_HEAP_EXECUTION; 188 int flags = CHILD_ALLOW_HEAP_EXECUTION;
184 #elif defined(OS_LINUX) 189 #elif defined(OS_LINUX)
185 int flags = plugin_launcher.empty() ? CHILD_ALLOW_SELF : CHILD_NORMAL; 190 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF :
191 ChildProcessHost::CHILD_NORMAL;
186 #else 192 #else
187 int flags = CHILD_NORMAL; 193 int flags = ChildProcessHost::CHILD_NORMAL;
188 #endif 194 #endif
189 195
190 FilePath exe_path = GetChildPath(flags); 196 FilePath exe_path = ChildProcessHost::GetChildPath(flags);
191 if (exe_path.empty()) 197 if (exe_path.empty())
192 return false; 198 return false;
193 199
194 CommandLine* cmd_line = new CommandLine(exe_path); 200 CommandLine* cmd_line = new CommandLine(exe_path);
195 // Put the process type and plugin path first so they're easier to see 201 // Put the process type and plugin path first so they're easier to see
196 // in process listings using native process management tools. 202 // in process listings using native process management tools.
197 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kPluginProcess); 203 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kPluginProcess);
198 cmd_line->AppendSwitchPath(switches::kPluginPath, info.path); 204 cmd_line->AppendSwitchPath(switches::kPluginPath, info.path);
199 205
200 // Propagate the following switches to the plugin command line (along with 206 // Propagate the following switches to the plugin command line (along with
(...skipping 25 matching lines...) Expand all
226 // If specified, prepend a launcher program to the command line. 232 // If specified, prepend a launcher program to the command line.
227 if (!plugin_launcher.empty()) 233 if (!plugin_launcher.empty())
228 cmd_line->PrependWrapper(plugin_launcher); 234 cmd_line->PrependWrapper(plugin_launcher);
229 235
230 if (!locale.empty()) { 236 if (!locale.empty()) {
231 // Pass on the locale so the null plugin will use the right language in the 237 // Pass on the locale so the null plugin will use the right language in the
232 // prompt to install the desired plugin. 238 // prompt to install the desired plugin.
233 cmd_line->AppendSwitchASCII(switches::kLang, locale); 239 cmd_line->AppendSwitchASCII(switches::kLang, locale);
234 } 240 }
235 241
236 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); 242 cmd_line->AppendSwitchASCII(switches::kProcessChannelID,
243 child_process_host()->channel_id());
237 244
238 #if defined(OS_POSIX) 245 #if defined(OS_POSIX)
239 base::environment_vector env; 246 base::environment_vector env;
240 #if defined(OS_MACOSX) && !defined(__LP64__) 247 #if defined(OS_MACOSX) && !defined(__LP64__)
241 // Add our interposing library for Carbon. This is stripped back out in 248 // Add our interposing library for Carbon. This is stripped back out in
242 // plugin_main.cc, so changes here should be reflected there. 249 // plugin_main.cc, so changes here should be reflected there.
243 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath); 250 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath);
244 const char* existing_list = 251 const char* existing_list =
245 getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey); 252 getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey);
246 if (existing_list) { 253 if (existing_list) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 host->pending_requests_.erase(host->pending_requests_.begin() + i); 359 host->pending_requests_.erase(host->pending_requests_.begin() + i);
353 --i; 360 --i;
354 } 361 }
355 } 362 }
356 } 363 }
357 } 364 }
358 365
359 void PluginProcessHost::OpenChannelToPlugin(Client* client) { 366 void PluginProcessHost::OpenChannelToPlugin(Client* client) {
360 Notify(content::NOTIFICATION_CHILD_INSTANCE_CREATED); 367 Notify(content::NOTIFICATION_CHILD_INSTANCE_CREATED);
361 client->SetPluginInfo(info_); 368 client->SetPluginInfo(info_);
362 if (opening_channel()) { 369 if (child_process_host()->opening_channel()) {
363 // The channel is already in the process of being opened. Put 370 // The channel is already in the process of being opened. Put
364 // this "open channel" request into a queue of requests that will 371 // this "open channel" request into a queue of requests that will
365 // be run once the channel is open. 372 // be run once the channel is open.
366 pending_requests_.push_back(client); 373 pending_requests_.push_back(client);
367 return; 374 return;
368 } 375 }
369 376
370 // We already have an open channel, send a request right away to plugin. 377 // We already have an open channel, send a request right away to plugin.
371 RequestPluginChannel(client); 378 RequestPluginChannel(client);
372 } 379 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 422 }
416 423
417 void PluginProcessHost::OnChannelCreated( 424 void PluginProcessHost::OnChannelCreated(
418 const IPC::ChannelHandle& channel_handle) { 425 const IPC::ChannelHandle& channel_handle) {
419 Client* client = sent_requests_.front(); 426 Client* client = sent_requests_.front();
420 427
421 if (client) 428 if (client)
422 client->OnChannelOpened(channel_handle); 429 client->OnChannelOpened(channel_handle);
423 sent_requests_.pop_front(); 430 sent_requests_.pop_front();
424 } 431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698