OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ppapi_plugin_process_host.h" | 5 #include "content/browser/ppapi_plugin_process_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "content/browser/browser_child_process_host_impl.h" | 20 #include "content/browser/browser_child_process_host_impl.h" |
21 #include "content/browser/plugin_service_impl.h" | 21 #include "content/browser/plugin_service_impl.h" |
22 #include "content/browser/renderer_host/render_message_filter.h" | 22 #include "content/browser/renderer_host/render_message_filter.h" |
23 #include "content/common/child_process_host_impl.h" | 23 #include "content/common/child_process_host_impl.h" |
24 #include "content/common/child_process_messages.h" | 24 #include "content/common/child_process_messages.h" |
25 #include "content/common/content_switches_internal.h" | 25 #include "content/common/content_switches_internal.h" |
| 26 #include "content/common/mojo/constants.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/common/content_constants.h" | 28 #include "content/public/common/content_constants.h" |
28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
29 #include "content/public/common/mojo_channel_switches.h" | 30 #include "content/public/common/mojo_channel_switches.h" |
30 #include "content/public/common/pepper_plugin_info.h" | 31 #include "content/public/common/pepper_plugin_info.h" |
31 #include "content/public/common/process_type.h" | 32 #include "content/public/common/process_type.h" |
32 #include "content/public/common/sandbox_type.h" | 33 #include "content/public/common/sandbox_type.h" |
33 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 34 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
34 #include "ipc/ipc_switches.h" | 35 #include "ipc/ipc_switches.h" |
35 #include "mojo/edk/embedder/embedder.h" | 36 #include "mojo/edk/embedder/embedder.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 312 } |
312 | 313 |
313 // We already have an open channel, send a request right away to plugin. | 314 // We already have an open channel, send a request right away to plugin. |
314 RequestPluginChannel(client); | 315 RequestPluginChannel(client); |
315 } | 316 } |
316 | 317 |
317 PpapiPluginProcessHost::PpapiPluginProcessHost( | 318 PpapiPluginProcessHost::PpapiPluginProcessHost( |
318 const PepperPluginInfo& info, | 319 const PepperPluginInfo& info, |
319 const base::FilePath& profile_data_directory) | 320 const base::FilePath& profile_data_directory) |
320 : profile_data_directory_(profile_data_directory), | 321 : profile_data_directory_(profile_data_directory), |
321 is_broker_(false), | 322 is_broker_(false) { |
322 mojo_child_token_(mojo::edk::GenerateRandomToken()) { | |
323 uint32_t base_permissions = info.permissions; | 323 uint32_t base_permissions = info.permissions; |
324 | 324 |
325 // We don't have to do any whitelisting for APIs in this process host, so | 325 // We don't have to do any whitelisting for APIs in this process host, so |
326 // don't bother passing a browser context or document url here. | 326 // don't bother passing a browser context or document url here. |
327 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( | 327 if (GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
328 NULL, GURL())) | 328 NULL, GURL())) |
329 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; | 329 base_permissions |= ppapi::PERMISSION_DEV_CHANNEL; |
330 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); | 330 permissions_ = ppapi::PpapiPermissions::GetForCommandLine(base_permissions); |
331 | 331 |
332 process_.reset(new BrowserChildProcessHostImpl( | 332 process_.reset(new BrowserChildProcessHostImpl( |
333 PROCESS_TYPE_PPAPI_PLUGIN, this, mojo_child_token_)); | 333 PROCESS_TYPE_PPAPI_PLUGIN, this, kPluginMojoApplicationName)); |
334 | 334 |
335 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, | 335 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name, |
336 info.path, profile_data_directory, | 336 info.path, profile_data_directory, |
337 false /* in_process */, | 337 false /* in_process */, |
338 false /* external_plugin */)); | 338 false /* external_plugin */)); |
339 | 339 |
340 filter_ = new PepperMessageFilter(); | 340 filter_ = new PepperMessageFilter(); |
341 process_->AddFilter(filter_.get()); | 341 process_->AddFilter(filter_.get()); |
342 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); | 342 process_->GetHost()->AddFilter(host_impl_->message_filter().get()); |
343 #if defined(OS_WIN) | 343 #if defined(OS_WIN) |
344 process_->AddFilter(new DWriteFontProxyMessageFilter()); | 344 process_->AddFilter(new DWriteFontProxyMessageFilter()); |
345 #endif | 345 #endif |
346 | 346 |
347 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); | 347 GetContentClient()->browser()->DidCreatePpapiPlugin(host_impl_.get()); |
348 | 348 |
349 // Only request network status updates if the plugin has dev permissions. | 349 // Only request network status updates if the plugin has dev permissions. |
350 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) | 350 if (permissions_.HasPermission(ppapi::PERMISSION_DEV)) |
351 network_observer_.reset(new PluginNetworkObserver(this)); | 351 network_observer_.reset(new PluginNetworkObserver(this)); |
352 } | 352 } |
353 | 353 |
354 PpapiPluginProcessHost::PpapiPluginProcessHost() | 354 PpapiPluginProcessHost::PpapiPluginProcessHost() : is_broker_(true) { |
355 : is_broker_(true), | |
356 mojo_child_token_(mojo::edk::GenerateRandomToken()) { | |
357 process_.reset(new BrowserChildProcessHostImpl( | 355 process_.reset(new BrowserChildProcessHostImpl( |
358 PROCESS_TYPE_PPAPI_BROKER, this, mojo_child_token_)); | 356 PROCESS_TYPE_PPAPI_BROKER, this, kPluginMojoApplicationName)); |
359 | 357 |
360 ppapi::PpapiPermissions permissions; // No permissions. | 358 ppapi::PpapiPermissions permissions; // No permissions. |
361 // The plugin name, path and profile data directory shouldn't be needed for | 359 // The plugin name, path and profile data directory shouldn't be needed for |
362 // the broker. | 360 // the broker. |
363 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, | 361 host_impl_.reset(new BrowserPpapiHostImpl(this, permissions, |
364 std::string(), base::FilePath(), | 362 std::string(), base::FilePath(), |
365 base::FilePath(), | 363 base::FilePath(), |
366 false /* in_process */, | 364 false /* in_process */, |
367 false /* external_plugin */)); | 365 false /* external_plugin */)); |
368 } | 366 } |
369 | 367 |
370 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { | 368 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { |
371 plugin_path_ = info.path; | 369 plugin_path_ = info.path; |
372 if (info.name.empty()) { | 370 if (info.name.empty()) { |
373 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); | 371 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); |
374 } else { | 372 } else { |
375 process_->SetName(base::UTF8ToUTF16(info.name)); | 373 process_->SetName(base::UTF8ToUTF16(info.name)); |
376 } | 374 } |
377 | 375 |
378 std::string mojo_channel_token = | 376 process_->GetHost()->CreateChannelMojo(); |
379 process_->GetHost()->CreateChannelMojo(mojo_child_token_); | |
380 if (mojo_channel_token.empty()) { | |
381 VLOG(1) << "Could not create pepper host channel."; | |
382 return false; | |
383 } | |
384 | 377 |
385 const base::CommandLine& browser_command_line = | 378 const base::CommandLine& browser_command_line = |
386 *base::CommandLine::ForCurrentProcess(); | 379 *base::CommandLine::ForCurrentProcess(); |
387 base::CommandLine::StringType plugin_launcher = | 380 base::CommandLine::StringType plugin_launcher = |
388 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 381 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
389 | 382 |
390 #if defined(OS_LINUX) | 383 #if defined(OS_LINUX) |
391 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 384 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
392 ChildProcessHost::CHILD_NORMAL; | 385 ChildProcessHost::CHILD_NORMAL; |
393 #else | 386 #else |
394 int flags = ChildProcessHost::CHILD_NORMAL; | 387 int flags = ChildProcessHost::CHILD_NORMAL; |
395 #endif | 388 #endif |
396 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 389 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
397 if (exe_path.empty()) { | 390 if (exe_path.empty()) { |
398 VLOG(1) << "Pepper plugin exe path is empty."; | 391 VLOG(1) << "Pepper plugin exe path is empty."; |
399 return false; | 392 return false; |
400 } | 393 } |
401 | 394 |
402 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | 395 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
403 cmd_line->AppendSwitchASCII(switches::kProcessType, | 396 cmd_line->AppendSwitchASCII(switches::kProcessType, |
404 is_broker_ ? switches::kPpapiBrokerProcess | 397 is_broker_ ? switches::kPpapiBrokerProcess |
405 : switches::kPpapiPluginProcess); | 398 : switches::kPpapiPluginProcess); |
406 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); | |
407 | 399 |
408 #if defined(OS_WIN) | 400 #if defined(OS_WIN) |
409 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker | 401 cmd_line->AppendArg(is_broker_ ? switches::kPrefetchArgumentPpapiBroker |
410 : switches::kPrefetchArgumentPpapi); | 402 : switches::kPrefetchArgumentPpapi); |
411 #endif // defined(OS_WIN) | 403 #endif // defined(OS_WIN) |
412 | 404 |
413 // These switches are forwarded to both plugin and broker pocesses. | 405 // These switches are forwarded to both plugin and broker pocesses. |
414 static const char* const kCommonForwardSwitches[] = { | 406 static const char* const kCommonForwardSwitches[] = { |
415 switches::kVModule | 407 switches::kVModule |
416 }; | 408 }; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 // sent_requests_ queue should be the one that the plugin just created. | 552 // sent_requests_ queue should be the one that the plugin just created. |
561 Client* client = sent_requests_.front(); | 553 Client* client = sent_requests_.front(); |
562 sent_requests_.pop(); | 554 sent_requests_.pop(); |
563 | 555 |
564 const ChildProcessData& data = process_->GetData(); | 556 const ChildProcessData& data = process_->GetData(); |
565 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), | 557 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), |
566 data.id); | 558 data.id); |
567 } | 559 } |
568 | 560 |
569 } // namespace content | 561 } // namespace content |
OLD | NEW |