Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
grt (UTC plus 2)
2011/05/25 16:10:07
2011
robertshield
2011/05/26 15:14:28
Done.
| |
| 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 // chrome_frame_helper_main.cc : The .exe that bootstraps the | 5 // chrome_frame_helper_main.cc : The .exe that bootstraps the |
| 6 // chrome_frame_helper.dll. | 6 // chrome_frame_helper.dll. |
| 7 // | 7 // |
| 8 // This is a small exe that loads the hook dll to set the event hooks and then | 8 // This is a small exe that loads the hook dll to set the event hooks and then |
| 9 // waits in a message loop. It is intended to be shut down by looking for a | 9 // waits in a message loop. It is intended to be shut down by looking for a |
| 10 // window with the class and title | 10 // window with the class and title |
| 11 // kChromeFrameHelperWindowClassName and kChromeFrameHelperWindowName and then | 11 // kChromeFrameHelperWindowClassName and kChromeFrameHelperWindowName and then |
| 12 // sending that window a WM_CLOSE message. | 12 // sending that window a WM_CLOSE message. |
| 13 // | 13 // |
| 14 | 14 |
| 15 #include <crtdbg.h> | 15 #include <crtdbg.h> |
| 16 #include <objbase.h> | |
| 16 #include <windows.h> | 17 #include <windows.h> |
| 18 #include <string> | |
| 17 | 19 |
| 18 #include "chrome_frame/crash_server_init.h" | 20 #include "chrome_frame/crash_server_init.h" |
| 21 #include "chrome_frame/chrome_frame_helper_util.h" | |
|
grt (UTC plus 2)
2011/05/25 16:10:07
move this above the previous line
robertshield
2011/05/26 15:14:28
Done.
| |
| 19 | 22 |
| 20 // Window class and window names. | 23 // Window class and window names. |
|
grt (UTC plus 2)
2011/05/25 16:10:07
nit: wrap as much of this as reasonable in namespa
robertshield
2011/05/26 15:14:28
Done.
| |
| 21 const wchar_t kChromeFrameHelperWindowClassName[] = | 24 const wchar_t kChromeFrameHelperWindowClassName[] = |
| 22 L"ChromeFrameHelperWindowClass"; | 25 L"ChromeFrameHelperWindowClass"; |
| 23 const wchar_t kChromeFrameHelperWindowName[] = | 26 const wchar_t kChromeFrameHelperWindowName[] = |
| 24 L"ChromeFrameHelperWindowName"; | 27 L"ChromeFrameHelperWindowName"; |
| 25 | 28 |
| 29 const wchar_t kChromeFrameClientStateKey[] = | |
| 30 L"Software\\Google\\Update\\ClientState\\" | |
| 31 L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}\\"; | |
|
grt (UTC plus 2)
2011/05/25 16:10:07
nit: I don't think we usually have a trailing sepa
robertshield
2011/05/26 15:14:28
Done.
| |
| 32 const wchar_t kChromeFrameUninstallCmdExeValue[] = L"UninstallString"; | |
| 33 const wchar_t kChromeFrameUninstallCmdArgsValue[] = L"UninstallArguments"; | |
| 34 | |
| 35 const wchar_t kFirstRunArg[] = L"--first-run"; | |
| 36 const wchar_t kForceUninstall[] = L"--force-uninstall"; | |
| 37 | |
| 26 // Small helper class that assists in loading the DLL that contains code | 38 // Small helper class that assists in loading the DLL that contains code |
| 27 // to register our event hook callback. Automatically removes the hook and | 39 // to register our event hook callback. Automatically removes the hook and |
| 28 // unloads the DLL on destruction. | 40 // unloads the DLL on destruction. |
| 29 class HookDllLoader { | 41 class HookDllLoader { |
| 30 public: | 42 public: |
| 31 HookDllLoader() : dll_(NULL), start_proc_(NULL), stop_proc_(NULL) {} | 43 HookDllLoader() : dll_(NULL), start_proc_(NULL), stop_proc_(NULL) {} |
| 32 ~HookDllLoader() { | 44 ~HookDllLoader() { |
| 33 if (dll_) { | 45 if (dll_) { |
| 34 Unload(); | 46 Unload(); |
| 35 } | 47 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 wcex.lpszClassName = kChromeFrameHelperWindowClassName; | 138 wcex.lpszClassName = kChromeFrameHelperWindowClassName; |
| 127 RegisterClassEx(&wcex); | 139 RegisterClassEx(&wcex); |
| 128 | 140 |
| 129 HWND hwnd = CreateWindow(kChromeFrameHelperWindowClassName, | 141 HWND hwnd = CreateWindow(kChromeFrameHelperWindowClassName, |
| 130 kChromeFrameHelperWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, | 142 kChromeFrameHelperWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, |
| 131 CW_USEDEFAULT, 0, NULL, NULL, hinstance, NULL); | 143 CW_USEDEFAULT, 0, NULL, NULL, hinstance, NULL); |
| 132 | 144 |
| 133 return hwnd; | 145 return hwnd; |
| 134 } | 146 } |
| 135 | 147 |
| 148 | |
| 149 // This method runs the user-level Chrome Frame uninstall command. This is | |
| 150 // intended to allow it to delegate to an existing system-level install. | |
| 151 bool UninstallUserLevelChromeFrame() { | |
| 152 bool success = false; | |
| 153 HKEY reg_handle = NULL; | |
| 154 wchar_t reg_path_buffer[MAX_PATH] = {0}; | |
| 155 LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, | |
| 156 kChromeFrameClientStateKey, | |
| 157 0, | |
| 158 KEY_READ, | |
|
grt (UTC plus 2)
2011/05/25 16:10:07
KEY_READ -> KEY_QUERY_VALUE
robertshield
2011/05/26 15:14:28
Done.
| |
| 159 ®_handle); | |
| 160 if (result == ERROR_SUCCESS) { | |
| 161 wchar_t exe_buffer[MAX_PATH] = {0}; | |
| 162 wchar_t args_buffer[MAX_PATH] = {0}; | |
| 163 LONG exe_result = ReadValue(reg_handle, | |
| 164 kChromeFrameUninstallCmdExeValue, | |
| 165 MAX_PATH, | |
| 166 exe_buffer); | |
| 167 LONG args_result = ReadValue(reg_handle, | |
| 168 kChromeFrameUninstallCmdArgsValue, | |
| 169 MAX_PATH, | |
| 170 args_buffer); | |
| 171 | |
|
grt (UTC plus 2)
2011/05/25 16:10:07
Consider moving RegCloseKey(reg_handle); reg_handl
robertshield
2011/05/26 15:14:28
Done.
| |
| 172 if (exe_result == ERROR_SUCCESS && args_result == ERROR_SUCCESS) { | |
| 173 STARTUPINFO startup_info = {0}; | |
| 174 startup_info.cb = sizeof(startup_info); | |
| 175 startup_info.dwFlags = STARTF_USESHOWWINDOW; | |
| 176 startup_info.wShowWindow = SW_SHOW; | |
| 177 PROCESS_INFORMATION process_info = {0}; | |
| 178 | |
| 179 // Quote the command string in the args. | |
| 180 std::wstring args(L"\""); | |
|
amit
2011/05/24 22:36:50
nit: size concern - if we are using std::string ju
grt (UTC plus 2)
2011/05/25 16:10:07
Agreed. The rest of the code seems to bend over t
robertshield
2011/05/26 15:14:28
Done.
robertshield
2011/05/26 15:14:28
Done.
| |
| 181 args += exe_buffer; | |
| 182 args += L"\" "; | |
| 183 args += args_buffer; | |
| 184 // Make sure the uninstall is silent. | |
| 185 args += L"\" "; | |
| 186 args += kForceUninstall; | |
| 187 | |
| 188 if (CreateProcess(exe_buffer, &args[0], | |
| 189 NULL, NULL, FALSE, 0, NULL, NULL, | |
| 190 &startup_info, &process_info)) { | |
| 191 // Close handles. | |
| 192 CloseHandle(process_info.hThread); | |
| 193 CloseHandle(process_info.hProcess); | |
| 194 success = true; | |
| 195 } | |
| 196 } | |
| 197 RegCloseKey(reg_handle); | |
| 198 } | |
| 199 | |
| 200 return success; | |
| 201 } | |
| 202 | |
| 203 | |
| 136 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE, wchar_t*, int show_cmd) { | 204 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE, wchar_t*, int show_cmd) { |
| 137 const wchar_t* cmd_line = ::GetCommandLine(); | 205 const wchar_t* cmd_line = ::GetCommandLine(); |
| 138 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad( | 206 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad( |
| 139 InitializeCrashReporting(cmd_line)); | 207 InitializeCrashReporting(cmd_line)); |
| 140 | 208 |
| 209 if (IsSystemLevelChromeFrameInstalled()) { | |
| 210 // If we're running at startup, check for system-level Chrome Frame | |
| 211 // installations. If we have one, time | |
| 212 // to bail, also schedule user-level CF to be uninstalled at next logon. | |
| 213 const wchar_t* cmd_line = ::GetCommandLine(); | |
| 214 if (cmd_line && wcsstr(cmd_line, kFirstRunArg) != NULL) { | |
| 215 bool uninstalled = UninstallUserLevelChromeFrame(); | |
| 216 _ASSERTE(uninstalled); | |
| 217 } | |
| 218 return 0; | |
| 219 } | |
| 220 | |
| 141 // Create a window with a known class and title just to listen for WM_CLOSE | 221 // Create a window with a known class and title just to listen for WM_CLOSE |
| 142 // messages that will shut us down. | 222 // messages that will shut us down. |
| 143 HWND hwnd = RegisterAndCreateWindow(hinstance); | 223 HWND hwnd = RegisterAndCreateWindow(hinstance); |
| 144 _ASSERTE(hwnd); | 224 _ASSERTE(hwnd); |
| 145 | 225 |
| 146 // Load the hook dll, and set the event hooks. | 226 // Load the hook dll, and set the event hooks. |
| 147 HookDllLoader loader; | 227 HookDllLoader loader; |
| 148 bool loaded = loader.Load(); | 228 bool loaded = loader.Load(); |
| 149 _ASSERTE(loaded); | 229 _ASSERTE(loaded); |
| 150 | 230 |
| 151 if (loaded) { | 231 if (loaded) { |
| 152 MSG msg; | 232 MSG msg; |
| 153 BOOL ret; | 233 BOOL ret; |
| 154 // Main message loop: | 234 // Main message loop: |
| 155 while ((ret = GetMessage(&msg, NULL, 0, 0))) { | 235 while ((ret = GetMessage(&msg, NULL, 0, 0))) { |
| 156 if (ret == -1) { | 236 if (ret == -1) { |
| 157 break; | 237 break; |
| 158 } else { | 238 } else { |
| 159 TranslateMessage(&msg); | 239 TranslateMessage(&msg); |
| 160 DispatchMessage(&msg); | 240 DispatchMessage(&msg); |
| 161 } | 241 } |
| 162 } | 242 } |
| 163 } | 243 } |
| 164 | 244 |
| 165 UnregisterClass(kChromeFrameHelperWindowClassName, hinstance); | 245 UnregisterClass(kChromeFrameHelperWindowClassName, hinstance); |
| 166 return 0; | 246 return 0; |
| 167 } | 247 } |
| OLD | NEW |