1 // Copyright 2018 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.
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"
15 constexpr base::FilePath::CharType kChromeExecutable[] =
16 FILE_PATH_LITERAL("chrome.exe");
18 constexpr base::FilePath::CharType kChromeProxyExecutable[] =
19 FILE_PATH_LITERAL("chrome_proxy.exe");
23 // This binary is a workaround for Windows 10 start menu pinning icon bug:
24 // https://crbug.com/732357.
26 // When a shortcut is pinned in the Windows 10 start menu Windows will follow
27 // the shortcut, find the target executable, look for a <target>.manifest file
28 // in the same directory and use the icon specified in there for the start menu
29 // pin. Because bookmark app shortcuts are shortcuts to Chrome (plus a few
30 // command line parameters) Windows ends up using the Chrome icon specified in
31 // chrome.exe.manifest instead of the site's icon stored inside the shortcut.
33 // The chrome_proxy.exe binary workaround "fixes" this by having bookmark app
34 // shortcuts target chrome_proxy.exe instead of chrome.exe such that Windows
35 // won't find a manifest and falls back to using the shortcut's icons as
36 // originally intended.
37 int WINAPI wWinMain(HINSTANCE instance,
38 HINSTANCE prev_instance,
39 wchar_t* /*command_line*/,
41 base::CommandLine::Init(0, nullptr);
43 logging::LoggingSettings logging_settings;
44 logging_settings.logging_dest =
45 logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
46 logging::InitLogging(logging_settings);
48 base::FilePath chrome_dir;
49 CHECK(base::PathService::Get(base::DIR_EXE, &chrome_dir));
50 base::CommandLine chrome_command_line(chrome_dir.Append(kChromeExecutable));
52 // Forward all command line arguments.
53 const std::vector<base::string16>& argv =
54 base::CommandLine::ForCurrentProcess()->argv();
55 // The first one is always the current executable path.
56 CHECK(argv.size() > 0);
57 CHECK_EQ(base::FilePath(argv[0]).BaseName().value(), kChromeProxyExecutable);
58 for (size_t i = 1; i < argv.size(); ++i)
59 chrome_command_line.AppendArgNative(argv[i]);
61 base::LaunchOptions launch_options;
62 launch_options.current_directory = chrome_dir;
63 launch_options.grant_foreground_privilege = true;
64 CHECK(base::LaunchProcess(chrome_command_line, launch_options).IsValid());