OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome_frame/chrome_launcher.h" |
| 6 |
| 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/path_service.h" |
| 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome_frame/chrome_frame_automation.h" |
| 15 #include "chrome_frame/crash_report.h" |
| 16 |
| 17 namespace chrome_launcher { |
| 18 |
| 19 const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe"; |
| 20 |
| 21 // These are the switches we will allow (along with their values) in the |
| 22 // safe-for-Low-Integrity version of the Chrome command line. |
| 23 const wchar_t* kAllowedSwitches[] = { |
| 24 switches::kAutomationClientChannelID, |
| 25 switches::kDisableMetrics, |
| 26 switches::kNoFirstRun, |
| 27 switches::kUserDataDir, |
| 28 switches::kLoadExtension, |
| 29 }; |
| 30 |
| 31 CommandLine* CreateLaunchCommandLine() { |
| 32 // TODO(joi) As optimization, could launch Chrome directly when running at |
| 33 // medium integrity. (Requires bringing in code to read SIDs, etc.) |
| 34 |
| 35 // The launcher EXE will be in the same directory as the npchrome_tab DLL, |
| 36 // so create a full path to it based on this assumption. Since our unit |
| 37 // tests also use this function, and live in the directory above, we test |
| 38 // existence of the file and try the path that includes the /servers/ |
| 39 // directory if needed. |
| 40 FilePath module_path; |
| 41 if (PathService::Get(base::FILE_MODULE, &module_path)) { |
| 42 FilePath current_dir = module_path.DirName(); |
| 43 FilePath same_dir_path = current_dir.Append(kLauncherExeBaseName); |
| 44 if (file_util::PathExists(same_dir_path)) { |
| 45 return new CommandLine(same_dir_path.ToWStringHack()); |
| 46 } else { |
| 47 FilePath servers_path = |
| 48 current_dir.Append(L"servers").Append(kLauncherExeBaseName); |
| 49 DCHECK(file_util::PathExists(servers_path)) << |
| 50 "What module is this? It's not in 'servers' or main output dir."; |
| 51 return new CommandLine(servers_path.ToWStringHack()); |
| 52 } |
| 53 } else { |
| 54 NOTREACHED(); |
| 55 return NULL; |
| 56 } |
| 57 } |
| 58 |
| 59 void SanitizeCommandLine(const CommandLine& original, CommandLine* sanitized) { |
| 60 int num_sanitized_switches = 0; |
| 61 for (int i = 0; i < arraysize(kAllowedSwitches); ++i) { |
| 62 const wchar_t* current_switch = kAllowedSwitches[i]; |
| 63 if (original.HasSwitch(current_switch)) { |
| 64 ++num_sanitized_switches; |
| 65 std::wstring switch_value = original.GetSwitchValue(current_switch); |
| 66 if (0 == switch_value.length()) { |
| 67 sanitized->AppendSwitch(current_switch); |
| 68 } else { |
| 69 sanitized->AppendSwitchWithValue(current_switch, switch_value); |
| 70 } |
| 71 } |
| 72 } |
| 73 if (num_sanitized_switches != original.GetSwitchCount()) { |
| 74 NOTREACHED(); |
| 75 LOG(ERROR) << "Original command line from Low Integrity had switches " |
| 76 << "that are not on our whitelist."; |
| 77 } |
| 78 } |
| 79 |
| 80 bool SanitizeAndLaunchChrome(const wchar_t* command_line) { |
| 81 std::wstring command_line_with_program(L"dummy.exe "); |
| 82 command_line_with_program += command_line; |
| 83 CommandLine original(L""); |
| 84 original.ParseFromString(command_line_with_program); |
| 85 CommandLine sanitized(GetChromeExecutablePath()); |
| 86 SanitizeCommandLine(original, &sanitized); |
| 87 |
| 88 return base::LaunchApp(sanitized.command_line_string(), false, false, NULL); |
| 89 } |
| 90 |
| 91 std::wstring GetChromeExecutablePath() { |
| 92 std::wstring cur_path; |
| 93 PathService::Get(base::DIR_MODULE, &cur_path); |
| 94 file_util::AppendToPath(&cur_path, chrome::kBrowserProcessExecutableName); |
| 95 |
| 96 // The installation model for Chrome places the DLLs in a versioned |
| 97 // sub-folder one down from the Chrome executable. If we fail to find |
| 98 // chrome.exe in the current path, try looking one up and launching that |
| 99 // instead. |
| 100 if (!file_util::PathExists(cur_path)) { |
| 101 PathService::Get(base::DIR_MODULE, &cur_path); |
| 102 file_util::UpOneDirectory(&cur_path); |
| 103 file_util::AppendToPath(&cur_path, chrome::kBrowserProcessExecutableName); |
| 104 } |
| 105 |
| 106 return cur_path; |
| 107 } |
| 108 |
| 109 } // namespace chrome_launcher |
| 110 |
| 111 // Entrypoint that implements the logic of chrome_launcher.exe. |
| 112 int CALLBACK CfLaunchChrome() { |
| 113 if (chrome_launcher::SanitizeAndLaunchChrome(::GetCommandLine())) { |
| 114 return ERROR_SUCCESS; |
| 115 } else { |
| 116 return ERROR_OPEN_FAILED; |
| 117 } |
| 118 } |
| 119 |
| 120 // Compile-time check to see that the type CfLaunchChromeProc is correct. |
| 121 #ifndef NODEBUG |
| 122 namespace { |
| 123 chrome_launcher::CfLaunchChromeProc cf_launch_chrome = CfLaunchChrome; |
| 124 } // namespace |
| 125 #endif // NODEBUG |
OLD | NEW |