Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/BrowserFactory.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_IE_BROWSERFACTORY_H_
18
#define WEBDRIVER_IE_BROWSERFACTORY_H_
19
20
#include <string>
21
22
namespace webdriver {
23
24
struct ProcessWindowInfo {
25
DWORD dwProcessId;
26
HWND hwndBrowser;
27
IWebBrowser2* pBrowser;
28
};
29
30
struct BrowserFactorySettings {
31
bool ignore_protected_mode_settings;
32
bool ignore_zoom_setting;
33
bool force_create_process_api;
34
bool force_shell_windows_api;
35
bool clear_cache_before_launch;
36
int browser_attach_timeout;
37
std::string initial_browser_url;
38
std::string browser_command_line_switches;
39
bool attach_to_edge_ie; // Used to attach to EdgeChromium IE processes
40
std::string edge_executable_path;
41
bool ignore_process_match; // Ignores window handle process id match on IE Mode.
42
};
43
44
class BrowserFactory {
45
public:
46
BrowserFactory(void);
47
virtual ~BrowserFactory(void);
48
49
50
void Initialize(BrowserFactorySettings settings);
51
52
DWORD LaunchBrowserProcess(std::string* error_message);
53
IWebBrowser2* CreateBrowser(bool is_protected_mode);
54
bool AttachToBrowser(ProcessWindowInfo* procWinInfo,
55
std::string* error_message);
56
bool GetDocumentFromWindowHandle(HWND window_handle,
57
IHTMLDocument2** document);
58
bool IsBrowserProcessInitialized(DWORD process_id);
59
60
bool ignore_protected_mode_settings(void) const { return this->ignore_protected_mode_settings_; }
61
bool ignore_zoom_setting(void) const { return this->ignore_zoom_setting_; }
62
bool clear_cache(void) const { return this->clear_cache_; }
63
bool force_createprocess_api(void) const { return this->force_createprocess_api_; }
64
bool force_shell_windows_api(void) const { return this->force_shell_windows_api_; }
65
int browser_attach_timeout(void) const { return this->browser_attach_timeout_; }
66
bool ignore_process_match(void) const { return this->ignore_process_match_; }
67
std::string initial_browser_url(void);
68
std::string browser_command_line_switches(void);
69
70
int browser_version(void) const { return this->ie_major_version_; }
71
72
static BOOL CALLBACK FindChildWindowForProcess(HWND hwnd, LPARAM arg);
73
static BOOL CALLBACK FindEdgeChildWindowForProcess(HWND hwnd, LPARAM arg);
74
static BOOL CALLBACK FindDialogWindowForProcess(HWND hwnd, LPARAM arg);
75
static BOOL CALLBACK FindIEBrowserHandles(HWND hwnd, LPARAM arg);
76
static BOOL CALLBACK FindEdgeBrowserHandles(HWND hwnd, LPARAM arg);
77
78
static bool IsWindowsVistaOrGreater(void);
79
static int DeleteDirectory(const std::wstring &dir_name);
80
81
bool IsEdgeMode(void) const;
82
std::wstring GetEdgeTempDir(void);
83
private:
84
static BOOL CALLBACK FindBrowserWindow(HWND hwnd, LPARAM param);
85
static BOOL CALLBACK FindEdgeWindow(HWND hwnd, LPARAM param);
86
static BOOL CALLBACK FindEdgeWindowIgnoringProcessMatch(HWND hwnd, LPARAM param);
87
static bool IsWindowsVersionOrGreater(unsigned short major_version,
88
unsigned short minor_version,
89
unsigned short service_pack);
90
91
static bool DirectoryExists(std::wstring& dir_name);
92
static bool CreateUniqueTempDir(std::wstring &temp_dir);
93
94
UINT html_getobject_msg_;
95
HINSTANCE oleacc_instance_handle_;
96
97
bool CreateLowIntegrityLevelToken(HANDLE* process_token_handle,
98
HANDLE* mic_token_handle,
99
PSID* sid);
100
101
bool AttachToBrowserUsingShellWindows(ProcessWindowInfo* process_window_info,
102
std::string* error_message);
103
bool AttachToBrowserUsingActiveAccessibility(
104
ProcessWindowInfo* process_window_info,
105
std::string* error_message);
106
107
void GetEdgeExecutableLocation(void);
108
void GetIEExecutableLocation(void);
109
void GetIEVersion(void);
110
bool ProtectedModeSettingsAreValid(void);
111
int GetZoneProtectedModeSetting(const HKEY key_handle,
112
const std::wstring& zone_subkey_name);
113
int GetBrowserZoomLevel(IWebBrowser2* browser);
114
int GetZoomLevel(IHTMLDocument2* document, IHTMLWindow2* window);
115
void LaunchBrowserUsingCreateProcess(PROCESS_INFORMATION* proc_info,
116
std::string* error_message);
117
void LaunchEdgeInIEMode(PROCESS_INFORMATION* proc_info,
118
std::string* error_message);
119
void LaunchBrowserUsingIELaunchURL(PROCESS_INFORMATION* proc_info,
120
std::string* error_message);
121
bool IsIELaunchURLAvailable(void);
122
bool IsCreateProcessApiAvailable(void);
123
void ClearCache(void);
124
void InvokeClearCacheUtility(bool use_low_integrity_level);
125
126
bool ignore_protected_mode_settings_;
127
bool ignore_zoom_setting_;
128
bool force_createprocess_api_;
129
bool force_shell_windows_api_;
130
bool clear_cache_;
131
132
std::wstring browser_command_line_switches_;
133
std::wstring initial_browser_url_;
134
int browser_attach_timeout_;
135
136
int ie_major_version_;
137
std::wstring ie_executable_location_;
138
std::wstring edge_executable_located_location_;
139
bool ie_redirects_edge_;
140
141
bool edge_ie_mode_;
142
bool ignore_process_match_;
143
std::wstring edge_executable_location_;
144
std::wstring edge_user_data_dir_;
145
};
146
147
} // namespace webdriver
148
149
#endif // WEBDRIVER_IE_BROWSERFACTORY_H_
150
151