OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <windows.h> | 5 #include <windows.h> |
6 #include <tchar.h> | 6 #include <tchar.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" |
13 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
14 #include "chrome/app/client_util.h" | 15 #include "chrome/app/client_util.h" |
15 #include "chrome/browser/chrome_process_finder_win.h" | 16 #include "chrome/browser/chrome_process_finder_win.h" |
16 #include "chrome/browser/policy/policy_path_parser.h" | 17 #include "chrome/browser/policy/policy_path_parser.h" |
17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_paths_internal.h" | 19 #include "chrome/common/chrome_paths_internal.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome_elf/chrome_elf_main.h" | 21 #include "chrome_elf/chrome_elf_main.h" |
21 #include "components/startup_metric_utils/startup_metric_utils.h" | 22 #include "components/startup_metric_utils/startup_metric_utils.h" |
22 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return false; | 72 return false; |
72 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); | 73 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); |
73 | 74 |
74 HWND chrome = chrome::FindRunningChromeWindow(user_data_dir); | 75 HWND chrome = chrome::FindRunningChromeWindow(user_data_dir); |
75 if (!chrome) | 76 if (!chrome) |
76 return false; | 77 return false; |
77 return chrome::AttemptToNotifyRunningChrome(chrome, true) == | 78 return chrome::AttemptToNotifyRunningChrome(chrome, true) == |
78 chrome::NOTIFY_SUCCESS; | 79 chrome::NOTIFY_SUCCESS; |
79 } | 80 } |
80 | 81 |
| 82 // Duplicated from Win8.1 SDK ShellScalingApi.h |
| 83 typedef enum PROCESS_DPI_AWARENESS { |
| 84 PROCESS_DPI_UNAWARE = 0, |
| 85 PROCESS_SYSTEM_DPI_AWARE = 1, |
| 86 PROCESS_PER_MONITOR_DPI_AWARE = 2 |
| 87 } PROCESS_DPI_AWARENESS; |
| 88 |
| 89 typedef enum MONITOR_DPI_TYPE { |
| 90 MDT_EFFECTIVE_DPI = 0, |
| 91 MDT_ANGULAR_DPI = 1, |
| 92 MDT_RAW_DPI = 2, |
| 93 MDT_DEFAULT = MDT_EFFECTIVE_DPI |
| 94 } MONITOR_DPI_TYPE; |
| 95 |
| 96 // Win8.1 supports monitor-specific DPI scaling. |
| 97 bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) { |
| 98 typedef BOOL(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS); |
| 99 SetProcessDpiAwarenessPtr set_process_dpi_awareness_func = |
| 100 reinterpret_cast<SetProcessDpiAwarenessPtr>( |
| 101 GetProcAddress(GetModuleHandleA("user32.dll"), |
| 102 "SetProcessDpiAwarenessInternal")); |
| 103 if (set_process_dpi_awareness_func) { |
| 104 HRESULT hr = set_process_dpi_awareness_func(value); |
| 105 if (SUCCEEDED(hr)) { |
| 106 VLOG(1) << "SetProcessDpiAwareness succeeded."; |
| 107 return true; |
| 108 } else if (hr == E_ACCESSDENIED) { |
| 109 LOG(ERROR) << "Access denied error from SetProcessDpiAwareness. " |
| 110 "Function called twice, or manifest was used."; |
| 111 } |
| 112 } |
| 113 return false; |
| 114 } |
| 115 |
| 116 // This function works for Windows Vista through Win8. Win8.1 must use |
| 117 // SetProcessDpiAwareness[Wrapper] |
| 118 BOOL SetProcessDPIAwareWrapper() { |
| 119 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); |
| 120 SetProcessDPIAwarePtr set_process_dpi_aware_func = |
| 121 reinterpret_cast<SetProcessDPIAwarePtr>( |
| 122 GetProcAddress(GetModuleHandleA("user32.dll"), |
| 123 "SetProcessDPIAware")); |
| 124 return set_process_dpi_aware_func && |
| 125 set_process_dpi_aware_func(); |
| 126 } |
| 127 |
| 128 |
| 129 void EnableHighDPISupport() { |
| 130 if (!SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) { |
| 131 SetProcessDPIAwareWrapper(); |
| 132 } |
| 133 } |
| 134 |
81 } // namespace | 135 } // namespace |
82 | 136 |
83 #if !defined(ADDRESS_SANITIZER) | 137 #if !defined(ADDRESS_SANITIZER) |
84 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 138 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
85 #else | 139 #else |
86 // The AddressSanitizer build should be a console program as it prints out stuff | 140 // The AddressSanitizer build should be a console program as it prints out stuff |
87 // on stderr. | 141 // on stderr. |
88 int main() { | 142 int main() { |
89 HINSTANCE instance = GetModuleHandle(NULL); | 143 HINSTANCE instance = GetModuleHandle(NULL); |
90 #endif | 144 #endif |
91 startup_metric_utils::RecordExeMainEntryTime(); | 145 startup_metric_utils::RecordExeMainEntryTime(); |
92 | 146 |
93 // Signal Chrome Elf that Chrome has begun to start. | 147 // Signal Chrome Elf that Chrome has begun to start. |
94 SignalChromeElf(); | 148 SignalChromeElf(); |
95 | 149 |
96 // Initialize the commandline singleton from the environment. | 150 // Initialize the commandline singleton from the environment. |
97 CommandLine::Init(0, NULL); | 151 CommandLine::Init(0, NULL); |
98 // The exit manager is in charge of calling the dtors of singletons. | 152 // The exit manager is in charge of calling the dtors of singletons. |
99 base::AtExitManager exit_manager; | 153 base::AtExitManager exit_manager; |
100 | 154 |
101 // We don't want to set DPI awareness on Vista because we don't support | 155 // We don't want to set DPI awareness on Vista because we don't support |
102 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 156 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
103 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 157 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
104 if (base::win::GetVersion() > base::win::VERSION_VISTA) | 158 if (base::win::GetVersion() > base::win::VERSION_VISTA) |
105 gfx::EnableHighDPISupport(); | 159 EnableHighDPISupport(); |
106 | 160 |
107 if (AttemptFastNotify(*CommandLine::ForCurrentProcess())) | 161 if (AttemptFastNotify(*CommandLine::ForCurrentProcess())) |
108 return 0; | 162 return 0; |
109 | 163 |
110 CheckSafeModeLaunch(); | 164 CheckSafeModeLaunch(); |
111 | 165 |
112 // Load and launch the chrome dll. *Everything* happens inside. | 166 // Load and launch the chrome dll. *Everything* happens inside. |
113 MainDllLoader* loader = MakeMainDllLoader(); | 167 MainDllLoader* loader = MakeMainDllLoader(); |
114 int rc = loader->Launch(instance); | 168 int rc = loader->Launch(instance); |
115 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 169 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
116 delete loader; | 170 delete loader; |
117 return rc; | 171 return rc; |
118 } | 172 } |
OLD | NEW |