| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome_frame/chrome_frame_helper_util.h" |
| 6 |
| 7 #include <shlwapi.h> |
| 8 |
| 9 const wchar_t kGetBrowserMessage[] = L"GetAutomationObject"; |
| 10 |
| 11 bool UtilIsWebBrowserWindow(HWND window_to_check) { |
| 12 bool is_browser_window = false; |
| 13 |
| 14 if (!IsWindow(window_to_check)) { |
| 15 return is_browser_window; |
| 16 } |
| 17 |
| 18 static wchar_t* known_ie_window_classes[] = { |
| 19 L"IEFrame", |
| 20 L"TabWindowClass" |
| 21 }; |
| 22 |
| 23 for (int i = 0; i < ARRAYSIZE(known_ie_window_classes); i++) { |
| 24 if (IsWindowOfClass(window_to_check, known_ie_window_classes[i])) { |
| 25 is_browser_window = true; |
| 26 break; |
| 27 } |
| 28 } |
| 29 |
| 30 return is_browser_window; |
| 31 } |
| 32 |
| 33 HRESULT UtilGetWebBrowserObjectFromWindow(HWND window, |
| 34 REFIID iid, |
| 35 void** web_browser_object) { |
| 36 if (NULL == web_browser_object) { |
| 37 return E_POINTER; |
| 38 } |
| 39 |
| 40 // Check whether this window is really a web browser window. |
| 41 if (UtilIsWebBrowserWindow(window)) { |
| 42 // IWebBroswer2 interface pointer can be retrieved from the browser |
| 43 // window by simply sending a registered message "GetAutomationObject" |
| 44 // Note that since we are sending a message to parent window make sure that |
| 45 // it is in the same thread. |
| 46 if (GetWindowThreadProcessId(window, NULL) != GetCurrentThreadId()) { |
| 47 return E_UNEXPECTED; |
| 48 } |
| 49 |
| 50 static const ULONG get_browser_message = |
| 51 RegisterWindowMessageW(kGetBrowserMessage); |
| 52 |
| 53 *web_browser_object = |
| 54 reinterpret_cast<void*>(SendMessage(window, |
| 55 get_browser_message, |
| 56 reinterpret_cast<WPARAM>(&iid), |
| 57 NULL)); |
| 58 if (NULL != *web_browser_object) { |
| 59 return S_OK; |
| 60 } |
| 61 } else { |
| 62 return E_INVALIDARG; |
| 63 } |
| 64 return E_NOINTERFACE; |
| 65 } |
| 66 |
| 67 |
| 68 bool IsWindowOfClass(HWND window_to_check, const wchar_t* window_class) { |
| 69 bool window_matches = false; |
| 70 const int buf_size = MAX_PATH; |
| 71 wchar_t buffer[buf_size] = {0}; |
| 72 DWORD dwRetSize = GetClassNameW(window_to_check, buffer, buf_size); |
| 73 // If the window name is any longer than this, it isn't the one we want. |
| 74 if (dwRetSize < (buf_size - 1)) { |
| 75 if (0 == lstrcmpiW(window_class, buffer)) { |
| 76 window_matches = true; |
| 77 } |
| 78 } |
| 79 return window_matches; |
| 80 } |
| 81 |
| 82 |
| 83 bool IsNamedProcess(const wchar_t* process_name) { |
| 84 wchar_t file_path[2048] = {0}; |
| 85 GetModuleFileName(NULL, file_path, 2047); |
| 86 wchar_t* file_name = PathFindFileName(file_path); |
| 87 return (0 == lstrcmpiW(file_name, process_name)); |
| 88 } |
| OLD | NEW |