1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "base/process/launch.h"
12 #include "chrome/common/chrome_switches.h"
16 constexpr base::FilePath::CharType kChromeExecutable[] =
17 FILE_PATH_LITERAL("chrome.exe");
19 constexpr base::FilePath::CharType kChromeProxyExecutable[] =
20 FILE_PATH_LITERAL("chrome_proxy.exe");
24 // This binary is a workaround for Windows 10 start menu pinning icon bug:
25 // https://crbug.com/732357.
27 // When a shortcut is pinned in the Windows 10 start menu Windows will follow
28 // the shortcut, find the target executable, look for a <target>.manifest file
29 // in the same directory and use the icon specified in there for the start menu
30 // pin. Because bookmark app shortcuts are shortcuts to Chrome (plus a few
31 // command line parameters) Windows ends up using the Chrome icon specified in
32 // chrome.VisualElementsManifest.xml instead of the site's icon stored inside
35 // The chrome_proxy.exe binary workaround "fixes" this by having bookmark app
36 // shortcuts target chrome_proxy.exe instead of chrome.exe such that Windows
37 // won't find a manifest and falls back to using the shortcut's icons as
38 // originally intended.
39 int WINAPI wWinMain(HINSTANCE instance,
40 HINSTANCE prev_instance,
41 wchar_t* /*command_line*/,
43 base::CommandLine::Init(0, nullptr);
45 logging::LoggingSettings logging_settings;
46 logging_settings.logging_dest =
47 logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
48 logging::InitLogging(logging_settings);
50 base::FilePath chrome_dir;
51 CHECK(base::PathService::Get(base::DIR_EXE, &chrome_dir));
52 base::CommandLine chrome_command_line(chrome_dir.Append(kChromeExecutable));
54 // Forward all command line arguments.
55 const std::vector<std::wstring>& argv =
56 base::CommandLine::ForCurrentProcess()->argv();
57 // The first one is always the current executable path.
58 CHECK(argv.size() > 0);
59 CHECK_EQ(base::FilePath(argv[0]).BaseName().value(), kChromeProxyExecutable);
60 for (size_t i = 1; i < argv.size(); ++i)
61 chrome_command_line.AppendArgNative(argv[i]);
63 // Pass to Chrome the path of the shortcut, if any, that launched
64 // chrome_proxy.exe. This is used to record LaunchMode metrics.
65 STARTUPINFOW si = {sizeof(si)};
66 ::GetStartupInfoW(&si);
67 if (si.dwFlags & STARTF_TITLEISLINKNAME) {
68 chrome_command_line.AppendSwitchNative(switches::kSourceShortcut,
72 base::LaunchOptions launch_options;
73 launch_options.current_directory = chrome_dir;
74 launch_options.grant_foreground_privilege = true;
75 CHECK(base::LaunchProcess(chrome_command_line, launch_options).IsValid());