From 9283f2789927383ece6aedbd948a645164c35c53 Mon Sep 17 00:00:00 2001 From: "robertshield@chromium.org" Date: Wed, 8 Sep 2010 18:23:30 +0000 Subject: Cause the chrome frame helper process to attempt to close down all other chrome frame helper processes on launch (after setting its own hook). BUG=53127 TEST=You can't start more than one medium/low integrity chrome_frame_helper.exe per desktop. Review URL: http://codereview.chromium.org/3371002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58855 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/chrome_frame_helper_main.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'chrome_frame/chrome_frame_helper_main.cc') diff --git a/chrome_frame/chrome_frame_helper_main.cc b/chrome_frame/chrome_frame_helper_main.cc index 5582261..0b6bc73 100644 --- a/chrome_frame/chrome_frame_helper_main.cc +++ b/chrome_frame/chrome_frame_helper_main.cc @@ -70,12 +70,44 @@ class HookDllLoader { PROC stop_proc_; }; +// Checks the window title and then class of hwnd. If they match with that +// of a chrome_frame_helper.exe window, then add it to the list of windows +// pointed to by lparam. +BOOL CALLBACK CloseHelperWindowsEnumProc(HWND hwnd, LPARAM lparam) { + _ASSERTE(lparam != 0); + + wchar_t title_buffer[MAX_PATH] = {0}; + if (GetWindowText(hwnd, title_buffer, MAX_PATH)) { + if (lstrcmpiW(title_buffer, kChromeFrameHelperWindowName) == 0) { + wchar_t class_buffer[MAX_PATH] = {0}; + if (GetClassName(hwnd, class_buffer, MAX_PATH)) { + if (lstrcmpiW(class_buffer, kChromeFrameHelperWindowClassName) == 0) { + if (hwnd != reinterpret_cast(lparam)) { + PostMessage(hwnd, WM_CLOSE, 0, 0); + } + } + } + } + } + + return TRUE; +} + +// Enumerates all top level windows, looking for those that look like a +// Chrome Frame helper window. It then closes all of them except for +// except_me. +void CloseAllHelperWindowsApartFrom(HWND except_me) { + EnumWindows(CloseHelperWindowsEnumProc, reinterpret_cast(except_me)); +} LRESULT CALLBACK ChromeFrameHelperWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { + case WM_CREATE: + CloseAllHelperWindowsApartFrom(hwnd); + break; case WM_DESTROY: PostQuitMessage(0); break; -- cgit v1.1