代理设置Chromium Embedded

时间:2012-11-17 01:09:49

标签: delphi tchromium

如何设置手动代理设置Ip:Port to Chromium Embedded。如果你为IE设置它,那将只影响控件而不是像它一样。

由于

3 个答案:

答案 0 :(得分:0)

uses ceflib;

procedure AppCefGetProxyForUrl(const url: ustring; var proxyType: TCefProxyType;
  var proxyList: ustring );
begin
  proxyType := CEF_PROXY_TYPE_NAMED;
  proxyList := 'ip:port';
end;

initialization
  CefGetProxyForUrl := @AppCefGetProxyForUrl;

end.

答案 1 :(得分:0)

在CEF 3中,您可以使用--proxy-server命令行开关。示例值为socks5://127.0.0.1:8888。您可以在CefApp::OnBeforeCommandLineProcessing中以编程方式进行设置。在此回调名称中设置时,不应包含--前缀。

答案 2 :(得分:0)

使用以前存在的类 CefProxyHandler 可以获得更大的控制。
最新的实现只使用命令行标志(我发现这些较差)。您可以在older SVN branches of CEF上找到以前的代码。

我已经以这种方式实现了(以下是Windows上的C ++方向 - 我不会粘贴太多代码,因为它可以从上面的URL中读取):
- 按照其他CEF类示例(如CefApp)实现导出的 CefProxyHandler 类; class有一个方法, GetProxyForUrl
- 在cef_types.h中定义 cef_proxy_type_t 枚举(direct,named,PAC)和 cef_proxy_info_t 结构(包含类型和字符串列表)
- 在cef_types_wrappers.h中定义 CefProxyInfoTraits 通过 cef_proxy_info_t (按照其他结构示例)和类 CefProxyInfo:public CefStructBase
- 在 PreMainMessageLoopRun 中的libcef / browser / browser_main.cc中,用 CefProxyServiceFactory :: CreateProxyConfigService 替换 ProxyServiceFactory :: CreateProxyConfigService ; Cef工厂将创建 CefProxyService ,最终创建 CefProxyConfigService - 灵感来自 src / net / proxy / proxy_config_service_win.cc 实现类 CefProxyConfigServiceWin ;主要是

static void GetCurrentProxyConfig(net::ProxyConfig* config) {
  CefRefPtr<CefApp> app = CefContentClient::Get()->application();
  if(app.get()) {
    CefRefPtr<CefProxyHandler> handler = app->GetProxyHandler();
    if(handler.get()) {
      // ... use handler->GetProxyForUrl etc.
    }
  }

  WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0};
  if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) {
    LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " <<
      GetLastError();
    *config = net::ProxyConfig::CreateDirect();
    config->set_source(net::PROXY_CONFIG_SOURCE_SYSTEM_FAILED);
    return;
  }
  SetFromIEConfig(config, ie_config);
  FreeIEConfig(&ie_config);
} 


- 重新添加older releases中存在的net :: ProxyConfigServiceWin :: set_force_auto_detect
- 在libcef / browser / url_request_context_getter.cc中(从较旧的CEF分支启发)实现 ProxyConfigServiceNull:public net :: ProxyConfigService (所有空实现),类CefProxyResolver:public net: :ProxyResolver (这里是 GetProxyForUrl 的地方),并且在 CefURLRequestContextGetter :: GetURLRequestContext()中检查自定义代理处理程序,例如:

bool fCustomProxyHandler = false;
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if(app.get()) {
    CefRefPtr<CefProxyHandler> handler = app->GetProxyHandler();
    if(handler.get()) {
    #if defined(OS_WIN)
      // Force auto-detect so the client resolver will be called.
      net::ProxyConfigServiceWin::set_force_auto_detect(true);
    #endif
      // The client will provide proxy resolution.
      storage_->set_proxy_service(
          new net::ProxyService(
                                net::ProxyService::CreateSystemProxyConfigService(io_loop_->message_loop_proxy(), file_loop_), 
                                new CefProxyResolver(handler), 
                                NULL
                               )
      );
      fCustomProxyHandler = true;
    }
}
if(!fCustomProxyHandler) {
    //  custom proxy resolution not provided
    scoped_ptr<net::ProxyService> system_proxy_service;
    system_proxy_service.reset(
        ProxyServiceFactory::CreateProxyService(
            NULL,
            url_request_context_.get(),
            url_request_context_->network_delegate(),
            CefContentBrowserClient::Get()->proxy_config_service().release(),
            command_line));
    storage_->set_proxy_service(system_proxy_service.release());
}

关键是提供存储_-&gt; set_proxy_service您自己的实现。 最后要做的是提供CefProxyHandler(以前的版本可以添加到CefApp或CefClient中,类似于生命周期处理程序,请求处理程序等)。上面的例子是从CefApp提供的。

最新的分支(2357,可能更低)在浏览器进程处理程序和应用程序之间分离更多。这取决于您,所有需要的是通过可用的全局上下文getter访问代理处理程序提供程序(通常是CefApp),并从应用程序直接获取代理处理程序并调用GetProxyHandler或浏览器进程处理程序(如果您计划在那里添加代理getter), CefClient等 之后,您可以轻松地让GetProxyHandler查询您的应用程序以进行代理设置(如果您在Windows上,则发布任务,使用WaitForSingleObject的PostMessage等),以便通过GetProxyForUrl检索代理服务器/端口/用户/传递。

这样做虽然不容易,但可以为您提供完全控制 - 如果您愿意,您甚至可以处理代理每个网址,在同一个浏览器/渲染器/插件中动态更改,而无需重新启动(请记住,等待下载或甚至插件流可能会受到影响。

相关问题