19
19
#include " interactions.h"
20
20
#include " json.h"
21
21
#include " logging.h"
22
+ #include " RegistryUtilities.h"
22
23
#include " StringUtilities.h"
23
24
24
25
namespace webdriver {
@@ -63,8 +64,11 @@ LRESULT IEWebDriverManagerCommandExecutor::OnCreate(UINT uMsg,
63
64
IID_IIEWebDriverManager,
64
65
reinterpret_cast <void **>(&this ->manager_ ));
65
66
if (FAILED (hr)) {
66
- // TOOD: Handle the case where the COM object is not installed.
67
+ // If the COM object isn't installed, or there is another error, mark the
68
+ // session as invalid. In theory, we should only hit this issue if we're
69
+ // forcing the
67
70
LOGHR (WARN, hr) << " Could not create instance of class IEWebDriverManager" ;
71
+ this ->is_valid_ = false ;
68
72
}
69
73
70
74
return 0 ;
@@ -78,6 +82,7 @@ LRESULT IEWebDriverManagerCommandExecutor::OnDestroy(UINT uMsg,
78
82
79
83
LOG (DEBUG) << " Posting quit message" ;
80
84
this ->manager_ .Release ();
85
+ delete this ->factory_ ;
81
86
::PostQuitMessage (0 );
82
87
LOG (DEBUG) << " Leaving IEWebDriverManagerCommandExecutor::OnDestroy" ;
83
88
return 0 ;
@@ -108,7 +113,7 @@ LRESULT IEWebDriverManagerCommandExecutor::OnGetResponseLength(UINT uMsg,
108
113
WPARAM wParam,
109
114
LPARAM lParam,
110
115
BOOL& bHandled) {
111
- // Not logging trace entering IEDevChannelCommandExecutor ::OnGetResponseLength,
116
+ // Not logging trace entering IEWebDriverManagerCommandExecutor ::OnGetResponseLength,
112
117
// because it is polled repeatedly for a non-zero return value.
113
118
size_t response_length = 0 ;
114
119
if (!this ->is_waiting_ ) {
@@ -224,21 +229,40 @@ unsigned int WINAPI IEWebDriverManagerCommandExecutor::ThreadProc(LPVOID lpParam
224
229
225
230
void IEWebDriverManagerCommandExecutor::DispatchCommand () {
226
231
LOG (TRACE) << " Entering IEWebDriverManagerCommandExecutor::DispatchCommand" ;
227
- std::wstring serialized_command = StringUtilities::ToWString (this ->current_command_ .Serialize ());
232
+ Response actual_response;
233
+ if (this ->current_command_ .command_type () == CommandType::NewSession && !this ->is_valid_ ) {
234
+ // Despite our best efforts, we've attempted to create a new session,
235
+ // but the IEWebDriverManager COM object could not be instantiated.
236
+ // The most common case of this would be when the user has attempted
237
+ // to force the use of the Microsoft driver implementation, but it's
238
+ // not installed, or is not installed properly. So we have to throw
239
+ // an error at this point.
240
+ actual_response.SetErrorResponse (ENOSUCHDRIVER, " Could not create IEWebDriverManager COM object. The most common cause of this is that the driver tool from Microsoft is not installed properly." );
241
+ } else {
242
+ std::wstring serialized_command = StringUtilities::ToWString (this ->current_command_ .Serialize ());
228
243
229
- LPWSTR pszResult = nullptr ;
244
+ LPWSTR pszResult = nullptr ;
230
245
231
- HRESULT hr = this ->manager_ ->ExecuteCommand ((LPWSTR)serialized_command.c_str (), &pszResult);
232
- std::wstring result (pszResult);
233
- Response actual_response;
234
- actual_response.Deserialize (StringUtilities::ToString (result));
246
+ HRESULT hr = this ->manager_ ->ExecuteCommand ((LPWSTR)serialized_command.c_str (), &pszResult);
247
+ std::wstring result (pszResult);
248
+ actual_response.Deserialize (StringUtilities::ToString (result));
249
+ ::CoTaskMemFree (pszResult);
250
+ }
235
251
this ->serialized_response_ = actual_response.Serialize ();
236
- ::CoTaskMemFree (pszResult);
237
252
238
253
if (this ->current_command_ .command_type () == webdriver::CommandType::Close ||
239
254
this ->current_command_ .command_type () == webdriver::CommandType::Quit) {
240
255
this ->is_valid_ = false ;
241
256
}
242
257
}
243
258
259
+ bool IEWebDriverManagerCommandExecutor::IsComponentRegistered () {
260
+ LPOLESTR webdriver_class_id;
261
+ ::StringFromCLSID (CLSID_IEWebDriverManager, &webdriver_class_id);
262
+ std::wstring subkey (L" CLSID\\ " );
263
+ subkey.append (webdriver_class_id);
264
+ ::CoTaskMemFree (webdriver_class_id);
265
+ return RegistryUtilities::RegistryKeyExists (HKEY_CLASSES_ROOT, subkey);
266
+ }
267
+
244
268
} // namespace webdriver
0 commit comments