Structural improvements for request handling (issue #1044)

- Add new CefRequestContext and CefRequestContextHandler classes.
- Add CefRequestContext argument to CefBrowserHost static factory methods.
- Move GetCookieManager from CefRequestHandler to CefRequestContextHandler.
- Use BrowserContext as the root proxy object for network requests.
- Move accessors for CefBrowserMainParts members from CefContext to CefContentBrowserClient.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1424 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-09-03 16:43:31 +00:00
parent 935a35f21c
commit 385be456c3
57 changed files with 2288 additions and 440 deletions

View File

@@ -1,73 +1,22 @@
// Copyright (c) 2011 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.
// 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_CONTEXT_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#pragma once
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "net/url_request/url_request_job_factory.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetter;
class CefBrowserContext : public content::BrowserContext {
public:
CefBrowserContext();
virtual ~CefBrowserContext();
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers);
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) = 0;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers);
private:
class CefResourceContext;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
content::ProtocolHandlerMap* protocol_handlers) = 0;
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include <map>
@@ -157,7 +157,7 @@ class CefGeolocationPermissionContext
} // namespace
class CefBrowserContext::CefResourceContext : public content::ResourceContext {
class CefBrowserContextImpl::CefResourceContext : public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
virtual ~CefResourceContext() {}
@@ -188,11 +188,11 @@ class CefBrowserContext::CefResourceContext : public content::ResourceContext {
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContext::CefBrowserContext()
CefBrowserContextImpl::CefBrowserContextImpl()
: resource_context_(new CefResourceContext) {
}
CefBrowserContext::~CefBrowserContext() {
CefBrowserContextImpl::~CefBrowserContextImpl() {
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_.get())
@@ -204,16 +204,16 @@ CefBrowserContext::~CefBrowserContext() {
}
}
base::FilePath CefBrowserContext::GetPath() const {
base::FilePath CefBrowserContextImpl::GetPath() const {
return _Context->cache_path();
}
bool CefBrowserContext::IsOffTheRecord() const {
bool CefBrowserContextImpl::IsOffTheRecord() const {
return false;
}
content::DownloadManagerDelegate*
CefBrowserContext::GetDownloadManagerDelegate() {
CefBrowserContextImpl::GetDownloadManagerDelegate() {
DCHECK(!download_manager_delegate_.get());
content::DownloadManager* manager = BrowserContext::GetDownloadManager(this);
@@ -221,40 +221,36 @@ content::DownloadManagerDelegate*
return download_manager_delegate_.get();
}
net::URLRequestContextGetter* CefBrowserContext::GetRequestContext() {
net::URLRequestContextGetter* CefBrowserContextImpl::GetRequestContext() {
CEF_REQUIRE_UIT();
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetRequestContextForRenderProcess(
CefBrowserContextImpl::GetRequestContextForRenderProcess(
int renderer_child_id) {
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserByChildID(renderer_child_id);
if (browser.get())
return browser->GetRequestContext();
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContext() {
CefBrowserContextImpl::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContextForRenderProcess(
CefBrowserContextImpl::GetMediaRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContext::GetMediaRequestContextForStoragePartition(
CefBrowserContextImpl::GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
return GetRequestContext();
}
void CefBrowserContext::RequestMIDISysExPermission(
void CefBrowserContextImpl::RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
@@ -263,12 +259,12 @@ void CefBrowserContext::RequestMIDISysExPermission(
callback.Run(false);
}
content::ResourceContext* CefBrowserContext::GetResourceContext() {
content::ResourceContext* CefBrowserContextImpl::GetResourceContext() {
return resource_context_.get();
}
content::GeolocationPermissionContext*
CefBrowserContext::GetGeolocationPermissionContext() {
CefBrowserContextImpl::GetGeolocationPermissionContext() {
if (!geolocation_permission_context_) {
geolocation_permission_context_ =
new CefGeolocationPermissionContext();
@@ -276,11 +272,11 @@ content::GeolocationPermissionContext*
return geolocation_permission_context_;
}
quota::SpecialStoragePolicy* CefBrowserContext::GetSpecialStoragePolicy() {
quota::SpecialStoragePolicy* CefBrowserContextImpl::GetSpecialStoragePolicy() {
return NULL;
}
net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_ = new CefURLRequestContextGetter(
@@ -292,7 +288,7 @@ net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
}
net::URLRequestContextGetter*
CefBrowserContext::CreateRequestContextForStoragePartition(
CefBrowserContextImpl::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {

View File

@@ -0,0 +1,72 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#pragma once
#include "libcef/browser/browser_context.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetter;
class CefBrowserContextImpl : public CefBrowserContext {
public:
CefBrowserContextImpl();
virtual ~CefBrowserContextImpl();
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// CefBrowserContext methods.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
private:
class CefResourceContext;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_

View File

@@ -0,0 +1,154 @@
// 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 "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/threading/thread.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
using content::BrowserThread;
class CefBrowserContextProxy::CefResourceContext : public content::ResourceContext {
public:
CefResourceContext() : getter_(NULL) {}
virtual ~CefResourceContext() {}
// ResourceContext implementation:
virtual net::HostResolver* GetHostResolver() OVERRIDE {
CHECK(getter_);
return getter_->GetHostResolver();
}
virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
CHECK(getter_);
return getter_->GetURLRequestContext();
}
virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
return true;
}
virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
return true;
}
void set_url_request_context_getter(CefURLRequestContextGetterProxy* getter) {
getter_ = getter;
}
private:
CefURLRequestContextGetterProxy* getter_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext);
};
CefBrowserContextProxy::CefBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent)
: refct_(0),
handler_(handler),
parent_(parent),
resource_context_(new CefResourceContext) {
}
CefBrowserContextProxy::~CefBrowserContextProxy() {
if (resource_context_.get()) {
BrowserThread::DeleteSoon(
BrowserThread::IO, FROM_HERE, resource_context_.release());
}
}
base::FilePath CefBrowserContextProxy::GetPath() const {
return parent_->GetPath();
}
bool CefBrowserContextProxy::IsOffTheRecord() const {
return parent_->IsOffTheRecord();
}
content::DownloadManagerDelegate*
CefBrowserContextProxy::GetDownloadManagerDelegate() {
DCHECK(!download_manager_delegate_.get());
content::DownloadManager* manager = BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
return download_manager_delegate_.get();
}
net::URLRequestContextGetter* CefBrowserContextProxy::GetRequestContext() {
CEF_REQUIRE_UIT();
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContext() {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContextForRenderProcess(
int renderer_child_id) {
return GetRequestContext();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
return GetRequestContext();
}
void CefBrowserContextProxy::RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) {
// TODO(CEF): Implement Web MIDI API permission handling.
callback.Run(false);
}
content::ResourceContext* CefBrowserContextProxy::GetResourceContext() {
return resource_context_.get();
}
content::GeolocationPermissionContext*
CefBrowserContextProxy::GetGeolocationPermissionContext() {
return parent_->GetGeolocationPermissionContext();
}
quota::SpecialStoragePolicy* CefBrowserContextProxy::GetSpecialStoragePolicy() {
return parent_->GetSpecialStoragePolicy();
}
net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_ =
new CefURLRequestContextGetterProxy(handler_,
static_cast<CefURLRequestContextGetter*>(
CefContentBrowserClient::Get()->request_context().get()));
resource_context_->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
net::URLRequestContextGetter*
CefBrowserContextProxy::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {
return NULL;
}

View File

@@ -0,0 +1,83 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "libcef/browser/browser_context.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetterProxy;
// This class is only accessed on the UI thread.
class CefBrowserContextProxy : public CefBrowserContext {
public:
CefBrowserContextProxy(CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContext* parent);
virtual ~CefBrowserContextProxy();
// Reference counting and object life span is managed by
// CefContentBrowserClient.
void AddRef() { refct_++; }
bool Release() { return (--refct_ == 0); }
// BrowserContext methods.
virtual base::FilePath GetPath() const OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
virtual net::URLRequestContextGetter*
GetMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) OVERRIDE;
virtual void RequestMIDISysExPermission(
int render_process_id,
int render_view_id,
const GURL& requesting_frame,
const MIDISysExPermissionCallback& callback) OVERRIDE;
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// CefBrowserContext methods.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
class CefResourceContext;
int refct_;
CefRefPtr<CefRequestContextHandler> handler_;
CefBrowserContext* parent_;
scoped_ptr<CefResourceContext> resource_context_;
scoped_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetterProxy> url_request_getter_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextProxy);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_

View File

@@ -18,10 +18,9 @@
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/navigate_params.h"
#include "libcef/browser/render_widget_host_view_osr.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "libcef/browser/web_contents_view_osr.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
@@ -57,21 +56,24 @@ class CreateBrowserHelper {
CreateBrowserHelper(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings)
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context)
: window_info_(windowInfo),
client_(client),
url_(url),
settings_(settings) {}
settings_(settings),
request_context_(request_context) {}
CefWindowInfo window_info_;
CefRefPtr<CefClient> client_;
CefString url_;
CefBrowserSettings settings_;
CefRefPtr<CefRequestContext> request_context_;
};
void CreateBrowserWithHelper(CreateBrowserHelper* helper) {
CefBrowserHost::CreateBrowserSync(helper->window_info_, helper->client_,
helper->url_, helper->settings_);
helper->url_, helper->settings_, helper->request_context_);
delete helper;
}
@@ -215,10 +217,12 @@ class CefRunFileDialogCallbackWrapper
// -----------------------------------------------------------------------------
// static
bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings) {
bool CefBrowserHost::CreateBrowser(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
@@ -248,7 +252,8 @@ bool CefBrowserHost::CreateBrowser(const CefWindowInfo& windowInfo,
// Create the browser on the UI thread.
CreateBrowserHelper* helper =
new CreateBrowserHelper(windowInfo, client, url, new_settings);
new CreateBrowserHelper(windowInfo, client, url, new_settings,
request_context);
CEF_POST_TASK(CEF_UIT, base::Bind(CreateBrowserWithHelper, helper));
return true;
@@ -259,7 +264,8 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings) {
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
@@ -304,7 +310,7 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
DCHECK(!info->is_popup());
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::Create(windowInfo, new_settings, client, NULL, info,
NULL);
NULL, request_context);
if (!url.empty()) {
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url, content::Referrer(),
content::PAGE_TRANSITION_TYPED, std::string());
@@ -326,16 +332,27 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener) {
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context) {
CEF_REQUIRE_UIT();
DCHECK(browser_info.get());
// If |opener| is non-NULL it must be a popup window.
DCHECK(opener == NULL || browser_info->is_popup());
if (web_contents == NULL) {
if (!web_contents) {
CefBrowserContext* browser_context = NULL;
if (request_context.get()) {
CefRequestContextImpl* request_context_impl =
static_cast<CefRequestContextImpl*>(request_context.get());
browser_context = request_context_impl->GetOrCreateBrowserContext();
} else {
browser_context = CefContentBrowserClient::Get()->browser_context();
}
DCHECK(browser_context);
content::WebContents::CreateParams create_params(
_Context->browser_context());
browser_context);
web_contents = content::WebContents::Create(create_params);
}
@@ -347,14 +364,6 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
return NULL;
}
if (browser->IsWindowRenderingDisabled()) {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents->GetRenderViewHost()->GetView());
if (view)
view->set_browser_impl(browser);
}
if (client.get()) {
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
if (handler.get())
@@ -417,28 +426,19 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::GetBrowserByRoutingID(
return GetBrowserForHost(render_view_host);
} else {
// Use the thread-safe approach.
return _Context->GetBrowserByRoutingID(render_process_id, render_view_id);
}
}
// static
CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::GetBrowserByChildID(
int render_process_id) {
if (CEF_CURRENTLY_ON_UIT()) {
// Use the non-thread-safe but potentially faster approach.
content::RenderWidgetHost::List widgets =
content::RenderWidgetHost::GetRenderWidgetHosts();
for (size_t i = 0; i < widgets.size(); ++i) {
if (widgets[i]->GetProcess()->GetID() == render_process_id &&
widgets[i]->IsRenderView()) {
return GetBrowserForHost(content::RenderViewHost::From(widgets[i]));
scoped_refptr<CefBrowserInfo> info =
CefContentBrowserClient::Get()->GetBrowserInfo(render_process_id,
render_view_id);
if (info.get()) {
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
if (!browser.get()) {
LOG(WARNING) << "Found browser id " << info->browser_id() <<
" but no browser object matching process id " <<
render_process_id << " and view id " << render_view_id;
}
return browser;
}
return NULL;
} else {
// Use the thread-safe approach.
return _Context->GetBrowserByRoutingID(render_process_id, -1);
}
}
@@ -504,6 +504,10 @@ CefRefPtr<CefClient> CefBrowserHostImpl::GetClient() {
return client_;
}
CefRefPtr<CefRequestContext> CefBrowserHostImpl::GetRequestContext() {
return request_context_;
}
CefString CefBrowserHostImpl::GetDevToolsURL(bool http_scheme) {
base::AutoLock lock_scope(state_lock_);
return (http_scheme ? devtools_url_http_ : devtools_url_chrome_);
@@ -583,7 +587,8 @@ void CefBrowserHostImpl::StartDownload(const CefString& url) {
if (!web_contents())
return;
CefBrowserContext* context = _Context->browser_context();
CefBrowserContext* context =
static_cast<CefBrowserContext*>(web_contents()->GetBrowserContext());
if (!context)
return;
@@ -1103,8 +1108,6 @@ void CefBrowserHostImpl::DestroyBrowser() {
DetachAllFrames();
request_context_proxy_ = NULL;
CefContentBrowserClient::Get()->RemoveBrowserInfo(browser_info_);
browser_info_->set_browser(NULL);
}
@@ -1121,17 +1124,6 @@ content::WebContents* CefBrowserHostImpl::GetWebContents() const {
return web_contents_.get();
}
net::URLRequestContextGetter* CefBrowserHostImpl::GetRequestContext() {
CEF_REQUIRE_UIT();
if (!request_context_proxy_) {
request_context_proxy_ =
new CefURLRequestContextGetterProxy(this,
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get()));
}
return request_context_proxy_.get();
}
CefRefPtr<CefFrame> CefBrowserHostImpl::GetFrameForRequest(
net::URLRequest* request) {
CEF_REQUIRE_IOT();
@@ -1695,7 +1687,7 @@ void CefBrowserHostImpl::WebContentsCreated(
CefRefPtr<CefBrowserHostImpl> browser = CefBrowserHostImpl::Create(
pending_popup_info->window_info, pending_popup_info->settings,
pending_popup_info->client, new_contents, info, opener);
pending_popup_info->client, new_contents, info, opener, NULL);
}
void CefBrowserHostImpl::DidNavigateMainFramePostCommit(
@@ -1774,7 +1766,7 @@ void CefBrowserHostImpl::RequestMediaAccessPermission(
case content::MEDIA_ENUMERATE_DEVICES:
// Get the default devices for the request.
CefMediaCaptureDevicesDispatcher::GetInstance()->
GetDefaultDevices(_Context->pref_service(),
GetDefaultDevices(CefContentBrowserClient::Get()->pref_service(),
microphone_requested,
webcam_requested,
&devices);
@@ -1795,7 +1787,8 @@ void CefBrowserHostImpl::RenderViewCreated(
render_view_host->GetRoutingID());
// Update the DevTools URLs, if any.
CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate();
CefDevToolsDelegate* devtools_delegate =
CefContentBrowserClient::Get()->devtools_delegate();
if (devtools_delegate) {
base::AutoLock lock_scope(state_lock_);
devtools_url_http_ =
@@ -2096,6 +2089,10 @@ CefBrowserHostImpl::CefBrowserHostImpl(
web_contents_.reset(web_contents);
web_contents->SetDelegate(this);
CefBrowserContext* browser_context =
static_cast<CefBrowserContext*>(web_contents->GetBrowserContext());
request_context_ = new CefRequestContextImpl(browser_context);
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
content::Source<content::WebContents>(web_contents));
@@ -2118,6 +2115,14 @@ CefBrowserHostImpl::CefBrowserHostImpl(
// Make sure RenderViewCreated is called at least one time.
RenderViewCreated(web_contents->GetRenderViewHost());
if (IsWindowRenderingDisabled()) {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents->GetRenderViewHost()->GetView());
if (view)
view->set_browser_impl(this);
}
}
CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(

View File

@@ -29,7 +29,6 @@
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/file_chooser_params.h"
#include "net/url_request/url_request_context_getter.h"
namespace content {
struct NativeWebKeyboardEvent;
@@ -87,7 +86,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefWindowHandle opener);
CefWindowHandle opener,
CefRefPtr<CefRequestContext> request_context);
// Returns the browser associated with the specified RenderViewHost.
static CefRefPtr<CefBrowserHostImpl> GetBrowserForHost(
@@ -101,11 +101,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Returns the browser associated with the specified routing IDs.
static CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(
int render_process_id, int render_view_id);
// Returns the first browser associated with the specified child process ID.
// There may be multiple browsers using the same render process so this method
// should be used with caution.
static CefRefPtr<CefBrowserHostImpl> GetBrowserByChildID(
int render_process_id);
// Returns true if window rendering is disabled in CefWindowInfo.
static bool IsWindowRenderingDisabled(const CefWindowInfo& info);
@@ -118,6 +113,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
virtual CefRefPtr<CefRequestContext> GetRequestContext() OVERRIDE;
virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE;
virtual double GetZoomLevel() OVERRIDE;
virtual void SetZoomLevel(double zoomLevel) OVERRIDE;
@@ -190,9 +186,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Returns a pointer to the WebContents.
content::WebContents* GetWebContents() const;
// Returns the browser-specific request context.
net::URLRequestContextGetter* GetRequestContext();
// Returns the frame associated with the specified URLRequest.
CefRefPtr<CefFrame> GetFrameForRequest(net::URLRequest* request);
@@ -487,6 +480,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
scoped_ptr<content::WebContents> web_contents_;
scoped_refptr<CefBrowserInfo> browser_info_;
CefWindowHandle opener_;
CefRefPtr<CefRequestContext> request_context_;
// Pending popup information. Access must be protected by
// |pending_popup_info_lock_|.
@@ -541,9 +535,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
// Used for managing notification subscriptions.
scoped_ptr<content::NotificationRegistrar> registrar_;
// Used for proxying cookie requests.
scoped_refptr<net::URLRequestContextGetter> request_context_proxy_;
// Manages response registrations.
scoped_ptr<CefResponseManager> response_manager_;

View File

@@ -6,9 +6,9 @@
#include <string>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_message_loop.h"
#include "libcef/browser/context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/devtools_delegate.h"
#include "libcef/common/net_resource_provider.h"
@@ -81,7 +81,8 @@ int CefBrowserMainParts::PreCreateThreads() {
}
void CefBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new CefBrowserContext());
// Create the global browser context.
global_browser_context_.reset(new CefBrowserContextImpl());
// Initialize the proxy configuration service. This needs to occur before
// CefURLRequestContextGetter::GetURLRequestContext() is called for the
@@ -92,7 +93,7 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
// Initialize the request context getter. This indirectly triggers a call
// to CefURLRequestContextGetter::GetURLRequestContext() on the IO thread.
_Context->set_request_context(browser_context_->GetRequestContext());
global_request_context_ = global_browser_context_->GetRequestContext();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
@@ -111,8 +112,13 @@ void CefBrowserMainParts::PostMainMessageLoopRun() {
if (devtools_delegate_)
devtools_delegate_->Stop();
pref_proxy_config_tracker_->DetachFromPrefService();
_Context->set_request_context(NULL);
browser_context_.reset();
// Only the global browser context should still exist.
DCHECK(browser_contexts_.empty());
browser_contexts_.clear();
global_request_context_ = NULL;
global_browser_context_.reset();
}
void CefBrowserMainParts::PostDestroyThreads() {
@@ -125,3 +131,19 @@ void CefBrowserMainParts::PostDestroyThreads() {
PlatformCleanup();
}
void CefBrowserMainParts::AddBrowserContext(CefBrowserContext* context) {
browser_contexts_.push_back(context);
}
void CefBrowserMainParts::RemoveBrowserContext(CefBrowserContext* context) {
ScopedVector<CefBrowserContext>::iterator it = browser_contexts_.begin();
for (; it != browser_contexts_.end(); ++it) {
if (*it == context) {
browser_contexts_.erase(it);
return;
}
}
NOTREACHED();
}

View File

@@ -10,11 +10,13 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/prefs/pref_service.h"
#include "base/strings/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"
#include "net/url_request/url_request_context_getter.h"
namespace base {
class MessageLoop;
@@ -44,18 +46,30 @@ class CefBrowserMainParts : public content::BrowserMainParts {
virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;
CefBrowserContext* browser_context() const { return browser_context_.get(); }
CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_.get(); }
CefBrowserContext* browser_context() const {
return global_browser_context_.get();
}
scoped_refptr<net::URLRequestContextGetter> request_context() const {
return global_request_context_;
}
CefDevToolsDelegate* devtools_delegate() const {
return devtools_delegate_.get();
}
PrefService* pref_service() const { return pref_service_.get(); }
scoped_ptr<net::ProxyConfigService> proxy_config_service() {
return proxy_config_service_.Pass();
}
void AddBrowserContext(CefBrowserContext* context);
void RemoveBrowserContext(CefBrowserContext* context);
private:
void PlatformInitialize();
void PlatformCleanup();
scoped_ptr<CefBrowserContext> browser_context_;
scoped_ptr<CefBrowserContext> global_browser_context_;
scoped_refptr<net::URLRequestContextGetter> global_request_context_;
ScopedVector<CefBrowserContext> browser_contexts_;
scoped_ptr<CefDevToolsDelegate> devtools_delegate_;
scoped_ptr<base::MessageLoop> message_loop_;
scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;

View File

@@ -12,6 +12,7 @@
#include "libcef/browser/origin_whitelist_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/content_client.h"
#include "libcef/common/values_impl.h"
#include "base/compiler_specific.h"
@@ -61,7 +62,7 @@ void CefBrowserMessageFilter::OnGetNewRenderThreadInfo(
CefProcessHostMsg_GetNewRenderThreadInfo_Params* params) {
GetCrossOriginWhitelistEntries(&params->cross_origin_whitelist_entries);
CefRefPtr<CefApp> app = _Context->application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();

View File

@@ -7,7 +7,7 @@
#include <string>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_user_data.h"
#include "libcef/common/http_header_utils.h"
@@ -119,7 +119,8 @@ class CefBrowserURLRequest::Context
fetcher_.reset(net::URLFetcher::Create(url, request_type,
fetcher_delegate_.get()));
fetcher_->SetRequestContext(_Context->request_context());
fetcher_->SetRequestContext(
CefContentBrowserClient::Get()->request_context());
CefRequest::HeaderMap headerMap;
request_->GetHeaderMap(headerMap);

View File

@@ -7,13 +7,13 @@
#include <algorithm>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_main.h"
#include "libcef/browser/browser_message_filter.h"
#include "libcef/browser/browser_settings.h"
#include "libcef/browser/chrome_scheme_handler.h"
#include "libcef/browser/context.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/resource_dispatcher_host_delegate.h"
#include "libcef/browser/speech_recognition_manager_delegate.h"
@@ -51,7 +51,8 @@ class CefAccessTokenStore : public content::AccessTokenStore {
virtual void LoadAccessTokens(
const LoadAccessTokensCallbackType& callback) OVERRIDE {
callback.Run(access_token_set_, _Context->request_context());
callback.Run(access_token_set_,
CefContentBrowserClient::Get()->request_context());
}
virtual void SaveAccessToken(
@@ -394,6 +395,39 @@ scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfo(
return scoped_refptr<CefBrowserInfo>();
}
CefBrowserContext* CefContentBrowserClient::CreateBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_UIT();
CefBrowserContextProxy* context =
new CefBrowserContextProxy(handler, browser_context());
browser_main_parts_->AddBrowserContext(context);
context->AddRef();
return context;
}
void CefContentBrowserClient::AddBrowserContextReference(
CefBrowserContext* context) {
CEF_REQUIRE_UIT();
// Skip the global browser context.
if (context == browser_context())
return;
CefBrowserContextProxy* proxy = static_cast<CefBrowserContextProxy*>(context);
proxy->AddRef();
}
void CefContentBrowserClient::RemoveBrowserContextReference(
CefBrowserContext* context) {
CEF_REQUIRE_UIT();
// Skip the global browser context.
if (context == browser_context())
return;
CefBrowserContextProxy* proxy = static_cast<CefBrowserContextProxy*>(context);
if (proxy->Release())
browser_main_parts_->RemoveBrowserContext(proxy);
}
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
browser_main_parts_ = new CefBrowserMainParts(parameters);
@@ -420,13 +454,15 @@ CefContentBrowserClient::OverrideCreateWebContentsView(
void CefContentBrowserClient::RenderProcessHostCreated(
content::RenderProcessHost* host) {
host->GetChannel()->AddFilter(new CefBrowserMessageFilter(host));
AddBrowserContextReference(
static_cast<CefBrowserContext*>(host->GetBrowserContext()));
}
net::URLRequestContextGetter* CefContentBrowserClient::CreateRequestContext(
content::BrowserContext* content_browser_context,
content::ProtocolHandlerMap* protocol_handlers) {
CefBrowserContext* cef_browser_context =
CefBrowserContextForBrowserContext(content_browser_context);
static_cast<CefBrowserContext*>(content_browser_context);
return cef_browser_context->CreateRequestContext(protocol_handlers);
}
@@ -437,7 +473,7 @@ CefContentBrowserClient::CreateRequestContextForStoragePartition(
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers) {
CefBrowserContext* cef_browser_context =
CefBrowserContextForBrowserContext(content_browser_context);
static_cast<CefBrowserContext*>(content_browser_context);
return cef_browser_context->CreateRequestContextForStoragePartition(
partition_path, in_memory, protocol_handlers);
}
@@ -501,7 +537,7 @@ void CefContentBrowserClient::AppendExtraCommandLineSwitches(
}
#endif // defined(OS_LINUX)
CefRefPtr<CefApp> app = _Context->application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
@@ -756,9 +792,24 @@ void CefContentBrowserClient::set_last_create_window_params(
last_create_window_params_ = params;
}
CefBrowserContext*
CefContentBrowserClient::CefBrowserContextForBrowserContext(
content::BrowserContext* content_browser_context) {
DCHECK_EQ(content_browser_context, browser_main_parts_->browser_context());
CefBrowserContext* CefContentBrowserClient::browser_context() const {
return browser_main_parts_->browser_context();
}
scoped_refptr<net::URLRequestContextGetter>
CefContentBrowserClient::request_context() const {
return browser_main_parts_->request_context();
}
CefDevToolsDelegate* CefContentBrowserClient::devtools_delegate() const {
return browser_main_parts_->devtools_delegate();
}
PrefService* CefContentBrowserClient::pref_service() const {
return browser_main_parts_->pref_service();
}
scoped_ptr<net::ProxyConfigService>
CefContentBrowserClient::proxy_config_service() const {
return browser_main_parts_->proxy_config_service();
}

View File

@@ -12,17 +12,23 @@
#include <string>
#include <utility>
#include "include/cef_request_context_handler.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/content_browser_client.h"
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
class CefBrowserContext;
class CefBrowserInfo;
class CefBrowserMainParts;
class CefDevToolsDelegate;
class CefResourceDispatcherHostDelegate;
class PrefService;
namespace content {
class PluginServiceFilter;
@@ -37,10 +43,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
// Returns the singleton CefContentBrowserClient instance.
static CefContentBrowserClient* Get();
CefBrowserMainParts* browser_main_parts() const {
return browser_main_parts_;
}
// Methods for managing CefBrowserInfo life span. Do not add new callers of
// these methods.
// During popup window creation there is a race between the call to
@@ -56,10 +58,22 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
// Retrieves the CefBrowserInfo matching the specified IDs or an empty
// pointer if no match is found. It is allowed to add new callers of this
// method but consider using CefContext::GetBrowserByRoutingID() instead.
// method but consider using CefBrowserHostImpl::GetBrowserByRoutingID()
// instead.
scoped_refptr<CefBrowserInfo> GetBrowserInfo(int render_process_id,
int render_view_id);
// Create and return a new CefBrowserContextProxy object.
CefBrowserContext* CreateBrowserContextProxy(
CefRefPtr<CefRequestContextHandler> handler);
// BrowserContexts are nominally owned by RenderViewHosts and
// CefRequestContextImpls. Keep track of how many objects reference a given
// context and delete the context when the reference count reaches zero.
void AddBrowserContextReference(CefBrowserContext* context);
void RemoveBrowserContextReference(CefBrowserContext* context);
// ContentBrowserClient implementation.
virtual content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) OVERRIDE;
virtual content::WebContentsViewPort* OverrideCreateWebContentsView(
@@ -145,10 +159,15 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
return use_osr_next_contents_view_;
}
private:
CefBrowserContext* CefBrowserContextForBrowserContext(
content::BrowserContext* content_browser_context);
CefBrowserContext* browser_context() const;
scoped_refptr<net::URLRequestContextGetter> request_context() const;
CefDevToolsDelegate* devtools_delegate() const;
PrefService* pref_service() const;
// Passes ownership.
scoped_ptr<net::ProxyConfigService> proxy_config_service() const;
private:
CefBrowserMainParts* browser_main_parts_;
scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;

View File

@@ -21,6 +21,8 @@
#include "base/synchronization/waitable_event.h"
#include "content/public/app/content_main.h"
#include "content/public/app/content_main_runner.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "ui/base/ui_base_switches.h"
@@ -284,46 +286,6 @@ bool CefContext::OnInitThread() {
return (base::PlatformThread::CurrentId() == init_thread_id_);
}
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByRoutingID(
int render_process_id, int render_view_id) {
scoped_refptr<CefBrowserInfo> info =
CefContentBrowserClient::Get()->GetBrowserInfo(render_process_id,
render_view_id);
if (info.get()) {
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
if (!browser.get()) {
LOG(WARNING) << "Found browser id " << info->browser_id() <<
" but no browser object matching process id " <<
render_process_id << " and view id " << render_view_id;
}
return browser;
}
return NULL;
}
CefRefPtr<CefApp> CefContext::application() const {
return main_delegate_->content_client()->application();
}
CefBrowserContext* CefContext::browser_context() const {
return main_delegate_->browser_client()->browser_main_parts()->
browser_context();
}
CefDevToolsDelegate* CefContext::devtools_delegate() const {
return main_delegate_->browser_client()->browser_main_parts()->
devtools_delegate();
}
scoped_ptr<net::ProxyConfigService> CefContext::proxy_config_service() const {
return main_delegate_->browser_client()->browser_main_parts()->
proxy_config_service();
}
PrefService* CefContext::pref_service() const {
return main_delegate_->browser_client()->browser_main_parts()->pref_service();
}
CefTraceSubscriber* CefContext::GetTraceSubscriber() {
CEF_REQUIRE_UIT();
if (shutting_down_)
@@ -339,8 +301,15 @@ void CefContext::OnContextInitialized() {
// Register internal scheme handlers.
scheme::RegisterInternalHandlers();
// Register for notifications.
registrar_.reset(new content::NotificationRegistrar());
registrar_->Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
registrar_->Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllBrowserContextsAndSources());
// Notify the handler.
CefRefPtr<CefApp> app = application();
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
@@ -355,6 +324,8 @@ void CefContext::FinishShutdownOnUIThread(
CefContentBrowserClient::Get()->DestroyAllBrowsers();
registrar_.reset();
if (trace_subscriber_.get())
trace_subscriber_.reset(NULL);
@@ -377,3 +348,16 @@ void CefContext::FinalizeShutdown() {
main_runner_.reset(NULL);
main_delegate_.reset(NULL);
}
void CefContext::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED ||
type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED);
content::RenderProcessHost* rph =
content::Source<content::RenderProcessHost>(source).ptr();
DCHECK(rph);
CefContentBrowserClient::Get()->RemoveBrowserContextReference(
static_cast<CefBrowserContext*>(rph->GetBrowserContext()));
}

View File

@@ -17,8 +17,8 @@
#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"
#include "net/url_request/url_request_context_getter.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace base {
class WaitableEvent;
@@ -28,14 +28,12 @@ namespace content {
class ContentMainRunner;
}
class CefBrowserContext;
class CefBrowserHostImpl;
class CefDevToolsDelegate;
class CefMainDelegate;
class CefTraceSubscriber;
class PrefService;
class CefContext : public CefBase {
class CefContext : public CefBase,
public content::NotificationObserver {
public:
typedef std::list<CefRefPtr<CefBrowserHostImpl> > BrowserList;
@@ -57,29 +55,11 @@ class CefContext : public CefBase {
// Returns true if the context is shutting down.
bool shutting_down() { return shutting_down_; }
CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(int render_process_id,
int render_view_id);
// Retrieve the path at which cache data will be stored on disk. If empty,
// cache data will be stored in-memory.
// Retrieve the path at which cache data will be stored on disk.
const base::FilePath& cache_path() const { return cache_path_; }
const CefSettings& settings() const { return settings_; }
CefRefPtr<CefApp> application() const;
CefBrowserContext* browser_context() const;
CefDevToolsDelegate* devtools_delegate() const;
PrefService* pref_service() const;
scoped_refptr<net::URLRequestContextGetter> request_context() const {
return request_context_;
}
void set_request_context(scoped_refptr<net::URLRequestContextGetter> context) {
request_context_ = context;
}
// Passes ownership.
scoped_ptr<net::ProxyConfigService> proxy_config_service() const;
CefTraceSubscriber* GetTraceSubscriber();
private:
@@ -92,6 +72,11 @@ class CefContext : public CefBase {
// Destroys the main runner and related objects.
void FinalizeShutdown();
// NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Track context state.
bool initialized_;
bool shutting_down_;
@@ -107,7 +92,8 @@ class CefContext : public CefBase {
scoped_ptr<content::ContentMainRunner> main_runner_;
scoped_ptr<CefTraceSubscriber> trace_subscriber_;
scoped_refptr<net::URLRequestContextGetter> request_context_;
// Only accessed on the UI Thread.
scoped_ptr<content::NotificationRegistrar> registrar_;
IMPLEMENT_REFCOUNTING(CefContext);
IMPLEMENT_LOCKING(CefContext);

View File

@@ -9,6 +9,7 @@
#include <vector>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h"
@@ -113,7 +114,7 @@ void CefCookieManagerImpl::SetSupportedSchemes(
// Global changes are handled by the request context.
scoped_refptr<CefURLRequestContextGetter> getter =
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get());
CefContentBrowserClient::Get()->request_context().get());
std::vector<std::string> scheme_vec;
std::vector<CefString>::const_iterator it = schemes.begin();
@@ -267,7 +268,7 @@ bool CefCookieManagerImpl::SetStoragePath(
// Global path changes are handled by the request context.
scoped_refptr<CefURLRequestContextGetter> getter =
static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get());
CefContentBrowserClient::Get()->request_context().get());
getter->SetCookieStoragePath(new_path, persist_session_cookies);
cookie_monster_ = getter->GetURLRequestContext()->cookie_store()->
GetCookieMonster();
@@ -348,9 +349,9 @@ bool CefCookieManagerImpl::FlushStore(CefRefPtr<CefCompletionHandler> handler) {
void CefCookieManagerImpl::SetGlobal() {
if (CEF_CURRENTLY_ON_IOT()) {
if (_Context->browser_context()) {
cookie_monster_ = _Context->request_context()->GetURLRequestContext()->
cookie_store()->GetCookieMonster();
if (CefContentBrowserClient::Get()->request_context()) {
cookie_monster_ = CefContentBrowserClient::Get()->request_context()->
GetURLRequestContext()->cookie_store()->GetCookieMonster();
DCHECK(cookie_monster_);
}
} else {

View File

@@ -0,0 +1,112 @@
// 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/request_context_impl.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "base/atomic_sequence_num.h"
#include "base/logging.h"
namespace {
void RemoveContextRef(CefBrowserContext* browser_context) {
CefContentBrowserClient::Get()->RemoveBrowserContextReference(
browser_context);
}
base::StaticAtomicSequenceNumber g_next_id;
} // namespace
// Static functions
CefRefPtr<CefRequestContext> CefRequestContext::GetGlobalContext() {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefRequestContextImpl(
CefContentBrowserClient::Get()->browser_context());
}
CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
CefRefPtr<CefRequestContextHandler> handler) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return new CefRequestContextImpl(handler);
}
// CefBrowserContextImpl
CefRequestContextImpl::CefRequestContextImpl(
CefBrowserContext* browser_context)
: browser_context_(browser_context),
unique_id_(0) {
DCHECK(browser_context);
if (!IsGlobal()) {
CEF_REQUIRE_UIT();
CefBrowserContextProxy* proxy =
static_cast<CefBrowserContextProxy*>(browser_context);
handler_ = proxy->handler();
CefContentBrowserClient::Get()->AddBrowserContextReference(browser_context);
}
}
CefRequestContextImpl::CefRequestContextImpl(
CefRefPtr<CefRequestContextHandler> handler)
: browser_context_(NULL),
handler_(handler),
unique_id_(g_next_id.GetNext()) {
}
CefRequestContextImpl::~CefRequestContextImpl() {
if (browser_context_) {
if (CEF_CURRENTLY_ON_UIT())
RemoveContextRef(browser_context_);
else
CEF_POST_TASK(CEF_UIT, base::Bind(RemoveContextRef, browser_context_));
}
}
CefBrowserContext* CefRequestContextImpl::GetOrCreateBrowserContext() {
CEF_REQUIRE_UIT();
if (!browser_context_) {
browser_context_ =
CefContentBrowserClient::Get()->CreateBrowserContextProxy(handler_);
}
return browser_context_;
}
bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) {
CefRequestContextImpl* impl =
static_cast<CefRequestContextImpl*>(other.get());
if (!impl)
return false;
// Compare CefBrowserContext points if one has been associated.
if (browser_context_ && impl->browser_context_)
return (browser_context_ == impl->browser_context_);
else if (browser_context_ || impl->browser_context_)
return false;
// Otherwise compare unique IDs.
return (unique_id_ == impl->unique_id_);
}
bool CefRequestContextImpl::IsGlobal() {
return (browser_context_ ==
CefContentBrowserClient::Get()->browser_context());
}
CefRefPtr<CefRequestContextHandler> CefRequestContextImpl::GetHandler() {
return handler_;
}

View File

@@ -0,0 +1,37 @@
// 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_REQUEST_CONTEXT_IMPL_H_
#define CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
#pragma once
#include "include/cef_request_context.h"
class CefBrowserContext;
class CefRequestContextImpl : public CefRequestContext {
public:
explicit CefRequestContextImpl(CefBrowserContext* browser_context);
explicit CefRequestContextImpl(CefRefPtr<CefRequestContextHandler> handler);
virtual ~CefRequestContextImpl();
CefBrowserContext* GetOrCreateBrowserContext();
virtual bool IsSame(CefRefPtr<CefRequestContext> other) OVERRIDE;
virtual bool IsGlobal() OVERRIDE;
virtual CefRefPtr<CefRequestContextHandler> GetHandler() OVERRIDE;
protected:
CefBrowserContext* browser_context_;
CefRefPtr<CefRequestContextHandler> handler_;
// Used to uniquely identify CefRequestContext objects before an associated
// CefBrowserContext has been created.
int unique_id_;
IMPLEMENT_REFCOUNTING(CefRequestContextImpl);
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);
};
#endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_

View File

@@ -9,6 +9,7 @@
#include "include/cef_scheme.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/resource_request_job.h"
#include "libcef/browser/scheme_handler.h"
@@ -195,7 +196,8 @@ class CefUrlRequestManager {
private:
net::URLRequestJobFactoryImpl* GetJobFactoryImpl() {
return static_cast<CefURLRequestContextGetter*>(
_Context->request_context().get())->job_factory_impl();
CefContentBrowserClient::Get()->request_context().get())->
job_factory_impl();
}
// Add or remove the protocol handler if necessary. |scheme| will already be

View File

@@ -10,6 +10,7 @@
#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"
@@ -107,7 +108,7 @@ net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
NULL,
url_request_context_.get(),
url_request_context_->network_delegate(),
_Context->proxy_config_service().release(),
CefContentBrowserClient::Get()->proxy_config_service().release(),
command_line));
storage_->set_proxy_service(system_proxy_service.release());

View File

@@ -8,12 +8,11 @@
#include "libcef/browser/url_request_context_proxy.h"
CefURLRequestContextGetterProxy::CefURLRequestContextGetterProxy(
CefBrowserHostImpl* browser,
CefRefPtr<CefRequestContextHandler> handler,
CefURLRequestContextGetter* parent)
: browser_(browser),
: handler_(handler),
parent_(parent),
context_proxy_(NULL) {
DCHECK(browser);
DCHECK(parent);
}
@@ -28,7 +27,7 @@ net::URLRequestContext*
CEF_REQUIRE_IOT();
if (!context_proxy_) {
context_proxy_ = parent_->CreateURLRequestContextProxy();
context_proxy_->Initialize(browser_);
context_proxy_->Initialize(handler_);
}
return context_proxy_;
}
@@ -37,3 +36,7 @@ scoped_refptr<base::SingleThreadTaskRunner>
CefURLRequestContextGetterProxy::GetNetworkTaskRunner() const {
return parent_->GetNetworkTaskRunner();
}
net::HostResolver* CefURLRequestContextGetterProxy::GetHostResolver() const {
return parent_->host_resolver();
}

View File

@@ -6,16 +6,21 @@
#define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_GETTER_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context_getter.h"
class CefBrowserHostImpl;
class CefURLRequestContextGetter;
class CefURLRequestContextProxy;
namespace net {
class HostResolver;
}
class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter {
public:
CefURLRequestContextGetterProxy(CefBrowserHostImpl* browser,
CefURLRequestContextGetterProxy(CefRefPtr<CefRequestContextHandler> handler,
CefURLRequestContextGetter* parent);
virtual ~CefURLRequestContextGetterProxy();
@@ -24,8 +29,12 @@ class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter {
virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const OVERRIDE;
net::HostResolver* GetHostResolver() const;
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
CefBrowserHostImpl* browser_;
CefRefPtr<CefRequestContextHandler> handler_;
scoped_refptr<CefURLRequestContextGetter> parent_;
// The |context_proxy_| object is owned by |parent_|.

View File

@@ -19,10 +19,10 @@ namespace {
class CefCookieStoreProxy : public net::CookieStore {
public:
explicit CefCookieStoreProxy(CefBrowserHostImpl* browser,
net::URLRequestContext* parent)
CefCookieStoreProxy(net::URLRequestContext* parent,
CefRefPtr<CefRequestContextHandler> handler)
: parent_(parent),
browser_(browser) {
handler_(handler) {
}
virtual ~CefCookieStoreProxy() {
CEF_REQUIRE_IOT();
@@ -79,20 +79,14 @@ class CefCookieStoreProxy : public net::CookieStore {
scoped_refptr<net::CookieStore> cookie_store;
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
// Get the manager from the handler.
CefRefPtr<CefCookieManager> manager =
handler->GetCookieManager(browser_.get(),
browser_->GetLoadingURL().spec());
if (manager.get()) {
cookie_store =
reinterpret_cast<CefCookieManagerImpl*>(
manager.get())->cookie_monster();
DCHECK(cookie_store);
}
if (handler_.get()) {
// Get the manager from the handler.
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
if (manager.get()) {
cookie_store =
reinterpret_cast<CefCookieManagerImpl*>(
manager.get())->cookie_monster();
DCHECK(cookie_store);
}
}
@@ -107,7 +101,7 @@ class CefCookieStoreProxy : public net::CookieStore {
// This pointer is guaranteed by the CefRequestContextProxy object.
net::URLRequestContext* parent_;
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefRequestContextHandler> handler_;
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy);
};
@@ -125,13 +119,14 @@ CefURLRequestContextProxy::~CefURLRequestContextProxy() {
CEF_REQUIRE_IOT();
}
void CefURLRequestContextProxy::Initialize(CefBrowserHostImpl* browser) {
void CefURLRequestContextProxy::Initialize(
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_IOT();
net::URLRequestContext* context = parent_->GetURLRequestContext();
// Cookie store that proxies to the browser implementation.
cookie_store_proxy_ = new CefCookieStoreProxy(browser, context);
cookie_store_proxy_ = new CefCookieStoreProxy(context, handler);
set_cookie_store(cookie_store_proxy_);
// All other values refer to the parent request context.

View File

@@ -6,6 +6,8 @@
#define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_PROXY_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context.h"
@@ -21,7 +23,7 @@ class CefURLRequestContextProxy : public net::URLRequestContext {
explicit CefURLRequestContextProxy(net::URLRequestContextGetter* parent);
virtual ~CefURLRequestContextProxy();
void Initialize(CefBrowserHostImpl* browser);
void Initialize(CefRefPtr<CefRequestContextHandler> handler);
// We may try to delete this proxy multiple times if URLRequests are still
// pending. Keep track of the number of tries so that they don't become