summaryrefslogtreecommitdiffstats
path: root/chrome_frame/chrome_launcher_utils.cc
blob: 0465b7bdca211c6fc0d2eb86503ea7ccdf5c56b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/chrome_launcher_utils.h"

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/win/windows_version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome_frame/chrome_frame_automation.h"
#include "chrome_frame/policy_settings.h"

namespace {

const char kUpdateCommandFlag[] = "--update-cmd";

// Searches for the path to chrome_launcher.exe. Will return false if this
// executable cannot be found, otherwise the command line will be placed in
// |command_line|.
bool CreateChromeLauncherCommandLine(scoped_ptr<CommandLine>* command_line) {
  DCHECK(command_line);
  bool success = false;
  // The launcher EXE will be in the same directory as the Chrome Frame DLL,
  // so create a full path to it based on this assumption.
  FilePath module_path;
  if (PathService::Get(base::FILE_MODULE, &module_path)) {
    FilePath current_dir = module_path.DirName();
    FilePath chrome_launcher = current_dir.Append(
        chrome_launcher::kLauncherExeBaseName);
    if (file_util::PathExists(chrome_launcher)) {
      command_line->reset(new CommandLine(chrome_launcher));
      success = true;
    }
  }

  if (!success) {
    NOTREACHED() << "Could not find " << chrome_launcher::kLauncherExeBaseName
                 << " in output dir.";
  }

  return success;
}

}  // namespace

namespace chrome_launcher {

const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe";

bool CreateUpdateCommandLine(const std::wstring& update_command,
                             scoped_ptr<CommandLine>* command_line) {
  DCHECK(command_line);
  bool success = false;

  if (CreateChromeLauncherCommandLine(command_line)) {
    (*command_line)->AppendArg(kUpdateCommandFlag);
    (*command_line)->AppendArg(WideToASCII(update_command));
    success = true;
  }

  return success;
}

bool CreateLaunchCommandLine(scoped_ptr<CommandLine>* command_line) {
  DCHECK(command_line);

  // Shortcut for OS versions that don't need the integrity broker.
  if (base::win::GetVersion() < base::win::VERSION_VISTA) {
    command_line->reset(new CommandLine(GetChromeExecutablePath()));

    // When we do not use the Chrome Launcher, we need to add the optional extra
    // parameters from the group policy here (this is normally done by the
    // chrome launcher).  We don't do this when we use the launcher as the
    // optional arguments could trip off sanitization checks and prevent Chrome
    // from being launched.
    const CommandLine& additional_params =
        PolicySettings::GetInstance()->AdditionalLaunchParameters();
    command_line->get()->AppendArguments(additional_params, false);
    return true;
  }

  return CreateChromeLauncherCommandLine(command_line);
}

FilePath GetChromeExecutablePath() {
  FilePath cur_path;
  PathService::Get(base::DIR_MODULE, &cur_path);
  cur_path = cur_path.Append(chrome::kBrowserProcessExecutableName);

  // The installation model for Chrome places the DLLs in a versioned
  // sub-folder one down from the Chrome executable. If we fail to find
  // chrome.exe in the current path, try looking one up and launching that
  // instead.
  if (!file_util::PathExists(cur_path)) {
    PathService::Get(base::DIR_MODULE, &cur_path);
    cur_path = cur_path.DirName().Append(chrome::kBrowserProcessExecutableName);
  }

  return cur_path;
}

}  // namespace chrome_launcher