| 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/event_hooker.h" | |
| 6 | |
| 7 #include <crtdbg.h> | |
| 8 #include "chrome_frame/bho_loader.h" | |
| 9 | |
| 10 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | |
| 11 | |
| 12 EventHooker::EventHooker() | |
| 13 : window_creation_hook_(NULL) {} | |
| 14 | |
| 15 EventHooker::~EventHooker() { | |
| 16 StopHook(); | |
| 17 } | |
| 18 | |
| 19 bool EventHooker::StartHook() { | |
| 20 if ((NULL != window_creation_hook_)) { | |
| 21 return false; | |
| 22 } | |
| 23 | |
| 24 window_creation_hook_ = SetWinEventHook(EVENT_OBJECT_CREATE, | |
| 25 EVENT_OBJECT_CREATE, | |
| 26 reinterpret_cast<HMODULE>( | |
| 27 &__ImageBase), | |
| 28 WindowCreationHookProc, | |
| 29 0, | |
| 30 0, | |
| 31 WINEVENT_INCONTEXT); | |
| 32 if (NULL == window_creation_hook_) { | |
| 33 return false; | |
| 34 } | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 void EventHooker::StopHook() { | |
| 39 if (NULL != window_creation_hook_) { | |
| 40 UnhookWinEvent(window_creation_hook_); | |
| 41 window_creation_hook_ = NULL; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 VOID CALLBACK EventHooker::WindowCreationHookProc(HWINEVENTHOOK hook, | |
| 46 DWORD event, | |
| 47 HWND window, | |
| 48 LONG object_id, | |
| 49 LONG child_id, | |
| 50 DWORD event_tid, | |
| 51 DWORD event_time) { | |
| 52 _ASSERTE((EVENT_OBJECT_CREATE == event) || | |
| 53 (EVENT_OBJECT_PARENTCHANGE == event)); | |
| 54 if (OBJID_WINDOW == object_id) { | |
| 55 BHOLoader::GetInstance()->OnHookEvent(event, window); | |
| 56 } | |
| 57 } | |
| 58 | |
| OLD | NEW |