mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add support for complete isolation of storage and permissions (cache, cookies, localStorage, access grants, etc) on a per-request-context basis (issue #1044).
- CefRequestContext instances can be configured using a new CefRequestContextSettings structure passed to CefRequestContext::CreateContext. - Scheme registration is now per-request-context using new CefRequestContext::RegisterSchemeHandlerFactory and ClearSchemeHandlerFactories methods. - Cookie managers are now per-request-context by default and can be retrieved using a new CefRequestContext::GetDefaultCookieManager method. - CefURLRequest::Create now accepts an optional CefRequestContext argument for associating a URL request with a context (browser process only). - The CefRequestContextHandler associated with a CefRequestContext will not be released until all objects related to that context have been destroyed. - When the cache path is empty an in-memory cache ("incognito mode") will be used for storage and no data will be persisted to disk. - Add CefSettings.user_data_path which specifies the location where user data such as spell checking dictionary files will be stored on disk. - Add asynchronous callbacks for all CefCookieManager methods. - Add PK_LOCAL_APP_DATA and PK_USER_DATA path keys for retrieving user directories via CefGetPath. - cefclient: Add "New Window" test that creates a new window unrelated to existing windows. When used in combination with `--request-context-per-browser` the new window will be given a new and isolated request context. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2040 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "libcef/browser/content_browser_client.h"
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/scheme_handler.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/browser/url_network_delegate.h"
|
||||
@@ -98,12 +96,16 @@ class CefHttpUserAgentSettings : public net::HttpUserAgentSettings {
|
||||
} // namespace
|
||||
|
||||
CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl(
|
||||
const CefRequestContextSettings& settings,
|
||||
base::MessageLoop* io_loop,
|
||||
base::MessageLoop* file_loop,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors)
|
||||
: io_loop_(io_loop),
|
||||
: settings_(settings),
|
||||
io_loop_(io_loop),
|
||||
file_loop_(file_loop),
|
||||
proxy_config_service_(proxy_config_service.Pass()),
|
||||
request_interceptors_(request_interceptors.Pass()) {
|
||||
// Must first be created on the UI thread.
|
||||
CEF_REQUIRE_UIT();
|
||||
@@ -124,19 +126,19 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
if (!url_request_context_.get()) {
|
||||
const base::FilePath& cache_path = CefContext::Get()->cache_path();
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
const CefSettings& settings = CefContext::Get()->settings();
|
||||
|
||||
base::FilePath cache_path;
|
||||
if (settings_.cache_path.length > 0)
|
||||
cache_path = base::FilePath(CefString(&settings_.cache_path));
|
||||
|
||||
url_request_context_.reset(new CefURLRequestContextImpl());
|
||||
storage_.reset(
|
||||
new net::URLRequestContextStorage(url_request_context_.get()));
|
||||
|
||||
bool persist_session_cookies =
|
||||
(settings.persist_session_cookies ||
|
||||
command_line->HasSwitch(switches::kPersistSessionCookies));
|
||||
SetCookieStoragePath(cache_path, persist_session_cookies);
|
||||
SetCookieStoragePath(cache_path,
|
||||
settings_.persist_session_cookies ? true : false);
|
||||
|
||||
storage_->set_network_delegate(new CefNetworkDelegate);
|
||||
|
||||
@@ -146,8 +148,8 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
base::WorkerPool::GetTaskRunner(true))));
|
||||
|
||||
const std::string& accept_language =
|
||||
settings.accept_language_list.length > 0 ?
|
||||
CefString(&settings.accept_language_list): "en-US,en";
|
||||
settings_.accept_language_list.length > 0 ?
|
||||
CefString(&settings_.accept_language_list): "en-US,en";
|
||||
storage_->set_http_user_agent_settings(
|
||||
new CefHttpUserAgentSettings(accept_language));
|
||||
|
||||
@@ -161,7 +163,7 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
NULL,
|
||||
url_request_context_.get(),
|
||||
url_request_context_->network_delegate(),
|
||||
CefContentBrowserClient::Get()->proxy_config_service().release(),
|
||||
proxy_config_service_.release(),
|
||||
*command_line,
|
||||
true));
|
||||
storage_->set_proxy_service(system_proxy_service.release());
|
||||
@@ -218,8 +220,7 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
network_session_params.http_server_properties =
|
||||
url_request_context_->http_server_properties();
|
||||
network_session_params.ignore_certificate_errors =
|
||||
(settings.ignore_certificate_errors ||
|
||||
command_line->HasSwitch(switches::kIgnoreCertificateErrors));
|
||||
settings_.ignore_certificate_errors ? true : false;
|
||||
|
||||
net::HttpCache* main_cache = new net::HttpCache(network_session_params,
|
||||
main_backend);
|
||||
@@ -232,13 +233,18 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
|
||||
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
|
||||
new net::URLRequestJobFactoryImpl());
|
||||
job_factory_impl_ = job_factory.get();
|
||||
url_request_manager_.reset(new CefURLRequestManager(job_factory.get()));
|
||||
|
||||
// Install internal scheme handlers that cannot be overridden.
|
||||
scheme::InstallInternalProtectedHandlers(job_factory.get(),
|
||||
url_request_manager_.get(),
|
||||
&protocol_handlers_,
|
||||
ftp_transaction_factory_.get());
|
||||
protocol_handlers_.clear();
|
||||
|
||||
// Register internal scheme handlers that can be overridden.
|
||||
scheme::RegisterInternalHandlers(url_request_manager_.get());
|
||||
|
||||
request_interceptors_.push_back(new CefRequestInterceptor());
|
||||
|
||||
// Set up interceptors in the reverse order.
|
||||
@@ -256,7 +262,12 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
||||
storage_->set_job_factory(top_job_factory.release());
|
||||
|
||||
#if defined(USE_NSS)
|
||||
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
||||
// Only do this for the first (global) request context.
|
||||
static bool request_context_for_nss_set = false;
|
||||
if (!request_context_for_nss_set) {
|
||||
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
||||
request_context_for_nss_set = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -347,6 +358,16 @@ void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes(
|
||||
delete [] arr;
|
||||
}
|
||||
|
||||
void CefURLRequestContextGetterImpl::AddHandler(
|
||||
CefRefPtr<CefRequestContextHandler> handler) {
|
||||
if (!CEF_CURRENTLY_ON_IOT()) {
|
||||
CEF_POST_TASK(CEF_IOT,
|
||||
base::Bind(&CefURLRequestContextGetterImpl::AddHandler, this, handler));
|
||||
return;
|
||||
}
|
||||
handler_list_.push_back(handler);
|
||||
}
|
||||
|
||||
void CefURLRequestContextGetterImpl::CreateProxyConfigService() {
|
||||
if (proxy_config_service_.get())
|
||||
return;
|
||||
|
Reference in New Issue
Block a user