diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 15:34:11 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 15:34:11 +0000 |
commit | 9ceda77323dcc335680d3cb47b0b76e2821199ad (patch) | |
tree | f5280e2a394d7d66a035b57d2c6b835bcbd7057b /chrome_frame/chrome_frame_helper_util.cc | |
parent | cf993864f9e684fb2e58f5b89d669ae680feefd9 (diff) | |
download | chromium_src-9ceda77323dcc335680d3cb47b0b76e2821199ad.zip chromium_src-9ceda77323dcc335680d3cb47b0b76e2821199ad.tar.gz chromium_src-9ceda77323dcc335680d3cb47b0b76e2821199ad.tar.bz2 |
Add a helper process to Chrome Frame to allow for non-administrative installs. The helper process registers a hook dll that performs the necessary BHO injection instead of registering it in HKLM.
BUG=53127
TEST=Non-admin CF installs work.
Review URL: http://codereview.chromium.org/3158036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57860 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 | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/chrome_frame/chrome_frame_helper_util.cc b/chrome_frame/chrome_frame_helper_util.cc new file mode 100644 index 0000000..d246881 --- /dev/null +++ b/chrome_frame/chrome_frame_helper_util.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2010 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 <shlwapi.h> + +const wchar_t kGetBrowserMessage[] = L"GetAutomationObject"; + +bool UtilIsWebBrowserWindow(HWND window_to_check) { + bool is_browser_window = false; + + if (!IsWindow(window_to_check)) { + return is_browser_window; + } + + static wchar_t* known_ie_window_classes[] = { + L"IEFrame", + L"TabWindowClass" + }; + + for (int i = 0; i < ARRAYSIZE(known_ie_window_classes); i++) { + if (IsWindowOfClass(window_to_check, known_ie_window_classes[i])) { + is_browser_window = true; + break; + } + } + + return is_browser_window; +} + +HRESULT UtilGetWebBrowserObjectFromWindow(HWND window, + REFIID iid, + void** web_browser_object) { + if (NULL == web_browser_object) { + return E_POINTER; + } + + // Check whether this window is really a web browser window. + if (UtilIsWebBrowserWindow(window)) { + // IWebBroswer2 interface pointer can be retrieved from the browser + // window by simply sending a registered message "GetAutomationObject" + // Note that since we are sending a message to parent window make sure that + // it is in the same thread. + if (GetWindowThreadProcessId(window, NULL) != GetCurrentThreadId()) { + return E_UNEXPECTED; + } + + static const ULONG get_browser_message = + RegisterWindowMessageW(kGetBrowserMessage); + + *web_browser_object = + reinterpret_cast<void*>(SendMessage(window, + get_browser_message, + reinterpret_cast<WPARAM>(&iid), + NULL)); + if (NULL != *web_browser_object) { + return S_OK; + } + } else { + return E_INVALIDARG; + } + return E_NOINTERFACE; +} + + +bool IsWindowOfClass(HWND window_to_check, const wchar_t* window_class) { + bool window_matches = false; + const int buf_size = MAX_PATH; + wchar_t buffer[buf_size] = {0}; + DWORD dwRetSize = GetClassNameW(window_to_check, buffer, buf_size); + // If the window name is any longer than this, it isn't the one we want. + if (dwRetSize < (buf_size - 1)) { + if (0 == lstrcmpiW(window_class, buffer)) { + window_matches = true; + } + } + return window_matches; +} + + +bool IsNamedProcess(const wchar_t* process_name) { + wchar_t file_path[2048] = {0}; + GetModuleFileName(NULL, file_path, 2047); + wchar_t* file_name = PathFindFileName(file_path); + return (0 == lstrcmpiW(file_name, process_name)); +} |