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.
5 #include "chrome_frame/chrome_launcher_utils.h"
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/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"
22 const char kUpdateCommandFlag
[] = "--update-cmd";
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
27 bool CreateChromeLauncherCommandLine(scoped_ptr
<CommandLine
>* command_line
) {
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 (file_util::PathExists(chrome_launcher
)) {
38 command_line
->reset(new CommandLine(chrome_launcher
));
44 NOTREACHED() << "Could not find " << chrome_launcher::kLauncherExeBaseName
53 namespace chrome_launcher
{
55 const wchar_t kLauncherExeBaseName
[] = L
"chrome_launcher.exe";
57 bool CreateUpdateCommandLine(const std::wstring
& update_command
,
58 scoped_ptr
<CommandLine
>* command_line
) {
62 if (CreateChromeLauncherCommandLine(command_line
)) {
63 (*command_line
)->AppendArg(kUpdateCommandFlag
);
64 (*command_line
)->AppendArg(WideToASCII(update_command
));
71 bool CreateLaunchCommandLine(scoped_ptr
<CommandLine
>* command_line
) {
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()));
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);
89 return CreateChromeLauncherCommandLine(command_line
);
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
);
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
101 if (!file_util::PathExists(cur_path
)) {
102 PathService::Get(base::DIR_MODULE
, &cur_path
);
103 cur_path
= cur_path
.DirName().Append(chrome::kBrowserProcessExecutableName
);
109 } // namespace chrome_launcher