File: chrome_proxy_main_win.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (78 lines) | stat: -rw-r--r-- 3,009 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <windows.h>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "chrome/common/chrome_switches.h"

namespace {

constexpr base::FilePath::CharType kChromeExecutable[] =
    FILE_PATH_LITERAL("chrome.exe");

constexpr base::FilePath::CharType kChromeProxyExecutable[] =
    FILE_PATH_LITERAL("chrome_proxy.exe");

}  // namespace

// This binary is a workaround for Windows 10 start menu pinning icon bug:
// https://crbug.com/732357.
//
// When a shortcut is pinned in the Windows 10 start menu Windows will follow
// the shortcut, find the target executable, look for a <target>.manifest file
// in the same directory and use the icon specified in there for the start menu
// pin. Because bookmark app shortcuts are shortcuts to Chrome (plus a few
// command line parameters) Windows ends up using the Chrome icon specified in
// chrome.VisualElementsManifest.xml instead of the site's icon stored inside
// the shortcut.
//
// The chrome_proxy.exe binary workaround "fixes" this by having bookmark app
// shortcuts target chrome_proxy.exe instead of chrome.exe such that Windows
// won't find a manifest and falls back to using the shortcut's icons as
// originally intended.
int WINAPI wWinMain(HINSTANCE instance,
                    HINSTANCE prev_instance,
                    wchar_t* /*command_line*/,
                    int show_command) {
  base::CommandLine::Init(0, nullptr);

  logging::LoggingSettings logging_settings;
  logging_settings.logging_dest =
      logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
  logging::InitLogging(logging_settings);

  base::FilePath chrome_dir;
  CHECK(base::PathService::Get(base::DIR_EXE, &chrome_dir));
  base::CommandLine chrome_command_line(chrome_dir.Append(kChromeExecutable));

  // Forward all command line arguments.
  const std::vector<std::wstring>& argv =
      base::CommandLine::ForCurrentProcess()->argv();
  // The first one is always the current executable path.
  CHECK(argv.size() > 0);
  CHECK_EQ(base::FilePath(argv[0]).BaseName().value(), kChromeProxyExecutable);
  for (size_t i = 1; i < argv.size(); ++i)
    chrome_command_line.AppendArgNative(argv[i]);

  // Pass to Chrome the path of the shortcut, if any, that launched
  // chrome_proxy.exe. This is used to record LaunchMode metrics.
  STARTUPINFOW si = {sizeof(si)};
  ::GetStartupInfoW(&si);
  if (si.dwFlags & STARTF_TITLEISLINKNAME) {
    chrome_command_line.AppendSwitchNative(switches::kSourceShortcut,
                                           si.lpTitle);
  }

  base::LaunchOptions launch_options;
  launch_options.current_directory = chrome_dir;
  launch_options.grant_foreground_privilege = true;
  CHECK(base::LaunchProcess(chrome_command_line, launch_options).IsValid());

  return 0;
}