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"
21 const char kUpdateCommandFlag
[] = "--update-cmd";
23 // Searches for the path to chrome_launcher.exe. Will return false if this
24 // executable cannot be found, otherwise the command line will be placed in
26 bool CreateChromeLauncherCommandLine(scoped_ptr
<CommandLine
>* command_line
) {
29 // The launcher EXE will be in the same directory as the Chrome Frame DLL,
30 // so create a full path to it based on this assumption.
32 if (PathService::Get(base::FILE_MODULE
, &module_path
)) {
33 FilePath current_dir
= module_path
.DirName();
34 FilePath chrome_launcher
= current_dir
.Append(
35 chrome_launcher::kLauncherExeBaseName
);
36 if (file_util::PathExists(chrome_launcher
)) {
37 command_line
->reset(new CommandLine(chrome_launcher
));
43 NOTREACHED() << "Could not find " << chrome_launcher::kLauncherExeBaseName
52 namespace chrome_launcher
{
54 const wchar_t kLauncherExeBaseName
[] = L
"chrome_launcher.exe";
56 bool CreateUpdateCommandLine(const std::wstring
& update_command
,
57 scoped_ptr
<CommandLine
>* command_line
) {
61 if (CreateChromeLauncherCommandLine(command_line
)) {
62 (*command_line
)->AppendArg(kUpdateCommandFlag
);
63 (*command_line
)->AppendArg(WideToASCII(update_command
));
70 bool CreateLaunchCommandLine(scoped_ptr
<CommandLine
>* command_line
) {
73 // Shortcut for OS versions that don't need the integrity broker.
74 if (base::win::GetVersion() < base::win::VERSION_VISTA
) {
75 command_line
->reset(new CommandLine(GetChromeExecutablePath()));
79 return CreateChromeLauncherCommandLine(command_line
);
82 FilePath
GetChromeExecutablePath() {
84 PathService::Get(base::DIR_MODULE
, &cur_path
);
85 cur_path
= cur_path
.Append(chrome::kBrowserProcessExecutableName
);
87 // The installation model for Chrome places the DLLs in a versioned
88 // sub-folder one down from the Chrome executable. If we fail to find
89 // chrome.exe in the current path, try looking one up and launching that
91 if (!file_util::PathExists(cur_path
)) {
92 PathService::Get(base::DIR_MODULE
, &cur_path
);
93 cur_path
= cur_path
.DirName().Append(chrome::kBrowserProcessExecutableName
);
99 } // namespace chrome_launcher