| 59 | } |
| 60 | |
| 61 | int CookieManager::SetCookie(const std::string& url, |
| 62 | const BrowserCookie& cookie) { |
| 63 | std::string full_data = url + "|" + cookie.ToString(); |
| 64 | WPARAM set_flags = 0; |
| 65 | if (cookie.is_httponly()) { |
| 66 | set_flags = INTERNET_COOKIE_HTTPONLY; |
| 67 | } |
| 68 | |
| 69 | HookSettings hook_settings; |
| 70 | hook_settings.hook_procedure_name = "CookieWndProc"; |
| 71 | hook_settings.hook_procedure_type = WH_CALLWNDPROC; |
| 72 | hook_settings.window_handle = this->window_handle_; |
| 73 | hook_settings.communication_type = OneWay; |
| 74 | |
| 75 | HookProcessor hook; |
| 76 | if (!hook.CanSetWindowsHook(this->window_handle_)) { |
| 77 | LOG(WARN) << "Cannot set cookie because driver and browser are not the " |
| 78 | << "same bit-ness."; |
| 79 | return EUNHANDLEDERROR; |
| 80 | } |
| 81 | hook.Initialize(hook_settings); |
| 82 | hook.PushData(StringUtilities::ToWString(full_data)); |
| 83 | ::SendMessage(this->window_handle_, WD_SET_COOKIE, set_flags, NULL); |
| 84 | int status = HookProcessor::GetDataBufferSize(); |
| 85 | if (status != 0) { |
| 86 | LOG(WARN) << "Setting cookie encountered error " << status; |
| 87 | return EINVALIDCOOKIEDOMAIN; |
| 88 | } |
| 89 | return WD_SUCCESS; |
| 90 | } |
| 91 | |
| 92 | int CookieManager::GetCookies(const std::string& url, |
| 93 | std::vector<BrowserCookie>* all_cookies) { |
no test coverage detected