MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / SetProxyWndProc

Function SetProxyWndProc

cpp/iedriver/ProxyManager.cpp:509–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

507#endif
508
509LRESULT CALLBACK SetProxyWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
510 CWPSTRUCT* call_window_proc_struct = reinterpret_cast<CWPSTRUCT*>(lParam);
511 if (WM_COPYDATA == call_window_proc_struct->message) {
512 COPYDATASTRUCT* data = reinterpret_cast<COPYDATASTRUCT*>(call_window_proc_struct->lParam);
513 webdriver::HookProcessor::CopyDataToBuffer(data->cbData, data->lpData);
514 } else if (WD_CHANGE_PROXY == call_window_proc_struct->message) {
515 // Allocate a buffer of the length of the data in the shared memory buffer,
516 // plus one extra wide char, to account for the null terminator.
517 int multibyte_buffer_size = webdriver::HookProcessor::GetDataBufferSize() + sizeof(wchar_t);
518 std::vector<char> multibyte_buffer(multibyte_buffer_size);
519 std::vector<char> multibyte_buffer_bypass(multibyte_buffer_size);
520 std::wstring proxy_settings = webdriver::HookProcessor::CopyWStringFromBuffer();
521 std::wstring proxy = proxy_settings;
522 std::wstring proxy_bypass = L"";
523
524 // Use the _TEXT macro to convert to a wstring literal
525 std::wstring bypass_marker = _TEXT(BYPASS_PROXY_MARKER);
526 size_t bypass_marker_index = proxy_settings.find(bypass_marker);
527 if (bypass_marker_index != std::wstring::npos) {
528 proxy = proxy_settings.substr(0, bypass_marker_index);
529 proxy_bypass = proxy_settings.substr(bypass_marker_index + bypass_marker.size());
530 }
531
532 INTERNET_PROXY_INFO proxy_info;
533 if (proxy == L"direct") {
534 proxy_info.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
535 proxy_info.lpszProxy = L"";
536 } else {
537 // UrlMkSetSessionOption only appears to work on either ASCII or
538 // multi-byte strings, not Unicode strings. Since the INTERNET_PROXY_INFO
539 // struct hard-codes to LPCTSTR, and that translates into LPCWSTR for the
540 // compiler settings we use, we must use the multi-byte version here.
541 // Note that for the count of input characters, we can use -1, since
542 // we've forced the string to be null-terminated.
543 ::WideCharToMultiByte(CP_UTF8,
544 0,
545 proxy.c_str(),
546 -1,
547 &multibyte_buffer[0],
548 static_cast<int>(multibyte_buffer.size()),
549 NULL,
550 NULL);
551 proxy_info.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
552 proxy_info.lpszProxy = reinterpret_cast<LPCTSTR>(&multibyte_buffer[0]);
553 }
554
555 ::WideCharToMultiByte(CP_UTF8,
556 0,
557 proxy_bypass.c_str(),
558 -1,
559 &multibyte_buffer_bypass[0],
560 static_cast<int>(multibyte_buffer_bypass.size()),
561 NULL,
562 NULL);
563 proxy_info.lpszProxyBypass = reinterpret_cast<LPCTSTR>(&multibyte_buffer_bypass[0]);
564 DWORD proxy_info_size = sizeof(proxy_info);
565 HRESULT hr = ::UrlMkSetSessionOption(INTERNET_OPTION_PROXY,
566 reinterpret_cast<void*>(&proxy_info),

Callers

nothing calls this directly

Calls 2

findMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected