Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/Browser.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_BROWSER_H_
18
#define WEBDRIVER_IE_BROWSER_H_
19
20
#include <string>
21
#include <vector>
22
23
#include <exdispid.h>
24
#include <mshtml.h>
25
26
#include "DocumentHost.h"
27
28
namespace webdriver {
29
30
struct BrowserReattachInfo {
31
DWORD current_process_id;
32
std::vector<DWORD> known_process_ids;
33
std::string browser_id;
34
};
35
36
struct NewWindowInfo {
37
std::string target_url;
38
LPSTREAM browser_stream;
39
};
40
41
// Forward declaration of classes to avoid
42
// circular include files.
43
class ElementRepository;
44
45
class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DIID_DWebBrowserEvents2> {
46
public:
47
Browser(IWebBrowser2* browser, HWND hwnd, HWND session_handle, bool isEdgeChrome = false);
48
virtual ~Browser(void);
49
50
static inline _ATL_FUNC_INFO* BeforeNavigate2Info() {
51
static _ATL_FUNC_INFO kBeforeNavigate2 = { CC_STDCALL,
52
VT_EMPTY,
53
7,
54
{ VT_DISPATCH,
55
VT_VARIANT | VT_BYREF,
56
VT_VARIANT | VT_BYREF,
57
VT_VARIANT | VT_BYREF,
58
VT_VARIANT | VT_BYREF,
59
VT_VARIANT | VT_BYREF,
60
VT_BOOL | VT_BYREF } };
61
return &kBeforeNavigate2;
62
}
63
64
static inline _ATL_FUNC_INFO* DocumentCompleteInfo() {
65
static _ATL_FUNC_INFO kDocumentComplete = { CC_STDCALL,
66
VT_EMPTY,
67
2,
68
{ VT_DISPATCH,
69
VT_VARIANT|VT_BYREF } };
70
return &kDocumentComplete;
71
}
72
73
static inline _ATL_FUNC_INFO* NoArgumentsInfo() {
74
static _ATL_FUNC_INFO kNoArguments = { CC_STDCALL, VT_EMPTY, 0 };
75
return &kNoArguments;
76
}
77
78
static inline _ATL_FUNC_INFO* NewWindow3Info() {
79
static _ATL_FUNC_INFO kNewWindow3 = { CC_STDCALL, VT_EMPTY, 5,
80
{ VT_DISPATCH | VT_BYREF,
81
VT_BOOL | VT_BYREF,
82
VT_I4,
83
VT_BSTR,
84
VT_BSTR } };
85
return &kNewWindow3;
86
}
87
88
static inline _ATL_FUNC_INFO* NewProcessInfo() {
89
static _ATL_FUNC_INFO kNewProcess = { CC_STDCALL, VT_EMPTY, 3,
90
{ VT_I4,
91
VT_DISPATCH,
92
VT_BOOL | VT_BYREF } };
93
return &kNewProcess;
94
}
95
96
BEGIN_SINK_MAP(Browser)
97
SINK_ENTRY_INFO(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, BeforeNavigate2, BeforeNavigate2Info())
98
SINK_ENTRY_INFO(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, DocumentComplete, DocumentCompleteInfo())
99
SINK_ENTRY_INFO(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnQuit, NoArgumentsInfo())
100
SINK_ENTRY_INFO(1, DIID_DWebBrowserEvents2, DISPID_NEWWINDOW3, NewWindow3, NewWindow3Info())
101
SINK_ENTRY_INFO(1, DIID_DWebBrowserEvents2, DISPID_NEWPROCESS, NewProcess, NewProcessInfo())
102
END_SINK_MAP()
103
104
STDMETHOD_(void, BeforeNavigate2)(IDispatch* pObject, VARIANT* pvarUrl, VARIANT* pvarFlags,
105
VARIANT* pvarTargetFrame, VARIANT* pvarData, VARIANT* pvarHeaders, VARIANT_BOOL* pbCancel);
106
STDMETHOD_(void, DocumentComplete)(IDispatch* pDisp, VARIANT* URL);
107
STDMETHOD_(void, OnQuit)();
108
STDMETHOD_(void, NewWindow3)(IDispatch** ppDisp, VARIANT_BOOL* pbCancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl);
109
STDMETHOD_(void, NewProcess)(DWORD lCauseFlag, IDispatch* pWB2, VARIANT_BOOL* pbCancel);
110
111
bool Wait(const std::string& page_load_strategy);
112
void Close(void);
113
bool IsBusy(void);
114
void GetDocument(const bool force_top_level_document,
115
IHTMLDocument2** doc);
116
void GetDocument(IHTMLDocument2** doc);
117
std::string GetWindowName(void);
118
std::string GetTitle(void);
119
std::string GetBrowserUrl(void);
120
HWND GetContentWindowHandle(void);
121
HWND GetBrowserWindowHandle(void);
122
HWND GetTopLevelWindowHandle(void);
123
HWND GetActiveDialogWindowHandle(void);
124
125
long GetWidth(void);
126
long GetHeight(void);
127
void SetWidth(long width);
128
void SetHeight(long height);
129
130
int NavigateToUrl(const std::string& url, std::string* error_message);
131
int NavigateBack(void);
132
int NavigateForward(void);
133
int Refresh(void);
134
135
bool IsValidWindow(void);
136
137
bool IsFullScreen(void);
138
bool SetFullScreen(bool is_full_screen);
139
140
void InitiateBrowserReattach(void);
141
void ReattachBrowser(IWebBrowser2* browser);
142
143
bool is_explicit_close_requested(void) const {
144
return this->is_explicit_close_requested_;
145
}
146
IWebBrowser2* browser(void) { return this->browser_; }
147
148
private:
149
void AttachEvents(void);
150
void DetachEvents(void);
151
bool IsDocumentNavigating(const std::string& page_load_strategy,
152
IHTMLDocument2* doc);
153
bool GetDocumentFromWindow(IHTMLWindow2* window, IHTMLDocument2** doc);
154
void CheckDialogType(HWND dialog_window_handle);
155
156
static unsigned int WINAPI GoBackThreadProc(LPVOID param);
157
static unsigned int WINAPI GoForwardThreadProc(LPVOID param);
158
159
CComPtr<IWebBrowser2> browser_;
160
bool is_navigation_started_;
161
bool is_explicit_close_requested_;
162
std::vector<DWORD> known_process_ids_;
163
};
164
165
} // namespace webdriver
166
167
#endif // WEBDRIVER_IE_BROWSER_H_
168
169