mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Introduce chrome proxy implementation based on command-line flags (issue #600).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1080 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "base/string_number_conversions.h"
|
||||
#include "chrome/browser/net/proxy_service_factory.h"
|
||||
#include "content/public/browser/gpu_data_manager.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
@@ -54,12 +55,28 @@ int CefBrowserMainParts::PreCreateThreads() {
|
||||
// before the IO thread is started.
|
||||
content::GpuDataManager::GetInstance();
|
||||
|
||||
// Initialize user preferences.
|
||||
user_prefs_ = new BrowserPrefStore();
|
||||
user_prefs_->SetInitializationCompleted();
|
||||
|
||||
// Initialize proxy configuration tracker.
|
||||
pref_proxy_config_tracker_.reset(
|
||||
ProxyServiceFactory::CreatePrefProxyConfigTracker(
|
||||
user_prefs_->CreateService()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
||||
browser_context_.reset(new CefBrowserContext());
|
||||
|
||||
// Initialize proxy configuration service.
|
||||
ChromeProxyConfigService* chrome_proxy_config_service =
|
||||
ProxyServiceFactory::CreateProxyConfigService(true);
|
||||
proxy_config_service_.reset(chrome_proxy_config_service);
|
||||
pref_proxy_config_tracker_->SetChromeProxyConfigService(
|
||||
chrome_proxy_config_service);
|
||||
|
||||
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
||||
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
|
||||
std::string port_str =
|
||||
@@ -76,9 +93,12 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
|
||||
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
||||
if (devtools_delegate_)
|
||||
devtools_delegate_->Stop();
|
||||
pref_proxy_config_tracker_->DetachFromPrefService();
|
||||
browser_context_.reset();
|
||||
}
|
||||
|
||||
void CefBrowserMainParts::PostDestroyThreads() {
|
||||
pref_proxy_config_tracker_.reset(NULL);
|
||||
|
||||
PlatformCleanup();
|
||||
}
|
||||
|
@@ -6,10 +6,14 @@
|
||||
#define CEF_LIBCEF_BROWSER_BROWSER_MAIN_H_
|
||||
#pragma once
|
||||
|
||||
#include "libcef/browser/browser_pref_store.h"
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/string_piece.h"
|
||||
#include "chrome/browser/net/pref_proxy_config_tracker.h"
|
||||
#include "content/public/browser/browser_main_parts.h"
|
||||
#include "net/proxy/proxy_config_service.h"
|
||||
|
||||
namespace base {
|
||||
class Thread;
|
||||
@@ -36,15 +40,20 @@ class CefBrowserMainParts : public content::BrowserMainParts {
|
||||
|
||||
CefBrowserContext* browser_context() const { return browser_context_.get(); }
|
||||
CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_; }
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service() {
|
||||
return proxy_config_service_.Pass();
|
||||
}
|
||||
|
||||
private:
|
||||
void PlatformInitialize();
|
||||
void PlatformCleanup();
|
||||
|
||||
scoped_ptr<CefBrowserContext> browser_context_;
|
||||
|
||||
scoped_ptr<MessageLoop> message_loop_;
|
||||
CefDevToolsDelegate* devtools_delegate_;
|
||||
scoped_ptr<MessageLoop> message_loop_;
|
||||
scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
|
||||
scoped_refptr<BrowserPrefStore> user_prefs_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefBrowserMainParts);
|
||||
};
|
||||
|
34
libcef/browser/browser_pref_store.cc
Normal file
34
libcef/browser/browser_pref_store.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "libcef/browser/browser_pref_store.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/prefs/command_line_pref_store.h"
|
||||
#include "chrome/browser/prefs/pref_service_builder.h"
|
||||
#include "chrome/browser/prefs/pref_service_simple.h"
|
||||
#include "chrome/browser/prefs/proxy_config_dictionary.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
|
||||
BrowserPrefStore::BrowserPrefStore() {
|
||||
}
|
||||
|
||||
PrefService* BrowserPrefStore::CreateService() {
|
||||
PrefServiceBuilder builder;
|
||||
builder.WithCommandLinePrefs(
|
||||
new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
|
||||
builder.WithUserPrefs(this);
|
||||
|
||||
PrefServiceSimple* service = builder.CreateSimple();
|
||||
|
||||
// Default settings.
|
||||
service->RegisterDictionaryPref(prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateDirect());
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
BrowserPrefStore::~BrowserPrefStore() {
|
||||
}
|
24
libcef/browser/browser_pref_store.h
Normal file
24
libcef/browser/browser_pref_store.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_BROWSER_PREF_STORE_H_
|
||||
#define CEF_LIBCEF_BROWSER_BROWSER_PREF_STORE_H_
|
||||
|
||||
#include "base/prefs/testing_pref_store.h"
|
||||
|
||||
class PrefService;
|
||||
|
||||
class BrowserPrefStore : public TestingPrefStore {
|
||||
public:
|
||||
BrowserPrefStore();
|
||||
|
||||
PrefService* CreateService();
|
||||
|
||||
protected:
|
||||
virtual ~BrowserPrefStore();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserPrefStore);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_BROWSER_PREF_STORE_H_
|
@@ -23,6 +23,7 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/file_path.h"
|
||||
#include "base/path_service.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "content/browser/plugin_service_impl.h"
|
||||
#include "content/public/browser/access_token_store.h"
|
||||
#include "content/public/browser/browser_url_handler.h"
|
||||
|
@@ -304,6 +304,11 @@ CefDevToolsDelegate* CefContext::devtools_delegate() const {
|
||||
devtools_delegate();
|
||||
}
|
||||
|
||||
scoped_ptr<net::ProxyConfigService> CefContext::proxy_config_service() const {
|
||||
return main_delegate_->browser_client()->browser_main_parts()->
|
||||
proxy_config_service();
|
||||
}
|
||||
|
||||
CefTraceSubscriber* CefContext::GetTraceSubscriber() {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (shutting_down_)
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "net/proxy/proxy_config_service.h"
|
||||
|
||||
namespace base {
|
||||
class WaitableEvent;
|
||||
@@ -66,6 +67,9 @@ class CefContext : public CefBase {
|
||||
CefBrowserContext* browser_context() const;
|
||||
CefDevToolsDelegate* devtools_delegate() const;
|
||||
|
||||
// Passes ownership.
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service() const;
|
||||
|
||||
CefTraceSubscriber* GetTraceSubscriber();
|
||||
|
||||
private:
|
||||
|
12
libcef/browser/proxy_stubs.cc
Normal file
12
libcef/browser/proxy_stubs.cc
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/prefs/pref_service_syncable.h"
|
||||
|
||||
// Required by PrefProxyConfigTrackerImpl::RegisterUserPrefs.
|
||||
void PrefServiceSyncable::RegisterDictionaryPref(const char* path,
|
||||
DictionaryValue* default_value,
|
||||
PrefSyncStatus sync_status) {
|
||||
NOTREACHED();
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
#include "libcef/browser/url_request_context_proxy.h"
|
||||
#include "libcef/browser/url_request_interceptor.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "base/string_util.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "chrome/browser/net/proxy_service_factory.h"
|
||||
#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/base/cert_verifier.h"
|
||||
@@ -35,9 +37,6 @@
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
#include "net/http/http_cache.h"
|
||||
#include "net/http/http_server_properties_impl.h"
|
||||
#include "net/proxy/proxy_config_service.h"
|
||||
#include "net/proxy/proxy_config_service_fixed.h"
|
||||
#include "net/proxy/proxy_resolver.h"
|
||||
#include "net/proxy/proxy_service.h"
|
||||
#include "net/url_request/static_http_user_agent_settings.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
@@ -52,76 +51,6 @@ using content::BrowserThread;
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
||||
// ProxyConfigService implementation that does nothing.
|
||||
class ProxyConfigServiceNull : public net::ProxyConfigService {
|
||||
public:
|
||||
ProxyConfigServiceNull() {}
|
||||
virtual void AddObserver(Observer* observer) OVERRIDE {}
|
||||
virtual void RemoveObserver(Observer* observer) OVERRIDE {}
|
||||
virtual ProxyConfigService::ConfigAvailability
|
||||
GetLatestProxyConfig(net::ProxyConfig* config) OVERRIDE {
|
||||
return ProxyConfigService::CONFIG_VALID;
|
||||
}
|
||||
virtual void OnLazyPoll() OVERRIDE {}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceNull);
|
||||
};
|
||||
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
// ProxyResolver implementation that forewards resolution to a CefProxyHandler.
|
||||
class CefProxyResolver : public net::ProxyResolver {
|
||||
public:
|
||||
explicit CefProxyResolver(CefRefPtr<CefProxyHandler> handler)
|
||||
: ProxyResolver(false),
|
||||
handler_(handler) {}
|
||||
virtual ~CefProxyResolver() {}
|
||||
|
||||
virtual int GetProxyForURL(const GURL& url,
|
||||
net::ProxyInfo* results,
|
||||
const net::CompletionCallback& callback,
|
||||
RequestHandle* request,
|
||||
const net::BoundNetLog& net_log) OVERRIDE {
|
||||
CefProxyInfo proxy_info;
|
||||
handler_->GetProxyForUrl(url.spec(), proxy_info);
|
||||
if (proxy_info.IsDirect())
|
||||
results->UseDirect();
|
||||
else if (proxy_info.IsNamedProxy())
|
||||
results->UseNamedProxy(proxy_info.ProxyList());
|
||||
else if (proxy_info.IsPacString())
|
||||
results->UsePacString(proxy_info.ProxyList());
|
||||
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
virtual int SetPacScript(
|
||||
const scoped_refptr<net::ProxyResolverScriptData>& pac_script,
|
||||
const net::CompletionCallback& callback) OVERRIDE {
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
virtual void CancelRequest(RequestHandle request) OVERRIDE {}
|
||||
virtual net::LoadState GetLoadState(RequestHandle request) const OVERRIDE {
|
||||
return net::LOAD_STATE_IDLE;
|
||||
}
|
||||
virtual net::LoadState GetLoadStateThreadSafe(RequestHandle request) const
|
||||
OVERRIDE {
|
||||
return net::LOAD_STATE_IDLE;
|
||||
}
|
||||
virtual void CancelSetPacScript() OVERRIDE {}
|
||||
|
||||
protected:
|
||||
CefRefPtr<CefProxyHandler> handler_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefProxyResolver);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
CefURLRequestContextGetter::CefURLRequestContextGetter(
|
||||
bool ignore_certificate_errors,
|
||||
const FilePath& base_path,
|
||||
@@ -133,13 +62,6 @@ CefURLRequestContextGetter::CefURLRequestContextGetter(
|
||||
file_loop_(file_loop) {
|
||||
// Must first be created on the UI thread.
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
#if !defined(OS_WIN)
|
||||
// We must create the proxy config service on the UI loop on Linux because it
|
||||
// must synchronously run on the glib message loop. This will be passed to
|
||||
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
|
||||
CreateProxyConfigService();
|
||||
#endif
|
||||
}
|
||||
|
||||
CefURLRequestContextGetter::~CefURLRequestContextGetter() {
|
||||
@@ -152,6 +74,7 @@ net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
|
||||
|
||||
if (!url_request_context_.get()) {
|
||||
const FilePath& cache_path = _Context->cache_path();
|
||||
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
||||
|
||||
url_request_context_.reset(new net::URLRequestContext());
|
||||
storage_.reset(
|
||||
@@ -171,64 +94,14 @@ net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
|
||||
storage_->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL));
|
||||
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
|
||||
|
||||
bool proxy_service_set = false;
|
||||
|
||||
CefRefPtr<CefApp> app = _Context->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefBrowserProcessHandler> handler =
|
||||
app->GetBrowserProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefProxyHandler> proxy_handler = handler->GetProxyHandler();
|
||||
if (proxy_handler.get()) {
|
||||
// The client will provide proxy resolution.
|
||||
CreateProxyConfigService();
|
||||
storage_->set_proxy_service(
|
||||
new net::ProxyService(proxy_config_service_.release(),
|
||||
new CefProxyResolver(proxy_handler), NULL));
|
||||
proxy_service_set = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(jam): use v8 if possible, look at chrome code.
|
||||
#if defined(OS_WIN)
|
||||
if (!proxy_service_set) {
|
||||
const CefSettings& settings = _Context->settings();
|
||||
if (!settings.auto_detect_proxy_settings_enabled) {
|
||||
// Using the system proxy resolver on Windows when "Automatically detect
|
||||
// settings" (auto-detection) is checked under LAN Settings can hurt
|
||||
// resource loading performance because the call to
|
||||
// WinHttpGetProxyForUrl in proxy_resolver_winhttp.cc will block the
|
||||
// IO thread. This is especially true for Windows 7 where auto-
|
||||
// detection is checked by default. To avoid slow resource loading on
|
||||
// Windows we only use the system proxy resolver if auto-detection is
|
||||
// unchecked.
|
||||
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0};
|
||||
if (WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) {
|
||||
if (ie_config.fAutoDetect == TRUE) {
|
||||
storage_->set_proxy_service(
|
||||
net::ProxyService::CreateWithoutProxyResolver(
|
||||
new ProxyConfigServiceNull(), NULL));
|
||||
proxy_service_set = true;
|
||||
}
|
||||
|
||||
if (ie_config.lpszAutoConfigUrl)
|
||||
GlobalFree(ie_config.lpszAutoConfigUrl);
|
||||
if (ie_config.lpszProxy)
|
||||
GlobalFree(ie_config.lpszProxy);
|
||||
if (ie_config.lpszProxyBypass)
|
||||
GlobalFree(ie_config.lpszProxyBypass);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
if (!proxy_service_set) {
|
||||
CreateProxyConfigService();
|
||||
storage_->set_proxy_service(
|
||||
net::ProxyService::CreateUsingSystemProxyResolver(
|
||||
proxy_config_service_.release(), 0, NULL));
|
||||
}
|
||||
scoped_ptr<net::ProxyService> system_proxy_service;
|
||||
system_proxy_service.reset(
|
||||
ProxyServiceFactory::CreateProxyService(
|
||||
NULL,
|
||||
url_request_context_.get(),
|
||||
_Context->proxy_config_service().release(),
|
||||
command_line));
|
||||
storage_->set_proxy_service(system_proxy_service.release());
|
||||
|
||||
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
|
||||
|
||||
|
@@ -6,9 +6,6 @@
|
||||
|
||||
namespace switches {
|
||||
|
||||
// Product version string.
|
||||
const char kProductVersion[] = "product-version";
|
||||
|
||||
// Log file path.
|
||||
const char kLogFile[] = "log-file";
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
|
||||
namespace switches {
|
||||
|
||||
extern const char kProductVersion[];
|
||||
extern const char kLogFile[];
|
||||
extern const char kLogSeverity[];
|
||||
extern const char kLogSeverity_Verbose[];
|
||||
|
@@ -6,13 +6,13 @@
|
||||
#include "include/cef_stream.h"
|
||||
#include "include/cef_version.h"
|
||||
#include "libcef/browser/scheme_registration.h"
|
||||
#include "libcef/common/cef_switches.h"
|
||||
#include "libcef/common/scheme_registrar_impl.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/string_piece.h"
|
||||
#include "base/stringprintf.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "webkit/user_agent/user_agent_util.h"
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "base/string_util.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "content/public/browser/browser_main_runner.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
|
Reference in New Issue
Block a user