Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / app_shim / win / app_shim_main.cc
blob6835f258bd9345c1ff5e69c65551a6d1e4f7fbb6
1 // Copyright 2014 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 <windows.h>
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/process/launch.h"
13 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
15 namespace {
17 // Return codes.
18 const int kOK = 0;
19 const int kNoProgram = 1;
20 const int kLaunchFailure = 2;
22 // Command-line switches.
23 const char kChromeSxS[] = "chrome-sxs";
25 } // namespace
27 // This program runs chrome.exe, passing its arguments on to the Chrome binary.
28 // It uses the Windows registry to find chrome.exe (and hence it only works if
29 // Chrome/Chromium has been properly installed). It terminates as soon as the
30 // program is launched. It is intended to allow file types to be associated with
31 // Chrome apps, with a custom name (and in some cases, icon) rather than simply
32 // the name of the Chrome binary.
34 // Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...]
36 // The -- is required if switches are to be passed to Chrome; any switches
37 // before the -- will be interpreted by app_shim_win, and not passed to Chrome.
39 // If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome.
40 // This will always fail for Chromium.
41 int WINAPI wWinMain(HINSTANCE instance,
42 HINSTANCE prev_instance,
43 wchar_t* /*command_line*/,
44 int show_command) {
45 base::CommandLine::Init(0, nullptr);
47 // Log to stderr. Otherwise it will log to a file by default.
48 logging::LoggingSettings logging_settings;
49 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
50 logging::InitLogging(logging_settings);
52 // Get the command-line for the Chrome binary.
53 // --chrome-sxs on the command line means we should run the SxS binary.
54 bool is_sxs = base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
55 base::FilePath chrome_path =
56 chrome_launcher_support::GetAnyChromePath(is_sxs);
57 if (chrome_path.empty()) {
58 LOG(ERROR) << "Could not find chrome.exe path in the registry.";
59 return kNoProgram;
61 base::CommandLine command_line(chrome_path);
63 // Get the command-line arguments for the subprocess, consisting of the
64 // arguments (but not switches) to this binary. This gets everything after the
65 // "--".
66 for (const auto& arg : base::CommandLine::ForCurrentProcess()->GetArgs())
67 command_line.AppendArgNative(arg);
69 if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) {
70 LOG(ERROR) << "Could not run chrome.exe.";
71 return kLaunchFailure;
74 return kOK;