Chromium Code Reviews| Index: chrome/app_shim/app_shim_win.cc |
| diff --git a/chrome/app_shim/app_shim_win.cc b/chrome/app_shim/app_shim_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a29f710514e3cc3aa38e7c9f3282e39beb44ea9 |
| --- /dev/null |
| +++ b/chrome/app_shim/app_shim_win.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2014 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 <string> |
| + |
| +#include "base/command_line.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/process/launch.h" |
| +#include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| + |
| +#include <windows.h> |
|
grt (UTC plus 2)
2014/10/30 17:04:56
move above line 5 as per http://google-styleguide.
Matt Giuca
2014/11/04 04:38:17
Done.
|
| + |
| +namespace { |
| + |
| +// Return codes. |
| +const int kOK = 0; |
| +const int kNoProgram = 1; |
| +const int kLaunchFailure = 2; |
| + |
| +// Command-line switches. |
| +const char kChromeSxS[] = "chrome-sxs"; |
| + |
| +base::FilePath GetChromeExePath(bool is_canary) { |
| + return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath() |
| + : chrome_launcher_support::GetAnyChromePath(); |
| +} |
| + |
| +} // namespace |
| + |
| +// This program runs chrome.exe, passing its arguments on to the Chrome binary. |
| +// It uses the Windows registry to find chrome.exe (and hence it only works if |
| +// Chrome/Chromium has been properly installed). It terminates as soon as the |
| +// program is launched. It is intended to allow file types to be associated with |
| +// Chrome apps, with a custom name (and in some cases, icon) rather than simply |
| +// the name of the Chrome binary. |
| +// |
| +// Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...] |
| +// |
| +// The -- is required if switches are to be passed to Chrome; any switches |
| +// before the -- will be interpreted by app_shim_win, and not passed to Chrome. |
| +// |
| +// If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome. |
| +// This will always fail for Chromium. |
| +int WINAPI WinMain(HINSTANCE instance, |
|
grt (UTC plus 2)
2014/10/30 17:04:56
WinMain -> wWinMain
Matt Giuca
2014/11/04 04:38:17
Done.
|
| + HINSTANCE prev_instance, |
| + char* /*command_line*/, |
| + int show_command) { |
| + CommandLine::Init(0, nullptr); |
| + |
| + // Log to stderr. Otherwise it will log to a file by default. |
| + logging::LoggingSettings logging_settings; |
| + logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| + logging::InitLogging(logging_settings); |
| + |
| + // Get the command-line for the Chrome binary. |
| + // --chrome-sxs on the command line means we should run the canary binary. |
| + bool is_canary = |
| + base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS); |
| + base::FilePath chrome_path = GetChromeExePath(is_canary); |
| + if (chrome_path.empty()) { |
| + LOG(ERROR) << "Could not find chrome.exe path in the registry."; |
| + return kNoProgram; |
| + } |
| + CommandLine command_line(chrome_path); |
| + |
| + // Get the command-line arguments for the subprocess, consisting of the |
| + // arguments (but not switches) to this binary. This gets everything after the |
| + // "--". |
| + for (const auto& arg : CommandLine::ForCurrentProcess()->GetArgs()) |
| + command_line.AppendArgNative(arg); |
| + |
| + base::LaunchOptions options; |
| + if (!base::LaunchProcess(command_line, options, nullptr)) |
|
grt (UTC plus 2)
2014/10/30 17:04:56
options -> base::LaunchOptions()
Matt Giuca
2014/11/04 04:38:17
Done.
|
| + return kLaunchFailure; |
|
grt (UTC plus 2)
2014/10/30 17:04:56
LOG(ERROR) here as on line 63?
Matt Giuca
2014/11/04 04:38:17
Done.
|
| + |
| + return kOK; |
| +} |