| 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/browser/plugin_process_host.h" | 5 #include "chrome/browser/plugin_process_host.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 this)); | 454 this)); |
| 455 if (!channel_->Connect()) | 455 if (!channel_->Connect()) |
| 456 return false; | 456 return false; |
| 457 | 457 |
| 458 // build command line for plugin, we have to quote the plugin's path to deal | 458 // build command line for plugin, we have to quote the plugin's path to deal |
| 459 // with spaces. | 459 // with spaces. |
| 460 std::wstring exe_path; | 460 std::wstring exe_path; |
| 461 if (!PathService::Get(base::FILE_EXE, &exe_path)) | 461 if (!PathService::Get(base::FILE_EXE, &exe_path)) |
| 462 return false; | 462 return false; |
| 463 | 463 |
| 464 std::wstring cmd_line(L"\""); | 464 CommandLine cmd_line(exe_path); |
| 465 cmd_line += exe_path; | |
| 466 cmd_line += L"\""; | |
| 467 if (logging::DialogsAreSuppressed()) | 465 if (logging::DialogsAreSuppressed()) |
| 468 CommandLine::AppendSwitch(&cmd_line, switches::kNoErrorDialogs); | 466 cmd_line.AppendSwitch(switches::kNoErrorDialogs); |
| 469 | 467 |
| 470 CommandLine browser_command_line; | 468 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 471 | 469 |
| 472 // propagate the following switches to the plugin command line (along with | 470 // propagate the following switches to the plugin command line (along with |
| 473 // any associated values) if present in the browser command line | 471 // any associated values) if present in the browser command line |
| 474 static const wchar_t* const switch_names[] = { | 472 static const wchar_t* const switch_names[] = { |
| 475 switches::kPluginStartupDialog, | 473 switches::kPluginStartupDialog, |
| 476 switches::kNoSandbox, | 474 switches::kNoSandbox, |
| 477 switches::kSafePlugins, | 475 switches::kSafePlugins, |
| 478 switches::kTestSandbox, | 476 switches::kTestSandbox, |
| 479 switches::kUserAgent, | 477 switches::kUserAgent, |
| 480 switches::kDisableBreakpad, | 478 switches::kDisableBreakpad, |
| 481 switches::kFullMemoryCrashReport, | 479 switches::kFullMemoryCrashReport, |
| 482 switches::kEnableLogging, | 480 switches::kEnableLogging, |
| 483 switches::kDisableLogging, | 481 switches::kDisableLogging, |
| 484 switches::kLoggingLevel, | 482 switches::kLoggingLevel, |
| 485 switches::kUserDataDir, | 483 switches::kUserDataDir, |
| 486 switches::kAllowAllActiveX, | 484 switches::kAllowAllActiveX, |
| 487 switches::kEnableDCHECK, | 485 switches::kEnableDCHECK, |
| 488 switches::kSilentDumpOnDCHECK, | 486 switches::kSilentDumpOnDCHECK, |
| 489 switches::kMemoryProfiling, | 487 switches::kMemoryProfiling, |
| 490 switches::kUseLowFragHeapCrt, | 488 switches::kUseLowFragHeapCrt, |
| 491 }; | 489 }; |
| 492 | 490 |
| 493 for (int i = 0; i < arraysize(switch_names); ++i) { | 491 for (int i = 0; i < arraysize(switch_names); ++i) { |
| 494 if (browser_command_line.HasSwitch(switch_names[i])) { | 492 if (browser_command_line.HasSwitch(switch_names[i])) { |
| 495 CommandLine::AppendSwitchWithValue( | 493 cmd_line.AppendSwitchWithValue( |
| 496 &cmd_line, switch_names[i], | 494 switch_names[i], |
| 497 browser_command_line.GetSwitchValue(switch_names[i])); | 495 browser_command_line.GetSwitchValue(switch_names[i])); |
| 498 } | 496 } |
| 499 } | 497 } |
| 500 | 498 |
| 501 // If specified, prepend a launcher program to the command line. | 499 // If specified, prepend a launcher program to the command line. |
| 502 std::wstring plugin_launcher = | 500 std::wstring plugin_launcher = |
| 503 browser_command_line.GetSwitchValue(switches::kPluginLauncher); | 501 browser_command_line.GetSwitchValue(switches::kPluginLauncher); |
| 504 if (!plugin_launcher.empty()) | 502 if (!plugin_launcher.empty()) { |
| 505 cmd_line = plugin_launcher + L" " + cmd_line; | 503 CommandLine new_cmd_line = CommandLine(plugin_launcher); |
| 504 new_cmd_line.AppendArguments(cmd_line, true); |
| 505 cmd_line = new_cmd_line; |
| 506 } |
| 506 | 507 |
| 507 if (!locale.empty()) { | 508 if (!locale.empty()) { |
| 508 // Pass on the locale so the null plugin will use the right language in the | 509 // Pass on the locale so the null plugin will use the right language in the |
| 509 // prompt to install the desired plugin. | 510 // prompt to install the desired plugin. |
| 510 CommandLine::AppendSwitchWithValue(&cmd_line, switches::kLang, locale); | 511 cmd_line.AppendSwitchWithValue(switches::kLang, locale); |
| 511 } | 512 } |
| 512 | 513 |
| 513 CommandLine::AppendSwitchWithValue(&cmd_line, | 514 cmd_line.AppendSwitchWithValue(switches::kProcessType, |
| 514 switches::kProcessType, | 515 switches::kPluginProcess); |
| 515 switches::kPluginProcess); | |
| 516 | 516 |
| 517 CommandLine::AppendSwitchWithValue(&cmd_line, | 517 cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, |
| 518 switches::kProcessChannelID, | 518 channel_id_); |
| 519 channel_id_); | |
| 520 | 519 |
| 521 CommandLine::AppendSwitchWithValue(&cmd_line, | 520 cmd_line.AppendSwitchWithValue(switches::kPluginPath, |
| 522 switches::kPluginPath, | 521 plugin_path.ToWStringHack()); |
| 523 plugin_path.ToWStringHack()); | |
| 524 | 522 |
| 525 bool in_sandbox = !browser_command_line.HasSwitch(switches::kNoSandbox) && | 523 bool in_sandbox = !browser_command_line.HasSwitch(switches::kNoSandbox) && |
| 526 browser_command_line.HasSwitch(switches::kSafePlugins); | 524 browser_command_line.HasSwitch(switches::kSafePlugins); |
| 527 | 525 |
| 528 bool child_needs_help = | 526 bool child_needs_help = |
| 529 DebugFlags::ProcessDebugFlags(&cmd_line, DebugFlags::PLUGIN, in_sandbox); | 527 DebugFlags::ProcessDebugFlags(&cmd_line, DebugFlags::PLUGIN, in_sandbox); |
| 530 | 528 |
| 531 if (in_sandbox) { | 529 if (in_sandbox) { |
| 532 // spawn the child process in the sandbox | 530 // spawn the child process in the sandbox |
| 533 sandbox::BrokerServices* broker_service = | 531 sandbox::BrokerServices* broker_service = |
| 534 g_browser_process->broker_services(); | 532 g_browser_process->broker_services(); |
| 535 | 533 |
| 536 sandbox::ResultCode result; | 534 sandbox::ResultCode result; |
| 537 PROCESS_INFORMATION target = {0}; | 535 PROCESS_INFORMATION target = {0}; |
| 538 sandbox::TargetPolicy* policy = broker_service->CreatePolicy(); | 536 sandbox::TargetPolicy* policy = broker_service->CreatePolicy(); |
| 539 | 537 |
| 540 std::wstring trusted_plugins = | 538 std::wstring trusted_plugins = |
| 541 browser_command_line.GetSwitchValue(switches::kTrustedPlugins); | 539 browser_command_line.GetSwitchValue(switches::kTrustedPlugins); |
| 542 if (!AddPolicyForPlugin(plugin_path, activex_clsid, trusted_plugins, | 540 if (!AddPolicyForPlugin(plugin_path, activex_clsid, trusted_plugins, |
| 543 policy)) { | 541 policy)) { |
| 544 NOTREACHED(); | 542 NOTREACHED(); |
| 545 return false; | 543 return false; |
| 546 } | 544 } |
| 547 | 545 |
| 548 if (!AddGenericPolicy(policy)) { | 546 if (!AddGenericPolicy(policy)) { |
| 549 NOTREACHED(); | 547 NOTREACHED(); |
| 550 return false; | 548 return false; |
| 551 } | 549 } |
| 552 | 550 |
| 553 result = broker_service->SpawnTarget(exe_path.c_str(), | 551 result = |
| 554 cmd_line.c_str(), policy, &target); | 552 broker_service->SpawnTarget(exe_path.c_str(), |
| 553 cmd_line.command_line_string().c_str(), |
| 554 policy, &target); |
| 555 policy->Release(); | 555 policy->Release(); |
| 556 if (sandbox::SBOX_ALL_OK != result) | 556 if (sandbox::SBOX_ALL_OK != result) |
| 557 return false; | 557 return false; |
| 558 | 558 |
| 559 ResumeThread(target.hThread); | 559 ResumeThread(target.hThread); |
| 560 CloseHandle(target.hThread); | 560 CloseHandle(target.hThread); |
| 561 process_.set_handle(target.hProcess); | 561 process_.set_handle(target.hProcess); |
| 562 | 562 |
| 563 // Help the process a little. It can't start the debugger by itself if | 563 // Help the process a little. It can't start the debugger by itself if |
| 564 // the process is in a sandbox. | 564 // the process is in a sandbox. |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 void PluginProcessHost::OnDestroyWindow(HWND window) { | 931 void PluginProcessHost::OnDestroyWindow(HWND window) { |
| 932 plugin_service_->main_message_loop()->PostTask(FROM_HERE, | 932 plugin_service_->main_message_loop()->PostTask(FROM_HERE, |
| 933 new DestroyWindowTask(window)); | 933 new DestroyWindowTask(window)); |
| 934 } | 934 } |
| 935 | 935 |
| 936 void PluginProcessHost::Shutdown() { | 936 void PluginProcessHost::Shutdown() { |
| 937 | 937 |
| 938 Send(new PluginProcessMsg_BrowserShutdown); | 938 Send(new PluginProcessMsg_BrowserShutdown); |
| 939 } | 939 } |
| 940 | 940 |
| OLD | NEW |