@@ -452,6 +452,24 @@ unsigned int WINAPI CookieManager::ThreadProc(LPVOID lpParameter) {
452
452
extern " C" {
453
453
#endif
454
454
455
+ // In order to run the IE driver against versions of IE that do not include
456
+ // a version of WinINet.dll that supports the InternetGetCookiesEx2 API,
457
+ // we must access the API in a way that does not import it into our DLL.
458
+ // To that end, we duplicate the INTERNET_COOKIE2 structure here, and will
459
+ // call the API (if it exists) via GetModuleHandle and GetProcAddress.
460
+ typedef struct {
461
+ PWSTR pwszName;
462
+ PWSTR pwszValue;
463
+ PWSTR pwszDomain;
464
+ PWSTR pwszPath;
465
+ DWORD dwFlags;
466
+ FILETIME ftExpires;
467
+ BOOL fExpiresSet ;
468
+ } INTERNETCOOKIE2;
469
+
470
+ typedef void * (__stdcall *InternetFreeCookiesProc)(INTERNETCOOKIE2*, DWORD);
471
+ typedef DWORD (__stdcall *InternetGetCookieEx2Proc)(PCWSTR, PCWSTR, DWORD, INTERNETCOOKIE2**, PDWORD);
472
+
455
473
LRESULT CALLBACK CookieWndProc (int nCode, WPARAM wParam, LPARAM lParam) {
456
474
CWPSTRUCT* call_window_proc_struct = reinterpret_cast <CWPSTRUCT*>(lParam);
457
475
if (WM_COPYDATA == call_window_proc_struct->message ) {
@@ -472,29 +490,30 @@ LRESULT CALLBACK CookieWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
472
490
CComBSTR path_bstr;
473
491
uri_pointer->GetPath (&path_bstr);
474
492
475
- // Get only the cookies for the base URL, omitting port, if there is one.
476
- // N.B., we only return cookies secure cookies when browsing a site using
477
- // SSL. The browser won't see cookies with the 'secure' flag for sites
478
- // visited using plain http.
479
- std::wstring parsed_uri = L" http" ;
480
- if ((WD_GET_SECURE_COOKIES == call_window_proc_struct->message ||
481
- WD_GET_SCRIPTABLE_COOKIES == call_window_proc_struct->message ) &&
482
- URL_SCHEME_HTTPS == scheme) {
483
- parsed_uri.append (L" s" );
484
- }
493
+ std::wstring parsed_uri = scheme_bstr;
485
494
parsed_uri.append (L" ://" );
486
495
parsed_uri.append (host_bstr);
487
496
parsed_uri.append (path_bstr);
488
497
489
- // Allocate a static array for cookies, since IE is documented
490
- // to limit the number of cookies to 50.
498
+ InternetGetCookieEx2Proc get_cookie_proc = NULL ;
499
+ InternetFreeCookiesProc free_cookies_proc = NULL ;
500
+ HMODULE wininet_handle = ::GetModuleHandle (L" wininet" );
501
+ if (wininet_handle) {
502
+ get_cookie_proc = reinterpret_cast <InternetGetCookieEx2Proc>(::GetProcAddress (wininet_handle, " InternetGetCookieEx2" ));
503
+ free_cookies_proc = reinterpret_cast <InternetFreeCookiesProc>(::GetProcAddress (wininet_handle, " InternetFreeCookies" ));
504
+ }
505
+
491
506
DWORD cookie_count = 0 ;
492
- INTERNET_COOKIE2* cookie_pointer;
493
- DWORD success = ::InternetGetCookieEx2 (parsed_uri.c_str (),
494
- NULL ,
495
- INTERNET_COOKIE_NON_SCRIPT,
496
- &cookie_pointer,
497
- &cookie_count);
507
+ INTERNETCOOKIE2* cookie_pointer = NULL ;
508
+ DWORD success = 1 ;
509
+ if (get_cookie_proc) {
510
+ success = get_cookie_proc (parsed_uri.c_str (),
511
+ NULL ,
512
+ INTERNET_COOKIE_NON_SCRIPT,
513
+ &cookie_pointer,
514
+ &cookie_count);
515
+ }
516
+
498
517
if (success == 0 ) {
499
518
// Mimic the format of the old persistent cookie files for ease of
500
519
// transmission back to the driver and parsing.
@@ -503,7 +522,7 @@ LRESULT CALLBACK CookieWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
503
522
if (all_cookies.size () > 0 ) {
504
523
all_cookies.append (L" \n *\n " );
505
524
}
506
- INTERNET_COOKIE2 * current_cookie = cookie_pointer + cookie_index;
525
+ INTERNETCOOKIE2 * current_cookie = cookie_pointer + cookie_index;
507
526
std::wstring cookie_name = current_cookie->pwszName ;
508
527
std::wstring cookie_value = current_cookie->pwszValue ;
509
528
std::wstring cookie_domain = current_cookie->pwszDomain ;
@@ -524,7 +543,7 @@ LRESULT CALLBACK CookieWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
524
543
all_cookies.append (L" \n\n " );
525
544
}
526
545
}
527
- ::InternetFreeCookies (cookie_pointer, cookie_count);
546
+ free_cookies_proc (cookie_pointer, cookie_count);
528
547
webdriver::HookProcessor::CopyWStringToBuffer (all_cookies);
529
548
} else {
530
549
webdriver::HookProcessor::SetDataBufferSize (sizeof (wchar_t ));
0 commit comments