Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/test/chrome_frame_test_utils.h" | 5 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlwin.h> | 8 #include <atlwin.h> |
| 9 #include <iepmapi.h> | 9 #include <iepmapi.h> |
| 10 #include <sddl.h> | 10 #include <sddl.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 namespace chrome_frame_test { | 22 namespace chrome_frame_test { |
| 23 | 23 |
| 24 const wchar_t kIEImageName[] = L"iexplore.exe"; | 24 const wchar_t kIEImageName[] = L"iexplore.exe"; |
| 25 const wchar_t kIEBrokerImageName[] = L"ieuser.exe"; | 25 const wchar_t kIEBrokerImageName[] = L"ieuser.exe"; |
| 26 const wchar_t kFirefoxImageName[] = L"firefox.exe"; | 26 const wchar_t kFirefoxImageName[] = L"firefox.exe"; |
| 27 const wchar_t kOperaImageName[] = L"opera.exe"; | 27 const wchar_t kOperaImageName[] = L"opera.exe"; |
| 28 const wchar_t kSafariImageName[] = L"safari.exe"; | 28 const wchar_t kSafariImageName[] = L"safari.exe"; |
| 29 const wchar_t kChromeImageName[] = L"chrome.exe"; | 29 const wchar_t kChromeImageName[] = L"chrome.exe"; |
| 30 | 30 |
| 31 bool IsTopLevelWindow(HWND window) { | |
| 32 long style = GetWindowLong(window, GWL_STYLE); // NOLINT | |
| 33 if (!(style & WS_CHILD)) | |
| 34 return true; | |
| 35 | |
| 36 HWND parent = GetParent(window); | |
| 37 if (!parent) | |
| 38 return true; | |
| 39 | |
| 40 if (parent == GetDesktopWindow()) | |
| 41 return true; | |
| 42 | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 // Callback function for EnumThreadWindows. | 31 // Callback function for EnumThreadWindows. |
| 47 BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { | 32 BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { |
| 48 int& count = *reinterpret_cast<int*>(param); | 33 int& count = *reinterpret_cast<int*>(param); |
| 49 if (IsWindowVisible(hwnd)) { | 34 if (IsWindowVisible(hwnd)) { |
| 50 if (IsWindowEnabled(hwnd)) { | 35 if (IsWindowEnabled(hwnd)) { |
| 51 DWORD results = 0; | 36 DWORD results = 0; |
| 52 if (!::SendMessageTimeout(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, SMTO_BLOCK, | 37 if (!::SendMessageTimeout(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, SMTO_BLOCK, |
| 53 10000, &results)) { | 38 10000, &results)) { |
| 54 LOG(WARNING) << "Window hung: " << StringPrintf(L"%08X", hwnd); | 39 LOG(WARNING) << "Window hung: " << StringPrintf(L"%08X", hwnd); |
| 55 } | 40 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 window_close_attempts += | 83 window_close_attempts += |
| 99 CloseVisibleTopLevelWindowsOnThread(te.th32ThreadID); | 84 CloseVisibleTopLevelWindowsOnThread(te.th32ThreadID); |
| 100 } | 85 } |
| 101 te.dwSize = sizeof(te); | 86 te.dwSize = sizeof(te); |
| 102 } while (Thread32Next(snapshot, &te)); | 87 } while (Thread32Next(snapshot, &te)); |
| 103 } | 88 } |
| 104 | 89 |
| 105 return window_close_attempts; | 90 return window_close_attempts; |
| 106 } | 91 } |
| 107 | 92 |
| 108 class ForegroundHelperWindow : public CWindowImpl<ForegroundHelperWindow> { | |
| 109 public: | |
| 110 BEGIN_MSG_MAP(ForegroundHelperWindow) | |
| 111 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey) | |
| 112 END_MSG_MAP() | |
| 113 | |
| 114 HRESULT SetForeground(HWND window) { | |
| 115 DCHECK(::IsWindow(window)); | |
| 116 if (NULL == Create(NULL, NULL, NULL, WS_POPUP)) | |
| 117 return AtlHresultFromLastError(); | |
| 118 | |
| 119 static const int kHotKeyId = 0x0000baba; | |
| 120 static const int kHotKeyWaitTimeout = 2000; | |
| 121 | |
| 122 SetWindowLongPtr(GWLP_USERDATA, reinterpret_cast<ULONG_PTR>(window)); | |
| 123 RegisterHotKey(m_hWnd, kHotKeyId, 0, VK_F22); | |
| 124 | |
| 125 MSG msg = {0}; | |
| 126 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); | |
| 127 | |
| 128 SendVirtualKey(VK_F22, false); | |
| 129 // There are scenarios where the WM_HOTKEY is not dispatched by the | |
| 130 // the corresponding foreground thread. To prevent us from indefinitely | |
| 131 // waiting for the hotkey, we set a timer and exit the loop. | |
| 132 SetTimer(kHotKeyId, kHotKeyWaitTimeout, NULL); | |
| 133 | |
| 134 while (GetMessage(&msg, NULL, 0, 0)) { | |
| 135 TranslateMessage(&msg); | |
| 136 DispatchMessage(&msg); | |
| 137 if (msg.message == WM_HOTKEY) | |
| 138 break; | |
| 139 else if (msg.message == WM_TIMER) { | |
| 140 SetForegroundWindow(window); | |
| 141 break; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 UnregisterHotKey(m_hWnd, kHotKeyId); | |
| 146 KillTimer(kHotKeyId); | |
| 147 DestroyWindow(); | |
| 148 return S_OK; | |
| 149 } | |
| 150 | |
| 151 LRESULT OnHotKey(UINT msg, WPARAM wp, LPARAM lp, BOOL& handled) { // NOLINT | |
| 152 HWND window = reinterpret_cast<HWND>(GetWindowLongPtr(GWLP_USERDATA)); | |
| 153 SetForegroundWindow(window); | |
| 154 return 1; | |
| 155 } | |
| 156 }; | |
| 157 | |
| 158 bool ForceSetForegroundWindow(HWND window) { | |
| 159 if (GetForegroundWindow() == window) | |
| 160 return true; | |
| 161 ForegroundHelperWindow foreground_helper_window; | |
| 162 HRESULT hr = foreground_helper_window.SetForeground(window); | |
| 163 return SUCCEEDED(hr); | |
| 164 } | |
| 165 | |
| 166 struct PidAndWindow { | |
| 167 base::ProcessId pid; | |
| 168 HWND hwnd; | |
| 169 }; | |
| 170 | |
| 171 BOOL CALLBACK FindWindowInProcessCallback(HWND hwnd, LPARAM param) { | |
| 172 PidAndWindow* paw = reinterpret_cast<PidAndWindow*>(param); | |
| 173 base::ProcessId pid; | |
| 174 GetWindowThreadProcessId(hwnd, &pid); | |
| 175 if (pid == paw->pid && IsWindowVisible(hwnd)) { | |
| 176 paw->hwnd = hwnd; | |
| 177 return FALSE; | |
| 178 } | |
| 179 | |
| 180 return TRUE; | |
| 181 } | |
| 182 | |
| 183 bool EnsureProcessInForeground(base::ProcessId process_id) { | |
| 184 HWND hwnd = GetForegroundWindow(); | |
| 185 base::ProcessId current_foreground_pid = 0; | |
| 186 DWORD active_thread_id = GetWindowThreadProcessId(hwnd, | |
| 187 ¤t_foreground_pid); | |
| 188 if (current_foreground_pid == process_id) | |
| 189 return true; | |
| 190 | |
| 191 PidAndWindow paw = { process_id }; | |
| 192 EnumWindows(FindWindowInProcessCallback, reinterpret_cast<LPARAM>(&paw)); | |
| 193 if (!IsWindow(paw.hwnd)) { | |
| 194 DLOG(ERROR) << "failed to find process window"; | |
| 195 return false; | |
| 196 } | |
| 197 | |
| 198 bool ret = ForceSetForegroundWindow(paw.hwnd); | |
| 199 LOG_IF(ERROR, !ret) << "ForceSetForegroundWindow: " << ret; | |
| 200 | |
| 201 return ret; | |
| 202 } | |
| 203 | |
| 204 // Iterates through all the characters in the string and simulates | |
| 205 // keyboard input. The input goes to the currently active application. | |
| 206 bool SendString(const wchar_t* string) { | |
| 207 DCHECK(string != NULL); | |
| 208 | |
| 209 INPUT input[2] = {0}; | |
| 210 input[0].type = INPUT_KEYBOARD; | |
| 211 input[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, etc. | |
| 212 input[1] = input[0]; | |
| 213 input[1].ki.dwFlags |= KEYEVENTF_KEYUP; | |
| 214 | |
| 215 for (const wchar_t* p = string; *p; p++) { | |
| 216 input[0].ki.wScan = input[1].ki.wScan = *p; | |
| 217 SendInput(2, input, sizeof(INPUT)); | |
| 218 } | |
| 219 | |
| 220 return true; | |
| 221 } | |
| 222 | |
| 223 void SendVirtualKey(int16 key, bool extended) { | |
| 224 INPUT input = { INPUT_KEYBOARD }; | |
| 225 input.ki.wVk = key; | |
| 226 input.ki.dwFlags = extended ? KEYEVENTF_EXTENDEDKEY : 0; | |
| 227 SendInput(1, &input, sizeof(input)); | |
| 228 input.ki.dwFlags = (extended ? KEYEVENTF_EXTENDEDKEY : 0) | KEYEVENTF_KEYUP; | |
| 229 SendInput(1, &input, sizeof(input)); | |
| 230 } | |
| 231 | |
| 232 void SendChar(char c) { | |
| 233 SendVirtualKey(VkKeyScanA(c), false); | |
| 234 } | |
| 235 | |
| 236 void SendString(const char* s) { | |
| 237 while (*s) { | |
| 238 SendChar(*s); | |
| 239 s++; | |
| 240 } | |
| 241 } | |
| 242 | |
| 243 // Sends a keystroke to the currently active application with optional | |
| 244 // modifiers set. | |
| 245 bool SendMnemonic(WORD mnemonic_char, bool shift_pressed, bool control_pressed, | |
| 246 bool alt_pressed) { | |
| 247 INPUT special_keys[3] = {0}; | |
| 248 for (int index = 0; index < arraysize(special_keys); ++index) { | |
| 249 special_keys[index].type = INPUT_KEYBOARD; | |
| 250 special_keys[index].ki.dwFlags = 0; | |
| 251 } | |
| 252 | |
| 253 int num_special_keys = 0; | |
| 254 if (shift_pressed) { | |
| 255 special_keys[num_special_keys].ki.wVk = VK_SHIFT; | |
| 256 num_special_keys++; | |
| 257 } | |
| 258 | |
| 259 if (control_pressed) { | |
| 260 special_keys[num_special_keys].ki.wVk = VK_CONTROL; | |
| 261 num_special_keys++; | |
| 262 } | |
| 263 | |
| 264 if (alt_pressed) { | |
| 265 special_keys[num_special_keys].ki.wVk = VK_MENU; | |
| 266 num_special_keys++; | |
| 267 } | |
| 268 | |
| 269 // Depress the modifiers. | |
| 270 SendInput(num_special_keys, special_keys, sizeof(INPUT)); | |
| 271 | |
| 272 Sleep(100); | |
| 273 | |
| 274 INPUT mnemonic = {0}; | |
| 275 mnemonic.type = INPUT_KEYBOARD; | |
| 276 mnemonic.ki.wVk = mnemonic_char; | |
| 277 | |
| 278 // Depress and release the mnemonic. | |
| 279 SendInput(1, &mnemonic, sizeof(INPUT)); | |
| 280 Sleep(100); | |
| 281 | |
| 282 mnemonic.ki.dwFlags |= KEYEVENTF_KEYUP; | |
| 283 SendInput(1, &mnemonic, sizeof(INPUT)); | |
| 284 Sleep(100); | |
| 285 | |
| 286 // Now release the modifiers. | |
| 287 for (int index = 0; index < num_special_keys; index++) { | |
| 288 special_keys[index].ki.dwFlags |= KEYEVENTF_KEYUP; | |
| 289 } | |
| 290 | |
| 291 SendInput(num_special_keys, special_keys, sizeof(INPUT)); | |
| 292 Sleep(100); | |
| 293 | |
| 294 return true; | |
| 295 } | |
| 296 | |
| 297 std::wstring GetExecutableAppPath(const std::wstring& file) { | 93 std::wstring GetExecutableAppPath(const std::wstring& file) { |
| 298 std::wstring kAppPathsKey = | 94 std::wstring kAppPathsKey = |
| 299 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; | 95 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; |
| 300 | 96 |
| 301 std::wstring app_path; | 97 std::wstring app_path; |
| 302 RegKey key(HKEY_LOCAL_MACHINE, (kAppPathsKey + file).c_str()); | 98 RegKey key(HKEY_LOCAL_MACHINE, (kAppPathsKey + file).c_str()); |
| 303 if (key.Handle()) { | 99 if (key.Handle()) { |
| 304 key.ReadValue(NULL, &app_path); | 100 key.ReadValue(NULL, &app_path); |
| 305 } | 101 } |
| 306 | 102 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 browser->Quit(); | 212 browser->Quit(); |
| 417 ++ret; | 213 ++ret; |
| 418 } | 214 } |
| 419 } | 215 } |
| 420 } | 216 } |
| 421 } | 217 } |
| 422 | 218 |
| 423 return ret; | 219 return ret; |
| 424 } | 220 } |
| 425 | 221 |
| 426 void ShowChromeFrameContextMenu() { | |
| 427 static const int kChromeFrameContextMenuTimeout = 500; | |
| 428 HWND renderer_window = GetChromeRendererWindow(); | |
| 429 EXPECT_TRUE(IsWindow(renderer_window)); | |
| 430 | |
| 431 SetKeyboardFocusToWindow(renderer_window, 100, 100); | |
| 432 | |
| 433 // Bring up the context menu in the Chrome renderer window. | |
| 434 PostMessage(renderer_window, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(50, 50)); | |
| 435 PostMessage(renderer_window, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(50, 50)); | |
| 436 | |
| 437 MessageLoop::current()->PostDelayedTask( | |
| 438 FROM_HERE, | |
| 439 NewRunnableFunction(SelectAboutChromeFrame), | |
| 440 kChromeFrameContextMenuTimeout); | |
| 441 } | |
| 442 | |
| 443 void SetKeyboardFocusToWindow(HWND window, int x, int y) { | |
| 444 HWND top_level_window = window; | |
| 445 if (!IsTopLevelWindow(top_level_window)) { | |
| 446 top_level_window = GetAncestor(window, GA_ROOT); | |
| 447 } | |
| 448 ForceSetForegroundWindow(top_level_window); | |
| 449 | |
| 450 POINT cursor_position = {130, 130}; | |
| 451 ClientToScreen(window, &cursor_position); | |
| 452 | |
| 453 double screen_width = ::GetSystemMetrics( SM_CXSCREEN ) - 1; | |
| 454 double screen_height = ::GetSystemMetrics( SM_CYSCREEN ) - 1; | |
| 455 double location_x = cursor_position.x * (65535.0f / screen_width); | |
| 456 double location_y = cursor_position.y * (65535.0f / screen_height); | |
| 457 | |
| 458 INPUT input_info = {0}; | |
| 459 input_info.type = INPUT_MOUSE; | |
| 460 input_info.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; | |
| 461 input_info.mi.dx = static_cast<long>(location_x); | |
| 462 input_info.mi.dy = static_cast<long>(location_y); | |
| 463 ::SendInput(1, &input_info, sizeof(INPUT)); | |
| 464 | |
| 465 Sleep(10); | |
| 466 | |
| 467 input_info.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE; | |
| 468 ::SendInput(1, &input_info, sizeof(INPUT)); | |
| 469 | |
| 470 Sleep(10); | |
| 471 | |
| 472 input_info.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE; | |
| 473 ::SendInput(1, &input_info, sizeof(INPUT)); | |
| 474 } | |
| 475 | |
| 476 void SendInputToWindow(HWND window, const std::string& input_string) { | |
| 477 const unsigned long kIntervalBetweenInput = 100; | |
| 478 | |
| 479 for (size_t index = 0; index < input_string.length(); index++) { | |
| 480 bool is_upper_case = isupper(input_string[index]); | |
| 481 if (is_upper_case) { | |
| 482 INPUT input = { INPUT_KEYBOARD }; | |
| 483 input.ki.wVk = VK_SHIFT; | |
| 484 input.ki.dwFlags = 0; | |
| 485 SendInput(1, &input, sizeof(input)); | |
| 486 Sleep(kIntervalBetweenInput); | |
| 487 } | |
| 488 | |
| 489 // The WM_KEYDOWN and WM_KEYUP messages for characters always contain | |
| 490 // the uppercase character codes. | |
| 491 SendVirtualKey(toupper(input_string[index]), false); | |
| 492 Sleep(kIntervalBetweenInput); | |
| 493 | |
| 494 if (is_upper_case) { | |
| 495 INPUT input = { INPUT_KEYBOARD }; | |
| 496 input.ki.wVk = VK_SHIFT; | |
| 497 input.ki.dwFlags = KEYEVENTF_KEYUP; | |
| 498 SendInput(1, &input, sizeof(input)); | |
| 499 Sleep(kIntervalBetweenInput); | |
| 500 } | |
| 501 } | |
| 502 } | |
| 503 | |
| 504 void SelectAboutChromeFrame() { | |
| 505 // Send a key up message to enable the About chrome frame option to be | |
| 506 // selected followed by a return to select it. | |
| 507 SendVirtualKey(VK_UP, true); | |
| 508 SendVirtualKey(VK_RETURN, false); | |
| 509 } | |
| 510 | |
| 511 BOOL CALLBACK FindChromeRendererWindowProc( | |
| 512 HWND window, LPARAM lParam) { | |
| 513 HWND* target_window = reinterpret_cast<HWND*>(lParam); | |
| 514 wchar_t class_name[MAX_PATH] = {0}; | |
| 515 | |
| 516 GetClassName(window, class_name, arraysize(class_name)); | |
| 517 if (!_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND")) { | |
| 518 *target_window = window; | |
| 519 return FALSE; | |
| 520 } | |
| 521 | |
| 522 return TRUE; | |
| 523 } | |
| 524 | |
| 525 BOOL CALLBACK EnumHostBrowserWindowProc( | |
| 526 HWND window, LPARAM lParam) { | |
| 527 EnumChildWindows(window, FindChromeRendererWindowProc, lParam); | |
| 528 HWND* target_window = reinterpret_cast<HWND*>(lParam); | |
| 529 if (IsWindow(*target_window)) | |
| 530 return FALSE; | |
| 531 return TRUE; | |
| 532 } | |
| 533 | |
| 534 HWND GetChromeRendererWindow() { | |
| 535 HWND chrome_window = NULL; | |
| 536 EnumWindows(EnumHostBrowserWindowProc, | |
| 537 reinterpret_cast<LPARAM>(&chrome_window)); | |
| 538 return chrome_window; | |
| 539 } | |
| 540 | |
| 541 | 222 |
| 542 LowIntegrityToken::LowIntegrityToken() : impersonated_(false) { | 223 LowIntegrityToken::LowIntegrityToken() : impersonated_(false) { |
| 543 } | 224 } |
| 544 | 225 |
| 545 LowIntegrityToken::~LowIntegrityToken() { | 226 LowIntegrityToken::~LowIntegrityToken() { |
| 546 RevertToSelf(); | 227 RevertToSelf(); |
| 547 } | 228 } |
| 548 | 229 |
| 549 BOOL LowIntegrityToken::RevertToSelf() { | 230 BOOL LowIntegrityToken::RevertToSelf() { |
| 550 BOOL ok = TRUE; | 231 BOOL ok = TRUE; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 return S_OK; | 476 return S_OK; |
| 796 } | 477 } |
| 797 | 478 |
| 798 HRESULT WebBrowserEventSink::OnLoadErrorInternal(const VARIANT* param) { | 479 HRESULT WebBrowserEventSink::OnLoadErrorInternal(const VARIANT* param) { |
| 799 DLOG(INFO) << __FUNCTION__ << " " << param->bstrVal; | 480 DLOG(INFO) << __FUNCTION__ << " " << param->bstrVal; |
| 800 OnLoadError(param->bstrVal); | 481 OnLoadError(param->bstrVal); |
| 801 return S_OK; | 482 return S_OK; |
| 802 } | 483 } |
| 803 | 484 |
| 804 HRESULT WebBrowserEventSink::OnMessageInternal(const VARIANT* param) { | 485 HRESULT WebBrowserEventSink::OnMessageInternal(const VARIANT* param) { |
| 805 DLOG(INFO) << __FUNCTION__ << " " << param->bstrVal; | 486 DLOG(INFO) << __FUNCTION__ << " " << param; |
| 806 OnMessage(param->bstrVal); | 487 ScopedVariant data, origin, source; |
|
tommi (sloooow) - chröme
2010/02/12 17:14:05
very nice
| |
| 488 if (param && (V_VT(param) == VT_DISPATCH)) { | |
| 489 wchar_t* properties[] = { L"data", L"origin", L"source" }; | |
| 490 const int prop_count = arraysize(properties); | |
| 491 DISPID ids[prop_count] = {0}; | |
| 492 | |
| 493 HRESULT hr = param->pdispVal->GetIDsOfNames(IID_NULL, properties, | |
| 494 prop_count,LOCALE_SYSTEM_DEFAULT , ids); | |
| 495 if (SUCCEEDED(hr)) { | |
| 496 DISPPARAMS params = { 0 }; | |
| 497 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[0], IID_NULL, | |
| 498 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | |
| 499 data.Receive(), NULL, NULL)); | |
| 500 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[1], IID_NULL, | |
| 501 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | |
| 502 origin.Receive(), NULL, NULL)); | |
| 503 EXPECT_HRESULT_SUCCEEDED(param->pdispVal->Invoke(ids[2], IID_NULL, | |
| 504 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, | |
| 505 source.Receive(), NULL, NULL)); | |
| 506 } | |
| 507 } | |
| 508 | |
| 509 OnMessage(V_BSTR(&data), V_BSTR(&origin), V_BSTR(&source)); | |
| 807 return S_OK; | 510 return S_OK; |
| 808 } | 511 } |
| 809 | 512 |
| 810 HRESULT WebBrowserEventSink::LaunchIEAndNavigate( | 513 HRESULT WebBrowserEventSink::LaunchIEAndNavigate( |
| 811 const std::wstring& navigate_url) { | 514 const std::wstring& navigate_url) { |
| 812 HRESULT hr = LaunchIEAsComServer(web_browser2_.Receive()); | 515 HRESULT hr = LaunchIEAsComServer(web_browser2_.Receive()); |
| 813 EXPECT_EQ(S_OK, hr); | 516 EXPECT_EQ(S_OK, hr); |
| 814 if (hr == S_OK) { | 517 if (hr == S_OK) { |
| 815 web_browser2_->put_Visible(VARIANT_TRUE); | 518 web_browser2_->put_Visible(VARIANT_TRUE); |
| 816 hr = DispEventAdvise(web_browser2_, &DIID_DWebBrowserEvents2); | 519 hr = DispEventAdvise(web_browser2_, &DIID_DWebBrowserEvents2); |
| 817 EXPECT_TRUE(hr == S_OK); | 520 EXPECT_TRUE(hr == S_OK); |
| 818 hr = Navigate(navigate_url); | 521 hr = Navigate(navigate_url); |
| 819 } | 522 } |
| 820 return hr; | 523 return hr; |
| 821 } | 524 } |
| 822 | 525 |
| 823 HRESULT WebBrowserEventSink::Navigate(const std::wstring& navigate_url) { | 526 HRESULT WebBrowserEventSink::Navigate(const std::wstring& navigate_url) { |
| 824 VARIANT empty = ScopedVariant::kEmptyVariant; | 527 VARIANT empty = ScopedVariant::kEmptyVariant; |
| 825 ScopedVariant url; | 528 ScopedVariant url; |
| 826 url.Set(navigate_url.c_str()); | 529 url.Set(navigate_url.c_str()); |
| 827 | 530 |
| 828 HRESULT hr = S_OK; | 531 HRESULT hr = S_OK; |
| 829 hr = web_browser2_->Navigate2(url.AsInput(), &empty, &empty, &empty, &empty); | 532 hr = web_browser2_->Navigate2(url.AsInput(), &empty, &empty, &empty, &empty); |
| 830 EXPECT_TRUE(hr == S_OK); | 533 EXPECT_TRUE(hr == S_OK); |
| 831 return hr; | 534 return hr; |
| 832 } | 535 } |
| 833 | 536 |
| 834 void WebBrowserEventSink::SetFocusToChrome() { | 537 void WebBrowserEventSink::SetFocusToChrome() { |
| 835 chrome_frame_test::SetKeyboardFocusToWindow(GetTabWindow(), 1, 1); | 538 simulate_input::SetKeyboardFocusToWindow(GetRendererWindow()); |
| 836 } | 539 } |
| 837 | 540 |
| 838 void WebBrowserEventSink::SendInputToChrome( | 541 void WebBrowserEventSink::SendKeys(const wchar_t* input_string) { |
| 839 const std::string& input_string) { | 542 SetFocusToChrome(); |
| 840 chrome_frame_test::SendInputToWindow(GetTabWindow(), input_string); | 543 simulate_input::SendString(input_string); |
| 544 } | |
| 545 | |
| 546 void WebBrowserEventSink::SendMouseClick(int x, int y, | |
| 547 simulate_input::MouseButton button) { | |
| 548 simulate_input::SendMouseClick(GetRendererWindow(), x, y, button); | |
| 841 } | 549 } |
| 842 | 550 |
| 843 void WebBrowserEventSink::ConnectToChromeFrame() { | 551 void WebBrowserEventSink::ConnectToChromeFrame() { |
| 844 DCHECK(web_browser2_); | 552 DCHECK(web_browser2_); |
| 845 ScopedComPtr<IShellBrowser> shell_browser; | 553 ScopedComPtr<IShellBrowser> shell_browser; |
| 846 DoQueryService(SID_STopLevelBrowser, web_browser2_, | 554 DoQueryService(SID_STopLevelBrowser, web_browser2_, |
| 847 shell_browser.Receive()); | 555 shell_browser.Receive()); |
| 848 | 556 |
| 849 if (shell_browser) { | 557 if (shell_browser) { |
| 850 ScopedComPtr<IShellView> shell_view; | 558 ScopedComPtr<IShellView> shell_view; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 868 void WebBrowserEventSink::DisconnectFromChromeFrame() { | 576 void WebBrowserEventSink::DisconnectFromChromeFrame() { |
| 869 if (chrome_frame_) { | 577 if (chrome_frame_) { |
| 870 ScopedVariant dummy(static_cast<IDispatch*>(NULL)); | 578 ScopedVariant dummy(static_cast<IDispatch*>(NULL)); |
| 871 chrome_frame_->put_onmessage(dummy); | 579 chrome_frame_->put_onmessage(dummy); |
| 872 chrome_frame_->put_onload(dummy); | 580 chrome_frame_->put_onload(dummy); |
| 873 chrome_frame_->put_onloaderror(dummy); | 581 chrome_frame_->put_onloaderror(dummy); |
| 874 chrome_frame_.Release(); | 582 chrome_frame_.Release(); |
| 875 } | 583 } |
| 876 } | 584 } |
| 877 | 585 |
| 878 HWND WebBrowserEventSink::GetTabWindow() { | 586 HWND WebBrowserEventSink::GetRendererWindow() { |
| 879 DCHECK(chrome_frame_); | 587 DCHECK(chrome_frame_); |
| 880 HWND renderer_window = NULL; | 588 HWND renderer_window = NULL; |
| 881 ScopedComPtr<IOleWindow> ole_window; | 589 ScopedComPtr<IOleWindow> ole_window; |
| 882 ole_window.QueryFrom(chrome_frame_); | 590 ole_window.QueryFrom(chrome_frame_); |
| 883 EXPECT_TRUE(ole_window.get()); | 591 EXPECT_TRUE(ole_window.get()); |
| 884 | 592 |
| 885 if (ole_window) { | 593 if (ole_window) { |
| 886 HWND activex_window = NULL; | 594 HWND activex_window = NULL; |
| 887 ole_window->GetWindow(&activex_window); | 595 ole_window->GetWindow(&activex_window); |
| 888 EXPECT_TRUE(IsWindow(activex_window)); | 596 EXPECT_TRUE(IsWindow(activex_window)); |
| 889 | 597 |
| 890 // chrome tab window is the first (and the only) child of activex | 598 // chrome tab window is the first (and the only) child of activex |
| 891 HWND chrome_tab_window = GetWindow(activex_window, GW_CHILD); | 599 HWND chrome_tab_window = GetWindow(activex_window, GW_CHILD); |
| 892 EXPECT_TRUE(IsWindow(chrome_tab_window)); | 600 EXPECT_TRUE(IsWindow(chrome_tab_window)); |
| 893 renderer_window = GetWindow(chrome_tab_window, GW_CHILD); | 601 renderer_window = GetWindow(chrome_tab_window, GW_CHILD); |
| 894 } | 602 } |
| 895 | 603 |
| 896 DCHECK(IsWindow(renderer_window)); | 604 EXPECT_TRUE(IsWindow(renderer_window)); |
| 897 return renderer_window; | 605 return renderer_window; |
| 898 } | 606 } |
| 899 | 607 |
| 900 HRESULT WebBrowserEventSink::SetWebBrowser(IWebBrowser2* web_browser2) { | 608 HRESULT WebBrowserEventSink::SetWebBrowser(IWebBrowser2* web_browser2) { |
| 901 DCHECK(web_browser2_.get() == NULL); | 609 DCHECK(web_browser2_.get() == NULL); |
| 902 web_browser2_ = web_browser2; | 610 web_browser2_ = web_browser2; |
| 903 web_browser2_->put_Visible(VARIANT_TRUE); | 611 web_browser2_->put_Visible(VARIANT_TRUE); |
| 904 HRESULT hr = DispEventAdvise(web_browser2_, &DIID_DWebBrowserEvents2); | 612 HRESULT hr = DispEventAdvise(web_browser2_, &DIID_DWebBrowserEvents2); |
| 905 return hr; | 613 return hr; |
| 906 } | 614 } |
| 907 | 615 |
| 616 void WebBrowserEventSink::ExpectRendererWindowHasfocus() { | |
| 617 HWND renderer_window = GetRendererWindow(); | |
| 618 EXPECT_TRUE(IsWindow(renderer_window)); | |
| 619 | |
| 620 for (HWND first_child = renderer_window; | |
| 621 IsWindow(first_child); first_child = GetWindow(first_child, GW_CHILD)) { | |
|
tommi (sloooow) - chröme
2010/02/12 17:14:05
indent off
| |
| 622 renderer_window = first_child; | |
| 623 } | |
| 624 | |
| 625 wchar_t class_name[MAX_PATH] = {0}; | |
| 626 GetClassName(renderer_window, class_name, arraysize(class_name)); | |
| 627 EXPECT_TRUE(_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND") == 0); | |
| 628 | |
| 629 DWORD renderer_thread = 0; | |
| 630 DWORD renderer_process = 0; | |
| 631 renderer_thread = GetWindowThreadProcessId(renderer_window, | |
| 632 &renderer_process); | |
| 633 | |
| 634 ASSERT_TRUE(AttachThreadInput(GetCurrentThreadId(), renderer_thread, TRUE)); | |
| 635 HWND focus_window = GetFocus(); | |
| 636 EXPECT_TRUE(focus_window == renderer_window); | |
| 637 EXPECT_TRUE(AttachThreadInput(GetCurrentThreadId(), renderer_thread, FALSE)); | |
| 638 } | |
| 639 | |
| 640 void WebBrowserEventSink::Exec(const GUID* cmd_group_guid, DWORD command_id, | |
| 641 DWORD cmd_exec_opt, VARIANT* in_args, | |
| 642 VARIANT* out_args) { | |
| 643 ScopedComPtr<IOleCommandTarget> shell_browser_cmd_target; | |
| 644 DoQueryService(SID_STopLevelBrowser, web_browser2_, | |
| 645 shell_browser_cmd_target.Receive()); | |
| 646 ASSERT_TRUE(NULL != shell_browser_cmd_target); | |
| 647 EXPECT_HRESULT_SUCCEEDED(shell_browser_cmd_target->Exec(cmd_group_guid, | |
| 648 command_id, cmd_exec_opt, in_args, out_args)); | |
| 649 } | |
| 650 | |
| 908 } // namespace chrome_frame_test | 651 } // namespace chrome_frame_test |
| OLD | NEW |