Esempio n. 1
0
int CookieManager::SetCookie(const std::string& url, 
                             const BrowserCookie& cookie) {
  std::string full_data = url + "|" + cookie.ToString();
  WPARAM set_flags = 0;
  if (cookie.is_httponly()) {
    set_flags = INTERNET_COOKIE_HTTPONLY;
  }

  HookSettings hook_settings;
  hook_settings.hook_procedure_name = "CookieWndProc";
  hook_settings.hook_procedure_type = WH_CALLWNDPROC;
  hook_settings.window_handle = this->window_handle_;
  hook_settings.communication_type = OneWay;

  HookProcessor hook;
  if (!hook.CanSetWindowsHook(this->window_handle_)) {
    LOG(WARN) << "Cannot set cookie because driver and browser are not the "
              << "same bit-ness.";
    return EUNHANDLEDERROR;
  }
  hook.Initialize(hook_settings);
  hook.PushData(StringUtilities::ToWString(full_data));
  ::SendMessage(this->window_handle_, WD_SET_COOKIE, set_flags, NULL);
  int status = HookProcessor::GetDataBufferSize();
  if (status != 0) {
    LOG(WARN) << "Setting cookie encountered error " << status;
    return EINVALIDCOOKIEDOMAIN;
  }
  return WD_SUCCESS;
}
Esempio n. 2
0
void ProxyManager::SetPerProcessProxySettings(HWND browser_window_handle) {
  LOG(TRACE) << "ProxyManager::SetPerProcessProxySettings";
  std::wstring proxy = this->BuildProxySettingsString();

  HookSettings hook_settings;
  hook_settings.window_handle = browser_window_handle;
  hook_settings.hook_procedure_name = "SetProxyWndProc";
  hook_settings.hook_procedure_type = WH_CALLWNDPROC;
  hook_settings.communication_type = OneWay;

  HookProcessor hook;
  if (!hook.CanSetWindowsHook(browser_window_handle)) {
    LOG(WARN) << "Proxy will not be set! There is a mismatch in the "
              << "bitness between the driver and browser. In particular, "
              << "be sure you are not attempting to use a 64-bit "
              << "IEDriverServer.exe against IE 10 or 11, even on 64-bit "
              << "Windows.";
  }
  hook.Initialize(hook_settings);
  hook.PushData(proxy);
  LRESULT result = ::SendMessage(browser_window_handle,
                                 WD_CHANGE_PROXY,
                                 NULL,
                                 NULL);

  if (this->socks_proxy_.size() > 0 && 
      (this->socks_user_name_.size() > 0 || this->socks_password_.size() > 0)) {
    LOG(WARN) << "Windows APIs provide no way to set proxy user name and "
              << "password on a per-process basis. Setting global setting.";

    this->SetProxyAuthentication(StringUtilities::ToWString(this->socks_user_name_),
                                 StringUtilities::ToWString(this->socks_password_));
    this->is_proxy_authorization_modified_ = true;
    
    // Notify WinINet clients that the proxy options have changed.
    BOOL success = ::InternetSetOption(NULL,
                                       INTERNET_OPTION_PROXY_SETTINGS_CHANGED,
                                       NULL,
                                       0);
    if (!success) {
      LOGERR(WARN) << "InternetSetOption failed setting INTERNET_OPTION_PROXY_SETTINGS_CHANGED";
    }
  }
}