| OLD | NEW |
| 1 // Copyright (c) 2010 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 "chrome_frame/chrome_frame_helper_util.h" | 5 #include "chrome_frame/chrome_frame_helper_util.h" |
| 6 #include "chrome_tab.h" // NOLINT |
| 6 | 7 |
| 7 #include <shlwapi.h> | 8 #include <shlwapi.h> |
| 9 #include <stdio.h> |
| 10 |
| 11 namespace { |
| 8 | 12 |
| 9 const wchar_t kGetBrowserMessage[] = L"GetAutomationObject"; | 13 const wchar_t kGetBrowserMessage[] = L"GetAutomationObject"; |
| 10 | 14 |
| 15 const wchar_t kBHORegistrationPathFmt[] = |
| 16 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer" |
| 17 L"\\Browser Helper Objects\\%s"; |
| 18 const wchar_t kChromeFrameClientKey[] = |
| 19 L"Software\\Google\\Update\\Clients\\" |
| 20 L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; |
| 21 const wchar_t kGoogleUpdateVersionValue[] = L"pv"; |
| 22 |
| 23 } // namespace |
| 24 |
| 11 bool UtilIsWebBrowserWindow(HWND window_to_check) { | 25 bool UtilIsWebBrowserWindow(HWND window_to_check) { |
| 12 bool is_browser_window = false; | 26 bool is_browser_window = false; |
| 13 | 27 |
| 14 if (!IsWindow(window_to_check)) { | 28 if (!IsWindow(window_to_check)) { |
| 15 return is_browser_window; | 29 return is_browser_window; |
| 16 } | 30 } |
| 17 | 31 |
| 18 static wchar_t* known_ie_window_classes[] = { | 32 static wchar_t* known_ie_window_classes[] = { |
| 19 L"IEFrame", | 33 L"IEFrame", |
| 20 L"TabWindowClass" | 34 L"TabWindowClass" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 DWORD thread_id_to_match, | 192 DWORD thread_id_to_match, |
| 179 DWORD process_id_to_match) { | 193 DWORD process_id_to_match) { |
| 180 if ((class_name == NULL) && (window_name == NULL)) { | 194 if ((class_name == NULL) && (window_name == NULL)) { |
| 181 return NULL; | 195 return NULL; |
| 182 } | 196 } |
| 183 FindWindowParams params(parent, class_name, window_name, | 197 FindWindowParams params(parent, class_name, window_name, |
| 184 thread_id_to_match, process_id_to_match); | 198 thread_id_to_match, process_id_to_match); |
| 185 EnumChildWindows(parent, WndEnumProc, reinterpret_cast<LPARAM>(¶ms)); | 199 EnumChildWindows(parent, WndEnumProc, reinterpret_cast<LPARAM>(¶ms)); |
| 186 return params.window_found_; | 200 return params.window_found_; |
| 187 } | 201 } |
| 202 |
| 203 // TODO(robertshield): This is stolen shamelessly from mini_installer.cc. |
| 204 // Refactor this before (more) bad things happen. |
| 205 LONG ReadValue(HKEY key, |
| 206 const wchar_t* value_name, |
| 207 size_t value_size, |
| 208 wchar_t* value) { |
| 209 DWORD type; |
| 210 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t)); |
| 211 LONG result = ::RegQueryValueEx(key, value_name, NULL, &type, |
| 212 reinterpret_cast<BYTE*>(value), |
| 213 &byte_length); |
| 214 if (result == ERROR_SUCCESS) { |
| 215 if (type != REG_SZ) { |
| 216 result = ERROR_NOT_SUPPORTED; |
| 217 } else if (byte_length == 0) { |
| 218 *value = L'\0'; |
| 219 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') { |
| 220 if ((byte_length / sizeof(wchar_t)) < value_size) |
| 221 value[byte_length / sizeof(wchar_t)] = L'\0'; |
| 222 else |
| 223 result = ERROR_MORE_DATA; |
| 224 } |
| 225 } |
| 226 return result; |
| 227 } |
| 228 |
| 229 bool IsBHOLoadingPolicyRegistered() { |
| 230 wchar_t bho_clsid_as_string[MAX_PATH] = {0}; |
| 231 int count = StringFromGUID2(CLSID_ChromeFrameBHO, bho_clsid_as_string, |
| 232 ARRAYSIZE(bho_clsid_as_string)); |
| 233 |
| 234 bool bho_registered = false; |
| 235 if (count > 0) { |
| 236 wchar_t reg_path_buffer[MAX_PATH] = {0}; |
| 237 int path_count = _snwprintf(reg_path_buffer, |
| 238 MAX_PATH - 1, |
| 239 kBHORegistrationPathFmt, |
| 240 bho_clsid_as_string); |
| 241 |
| 242 if (path_count > 0) { |
| 243 HKEY reg_handle = NULL; |
| 244 LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
| 245 reg_path_buffer, |
| 246 0, |
| 247 KEY_QUERY_VALUE, |
| 248 ®_handle); |
| 249 if (result == ERROR_SUCCESS) { |
| 250 RegCloseKey(reg_handle); |
| 251 bho_registered = true; |
| 252 } |
| 253 } |
| 254 } |
| 255 |
| 256 return bho_registered; |
| 257 } |
| 258 |
| 259 bool IsSystemLevelChromeFrameInstalled() { |
| 260 bool system_level_installed = false; |
| 261 HKEY reg_handle = NULL; |
| 262 LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
| 263 kChromeFrameClientKey, |
| 264 0, |
| 265 KEY_QUERY_VALUE, |
| 266 ®_handle); |
| 267 if (result == ERROR_SUCCESS) { |
| 268 wchar_t version_buffer[MAX_PATH] = {0}; |
| 269 result = ReadValue(reg_handle, |
| 270 kGoogleUpdateVersionValue, |
| 271 MAX_PATH, |
| 272 version_buffer); |
| 273 if (result == ERROR_SUCCESS && version_buffer[0] != L'\0') { |
| 274 system_level_installed = true; |
| 275 } |
| 276 RegCloseKey(reg_handle); |
| 277 } |
| 278 |
| 279 return system_level_installed; |
| 280 } |
| 281 |
| OLD | NEW |