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:
Marshall Greenblatt
2015-03-02 20:25:14 +00:00
parent 031f192e5a
commit ca0e381681
91 changed files with 3816 additions and 1347 deletions

View File

@ -10,10 +10,9 @@
#include "include/cef_version.h"
#include "include/cef_web_plugin.h"
#include "libcef/browser/context.h"
#include "libcef/browser/frame_host_impl.h"
#include "libcef/browser/internal_scheme_handler.h"
#include "libcef/browser/scheme_impl.h"
#include "libcef/browser/url_request_manager.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/content_client.h"
@ -182,7 +181,8 @@ class Delegate : public InternalHandlerDelegate {
public:
Delegate() {}
bool OnRequest(CefRefPtr<CefRequest> request,
bool OnRequest(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request,
Action* action) override {
GURL url = GURL(request->GetURL().ToString());
std::string path = url.path();
@ -200,7 +200,7 @@ class Delegate : public InternalHandlerDelegate {
handled = OnLicense(action);
break;
case CHROME_VERSION:
handled = OnVersion(action);
handled = OnVersion(browser, action);
break;
default:
break;
@ -245,7 +245,8 @@ class Delegate : public InternalHandlerDelegate {
return true;
}
bool OnVersion(Action* action) {
bool OnVersion(CefRefPtr<CefBrowser> browser,
Action* action) {
base::StringPiece piece = CefContentClient::Get()->GetDataResource(
IDR_CEF_VERSION_HTML, ui::SCALE_FACTOR_NONE);
if (piece.empty()) {
@ -276,7 +277,8 @@ class Delegate : public InternalHandlerDelegate {
parser.Add("USERAGENT", CefContentClient::Get()->GetUserAgent());
parser.Add("COMMANDLINE", GetCommandLine());
parser.Add("MODULEPATH", GetModulePath());
parser.Add("CACHEPATH", CefString(CefContext::Get()->cache_path().value()));
parser.Add("CACHEPATH",
browser->GetHost()->GetRequestContext()->GetCachePath());
std::string tmpl = piece.as_string();
parser.Parse(&tmpl);
@ -328,15 +330,20 @@ void DidFinishChromeVersionLoad(CefRefPtr<CefFrame> frame) {
class ChromeProtocolHandlerWrapper :
public net::URLRequestJobFactory::ProtocolHandler {
public:
explicit ChromeProtocolHandlerWrapper(
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> chrome_protocol_handler)
: chrome_protocol_handler_(chrome_protocol_handler.Pass()) {
ChromeProtocolHandlerWrapper(
CefURLRequestManager* request_manager,
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler)
: request_manager_(request_manager),
chrome_protocol_handler_(chrome_protocol_handler.Pass()) {
DCHECK(request_manager_);
}
net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override {
// Keep synchronized with the checks in ChromeProtocolHandler::MaybeCreateJob.
// Keep synchronized with the checks in
// ChromeProtocolHandler::MaybeCreateJob.
if (content::ViewHttpCacheJobFactory::IsSupportedURL(request->url()) ||
(request->url().SchemeIs(content::kChromeUIScheme) &&
request->url().host() == content::kChromeUIAppCacheInternalsHost) ||
@ -347,21 +354,24 @@ class ChromeProtocolHandlerWrapper :
#endif
(request->url().SchemeIs(content::kChromeUIScheme) &&
request->url().host() == content::kChromeUIHistogramHost)) {
return chrome_protocol_handler_->MaybeCreateJob(request, network_delegate);
return chrome_protocol_handler_->MaybeCreateJob(request,
network_delegate);
}
// Use the protocol handler registered with CEF.
return scheme::GetRequestJob(request, network_delegate);
return request_manager_->GetRequestJob(request, network_delegate);
}
private:
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> chrome_protocol_handler_;
CefURLRequestManager* request_manager_;
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler_;
};
} // namespace
void RegisterChromeHandler() {
CefRegisterSchemeHandlerFactory(
void RegisterChromeHandler(CefURLRequestManager* request_manager) {
request_manager->AddFactory(
content::kChromeUIScheme,
std::string(),
CreateInternalHandlerFactory(
@ -393,10 +403,12 @@ void DidFinishChromeLoad(CefRefPtr<CefFrame> frame,
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
WrapChromeProtocolHandler(
CefURLRequestManager* request_manager,
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler) {
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> ret(
new ChromeProtocolHandlerWrapper(chrome_protocol_handler.Pass()));
new ChromeProtocolHandlerWrapper(request_manager,
chrome_protocol_handler.Pass()));
return ret.Pass();
}