Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/HookProcessor.h
2867 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#ifndef WEBDRIVER_HOOKPROCESSOR_H_
18
#define WEBDRIVER_HOOKPROCESSOR_H_
19
20
#include <string>
21
#include <vector>
22
23
namespace webdriver {
24
25
enum HookCommunicationType {
26
OneWay = 0,
27
TwoWay = 1
28
};
29
30
struct HookSettings {
31
std::string hook_procedure_name;
32
int hook_procedure_type;
33
HookCommunicationType communication_type;
34
HWND window_handle;
35
};
36
37
class HookProcessor {
38
public:
39
HookProcessor(void);
40
virtual ~HookProcessor(void);
41
42
static int GetDataBufferSize(void);
43
static void SetDataBufferSize(int size);
44
static void* GetDataBufferAddress(void);
45
46
static int GetEventCount(void);
47
static void ResetEventCount(void);
48
static void IncrementEventCount(int increment);
49
50
static void ResetFlag(void);
51
static bool GetFlagValue(void);
52
static void SetFlagValue(bool flag_value);
53
54
static void CopyDataToBuffer(int source_data_size, void* source);
55
static void CopyDataFromBuffer(int destination_data_size, void* destination);
56
static void CopyWStringToBuffer(const std::wstring& data);
57
static std::wstring CopyWStringFromBuffer(void);
58
59
static void WriteBufferToPipe(const int process_id);
60
61
bool CanSetWindowsHook(HWND window_handle);
62
void Initialize(const HookSettings& settings);
63
void Initialize(const std::string& hook_proc_name, const int hook_proc_type);
64
void Dispose(void);
65
66
bool PushData(int data_size,
67
void* pointer_to_data);
68
bool PushData(const std::wstring& data);
69
70
int PullData(std::vector<char>* data);
71
int PullData(std::wstring data);
72
73
private:
74
static void ClearBuffer(void);
75
76
void CreateReturnPipe(void);
77
bool InstallWindowsHook(const std::string& hook_proc_name,
78
const int hook_proc_type);
79
void UninstallWindowsHook(void);
80
bool Is64BitProcess(HANDLE process_handle);
81
82
HookCommunicationType communication_type_;
83
HWND window_handle_;
84
HHOOK hook_procedure_handle_;
85
HANDLE pipe_handle_;
86
};
87
88
} // namespace webdriver
89
90
#endif // WEBDRIVER_HOOKPROCESSOR_H_
91
92
93