diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 16:44:31 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 16:44:31 +0000 |
commit | 6a7748e79cb7118089d5857291cb76d57c5c8162 (patch) | |
tree | bdfe13aba5f79d4c090bd27fdf75173ff751bb3c /chrome_frame/chrome_frame_helper_util.cc | |
parent | 13ffa32ea65d5fda56bcb030643b989d5564c586 (diff) | |
download | chromium_src-6a7748e79cb7118089d5857291cb76d57c5c8162.zip chromium_src-6a7748e79cb7118089d5857291cb76d57c5c8162.tar.gz chromium_src-6a7748e79cb7118089d5857291cb76d57c5c8162.tar.bz2 |
Add a self-destruct mechanism to user-level Chrome Frame when it detects that system-level Chrome Frame is present. This is a first step to handling user-to-system-level handoff.
It will cause a user-level install to be correctly replaced with a system-level one once the user logs out and back in again. Additional changelists
will follow that:
1) Ensure full clean-up of the user-level installation.
2) Handle notifications such that logging out and in again isn't required.
BUG=82816
TEST=Install user-level Chrome Frame.
Review URL: http://codereview.chromium.org/7065024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87033 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/chrome_frame_helper_util.cc')
-rw-r--r-- | chrome_frame/chrome_frame_helper_util.cc | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/chrome_frame/chrome_frame_helper_util.cc b/chrome_frame/chrome_frame_helper_util.cc index 87f0efc..333fc96 100644 --- a/chrome_frame/chrome_frame_helper_util.cc +++ b/chrome_frame/chrome_frame_helper_util.cc @@ -1,13 +1,27 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome_frame/chrome_frame_helper_util.h" +#include "chrome_tab.h" // NOLINT #include <shlwapi.h> +#include <stdio.h> + +namespace { const wchar_t kGetBrowserMessage[] = L"GetAutomationObject"; +const wchar_t kBHORegistrationPathFmt[] = + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer" + L"\\Browser Helper Objects\\%s"; +const wchar_t kChromeFrameClientKey[] = + L"Software\\Google\\Update\\Clients\\" + L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; +const wchar_t kGoogleUpdateVersionValue[] = L"pv"; + +} // namespace + bool UtilIsWebBrowserWindow(HWND window_to_check) { bool is_browser_window = false; @@ -185,3 +199,83 @@ HWND RecurseFindWindow(HWND parent, EnumChildWindows(parent, WndEnumProc, reinterpret_cast<LPARAM>(¶ms)); return params.window_found_; } + +// TODO(robertshield): This is stolen shamelessly from mini_installer.cc. +// Refactor this before (more) bad things happen. +LONG ReadValue(HKEY key, + const wchar_t* value_name, + size_t value_size, + wchar_t* value) { + DWORD type; + DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t)); + LONG result = ::RegQueryValueEx(key, value_name, NULL, &type, + reinterpret_cast<BYTE*>(value), + &byte_length); + if (result == ERROR_SUCCESS) { + if (type != REG_SZ) { + result = ERROR_NOT_SUPPORTED; + } else if (byte_length == 0) { + *value = L'\0'; + } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') { + if ((byte_length / sizeof(wchar_t)) < value_size) + value[byte_length / sizeof(wchar_t)] = L'\0'; + else + result = ERROR_MORE_DATA; + } + } + return result; +} + +bool IsBHOLoadingPolicyRegistered() { + wchar_t bho_clsid_as_string[MAX_PATH] = {0}; + int count = StringFromGUID2(CLSID_ChromeFrameBHO, bho_clsid_as_string, + ARRAYSIZE(bho_clsid_as_string)); + + bool bho_registered = false; + if (count > 0) { + wchar_t reg_path_buffer[MAX_PATH] = {0}; + int path_count = _snwprintf(reg_path_buffer, + MAX_PATH - 1, + kBHORegistrationPathFmt, + bho_clsid_as_string); + + if (path_count > 0) { + HKEY reg_handle = NULL; + LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + reg_path_buffer, + 0, + KEY_QUERY_VALUE, + ®_handle); + if (result == ERROR_SUCCESS) { + RegCloseKey(reg_handle); + bho_registered = true; + } + } + } + + return bho_registered; +} + +bool IsSystemLevelChromeFrameInstalled() { + bool system_level_installed = false; + HKEY reg_handle = NULL; + LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + kChromeFrameClientKey, + 0, + KEY_QUERY_VALUE, + ®_handle); + if (result == ERROR_SUCCESS) { + wchar_t version_buffer[MAX_PATH] = {0}; + result = ReadValue(reg_handle, + kGoogleUpdateVersionValue, + MAX_PATH, + version_buffer); + if (result == ERROR_SUCCESS && version_buffer[0] != L'\0') { + system_level_installed = true; + } + RegCloseKey(reg_handle); + } + + return system_level_installed; +} + |