OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include <windows.h> |
| 6 |
| 7 #include <string> |
| 8 |
| 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" |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Return codes. |
| 18 const int kOK = 0; |
| 19 const int kNoProgram = 1; |
| 20 const int kLaunchFailure = 2; |
| 21 |
| 22 // Command-line switches. |
| 23 const char kChromeSxS[] = "chrome-sxs"; |
| 24 |
| 25 base::FilePath GetChromeExePath(bool is_canary) { |
| 26 return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath() |
| 27 : chrome_launcher_support::GetAnyChromePath(); |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 32 // This program runs chrome.exe, passing its arguments on to the Chrome binary. |
| 33 // It uses the Windows registry to find chrome.exe (and hence it only works if |
| 34 // Chrome/Chromium has been properly installed). It terminates as soon as the |
| 35 // program is launched. It is intended to allow file types to be associated with |
| 36 // Chrome apps, with a custom name (and in some cases, icon) rather than simply |
| 37 // the name of the Chrome binary. |
| 38 // |
| 39 // Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...] |
| 40 // |
| 41 // The -- is required if switches are to be passed to Chrome; any switches |
| 42 // before the -- will be interpreted by app_shim_win, and not passed to Chrome. |
| 43 // |
| 44 // If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome. |
| 45 // This will always fail for Chromium. |
| 46 int WINAPI wWinMain(HINSTANCE instance, |
| 47 HINSTANCE prev_instance, |
| 48 wchar_t* /*command_line*/, |
| 49 int show_command) { |
| 50 CommandLine::Init(0, nullptr); |
| 51 |
| 52 // Log to stderr. Otherwise it will log to a file by default. |
| 53 logging::LoggingSettings logging_settings; |
| 54 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 55 logging::InitLogging(logging_settings); |
| 56 |
| 57 // Get the command-line for the Chrome binary. |
| 58 // --chrome-sxs on the command line means we should run the canary binary. |
| 59 bool is_canary = |
| 60 base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS); |
| 61 base::FilePath chrome_path = GetChromeExePath(is_canary); |
| 62 if (chrome_path.empty()) { |
| 63 LOG(ERROR) << "Could not find chrome.exe path in the registry."; |
| 64 return kNoProgram; |
| 65 } |
| 66 CommandLine command_line(chrome_path); |
| 67 |
| 68 // Get the command-line arguments for the subprocess, consisting of the |
| 69 // arguments (but not switches) to this binary. This gets everything after the |
| 70 // "--". |
| 71 for (const auto& arg : CommandLine::ForCurrentProcess()->GetArgs()) |
| 72 command_line.AppendArgNative(arg); |
| 73 |
| 74 if (!base::LaunchProcess(command_line, base::LaunchOptions(), nullptr)) { |
| 75 LOG(ERROR) << "Could not run chrome.exe."; |
| 76 return kLaunchFailure; |
| 77 } |
| 78 |
| 79 return kOK; |
| 80 } |
OLD | NEW |