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 3 // found in the LICENSE file. 4 5 #include "chrome_frame/chrome_launcher_utils.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/memory/scoped_ptr.h" 12 #include "base/path_service.h" 13 #include "base/strings/string_util.h" 14 #include "base/win/windows_version.h" 15 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_switches.h" 17 #include "chrome_frame/chrome_frame_automation.h" 18 #include "chrome_frame/policy_settings.h" 19 20 namespace { 21 22 const char kUpdateCommandFlag[] = "--update-cmd"; 23 24 // Searches for the path to chrome_launcher.exe. Will return false if this 25 // executable cannot be found, otherwise the command line will be placed in 26 // |command_line|. 27 bool CreateChromeLauncherCommandLine(scoped_ptr<CommandLine>* command_line) { 28 DCHECK(command_line); 29 bool success = false; 30 // The launcher EXE will be in the same directory as the Chrome Frame DLL, 31 // so create a full path to it based on this assumption. 32 base::FilePath module_path; 33 if (PathService::Get(base::FILE_MODULE, &module_path)) { 34 base::FilePath current_dir = module_path.DirName(); 35 base::FilePath chrome_launcher = current_dir.Append( 36 chrome_launcher::kLauncherExeBaseName); 37 if (base::PathExists(chrome_launcher)) { 38 command_line->reset(new CommandLine(chrome_launcher)); 39 success = true; 40 } 41 } 42 43 if (!success) { 44 NOTREACHED() << "Could not find " << chrome_launcher::kLauncherExeBaseName 45 << " in output dir."; 46 } 47 48 return success; 49 } 50 51 } // namespace 52 53 namespace chrome_launcher { 54 55 const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe"; 56 57 bool CreateUpdateCommandLine(const std::wstring& update_command, 58 scoped_ptr<CommandLine>* command_line) { 59 DCHECK(command_line); 60 bool success = false; 61 62 if (CreateChromeLauncherCommandLine(command_line)) { 63 (*command_line)->AppendArg(kUpdateCommandFlag); 64 (*command_line)->AppendArg(WideToASCII(update_command)); 65 success = true; 66 } 67 68 return success; 69 } 70 71 bool CreateLaunchCommandLine(scoped_ptr<CommandLine>* command_line) { 72 DCHECK(command_line); 73 74 // Shortcut for OS versions that don't need the integrity broker. 75 if (base::win::GetVersion() < base::win::VERSION_VISTA) { 76 command_line->reset(new CommandLine(GetChromeExecutablePath())); 77 78 // When we do not use the Chrome Launcher, we need to add the optional extra 79 // parameters from the group policy here (this is normally done by the 80 // chrome launcher). We don't do this when we use the launcher as the 81 // optional arguments could trip off sanitization checks and prevent Chrome 82 // from being launched. 83 const CommandLine& additional_params = 84 PolicySettings::GetInstance()->AdditionalLaunchParameters(); 85 command_line->get()->AppendArguments(additional_params, false); 86 return true; 87 } 88 89 return CreateChromeLauncherCommandLine(command_line); 90 } 91 92 base::FilePath GetChromeExecutablePath() { 93 base::FilePath cur_path; 94 PathService::Get(base::DIR_MODULE, &cur_path); 95 cur_path = cur_path.Append(chrome::kBrowserProcessExecutableName); 96 97 // The installation model for Chrome places the DLLs in a versioned 98 // sub-folder one down from the Chrome executable. If we fail to find 99 // chrome.exe in the current path, try looking one up and launching that 100 // instead. 101 if (!base::PathExists(cur_path)) { 102 PathService::Get(base::DIR_MODULE, &cur_path); 103 cur_path = cur_path.DirName().Append(chrome::kBrowserProcessExecutableName); 104 } 105 106 return cur_path; 107 } 108 109 } // namespace chrome_launcher 110