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.
5 #include "chrome_frame/event_hooker.h"
8 #include "chrome_frame/bho_loader.h"
10 EXTERN_C IMAGE_DOS_HEADER __ImageBase
;
12 EventHooker::EventHooker()
13 : window_creation_hook_(NULL
) {}
15 EventHooker::~EventHooker() {
19 bool EventHooker::StartHook() {
20 if ((NULL
!= window_creation_hook_
)) {
24 window_creation_hook_
= SetWinEventHook(EVENT_OBJECT_CREATE
,
26 reinterpret_cast<HMODULE
>(
28 WindowCreationHookProc
,
32 if (NULL
== window_creation_hook_
) {
38 void EventHooker::StopHook() {
39 if (NULL
!= window_creation_hook_
) {
40 UnhookWinEvent(window_creation_hook_
);
41 window_creation_hook_
= NULL
;
45 VOID CALLBACK
EventHooker::WindowCreationHookProc(HWINEVENTHOOK hook
,
52 _ASSERTE((EVENT_OBJECT_CREATE
== event
) ||
53 (EVENT_OBJECT_PARENTCHANGE
== event
));
54 if (OBJID_WINDOW
== object_id
) {
55 BHOLoader::GetInstance()->OnHookEvent(event
, window
);