mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add PDF extension support (issue #1565)
This commit is contained in:
@@ -6,18 +6,21 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "libcef/browser/browser_context_proxy.h"
|
||||
#include "libcef/browser/content_browser_client.h"
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/download_manager_delegate.h"
|
||||
#include "libcef/browser/permission_manager.h"
|
||||
#include "libcef/browser/ssl_host_state_delegate.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/extensions/extensions_util.h"
|
||||
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "chrome/browser/net/proxy_service_factory.h"
|
||||
#include "components/guest_view/browser/guest_view_manager.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
@@ -27,15 +30,64 @@ using content::BrowserThread;
|
||||
|
||||
namespace {
|
||||
|
||||
// Manages the global mapping of cache path to Impl instance.
|
||||
// Manages the global list of Impl instances.
|
||||
class ImplManager {
|
||||
public:
|
||||
typedef std::vector<CefBrowserContextImpl*> Vector;
|
||||
|
||||
ImplManager() {}
|
||||
~ImplManager() {
|
||||
DCHECK(all_.empty());
|
||||
DCHECK(map_.empty());
|
||||
}
|
||||
|
||||
CefBrowserContextImpl* GetImpl(const base::FilePath& path) {
|
||||
void AddImpl(CefBrowserContextImpl* impl) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!IsValidImpl(impl));
|
||||
all_.push_back(impl);
|
||||
}
|
||||
|
||||
void RemoveImpl(CefBrowserContextImpl* impl, const base::FilePath& path) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
Vector::iterator it = GetImplPos(impl);
|
||||
DCHECK(it != all_.end());
|
||||
all_.erase(it);
|
||||
|
||||
if (!path.empty()) {
|
||||
PathMap::iterator it = map_.find(path);
|
||||
DCHECK(it != map_.end());
|
||||
if (it != map_.end())
|
||||
map_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidImpl(const CefBrowserContextImpl* impl) {
|
||||
CEF_REQUIRE_UIT();
|
||||
return GetImplPos(impl) != all_.end();
|
||||
}
|
||||
|
||||
CefBrowserContextImpl* GetImplForContext(
|
||||
const content::BrowserContext* context) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
Vector::iterator it = all_.begin();
|
||||
for (; it != all_.end(); ++it) {
|
||||
if (*it == context || (*it)->HasProxy(context))
|
||||
return *it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetImplPath(CefBrowserContextImpl* impl, const base::FilePath& path) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!path.empty());
|
||||
DCHECK(IsValidImpl(impl));
|
||||
DCHECK(GetImplForPath(path) == NULL);
|
||||
map_.insert(std::make_pair(path, impl));
|
||||
}
|
||||
|
||||
CefBrowserContextImpl* GetImplForPath(const base::FilePath& path) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!path.empty());
|
||||
PathMap::const_iterator it = map_.find(path);
|
||||
@@ -44,26 +96,23 @@ class ImplManager {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void AddImpl(const base::FilePath& path, CefBrowserContextImpl* impl) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!path.empty());
|
||||
DCHECK(GetImpl(path) == NULL);
|
||||
map_.insert(std::make_pair(path, impl));
|
||||
}
|
||||
|
||||
void RemoveImpl(const base::FilePath& path) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!path.empty());
|
||||
PathMap::iterator it = map_.find(path);
|
||||
DCHECK(it != map_.end());
|
||||
if (it != map_.end())
|
||||
map_.erase(it);
|
||||
}
|
||||
const Vector GetAllImpl() const { return all_; }
|
||||
|
||||
private:
|
||||
Vector::iterator GetImplPos(const CefBrowserContextImpl* impl) {
|
||||
Vector::iterator it = all_.begin();
|
||||
for (; it != all_.end(); ++it) {
|
||||
if (*it == impl)
|
||||
return it;
|
||||
}
|
||||
return all_.end();
|
||||
}
|
||||
|
||||
typedef std::map<base::FilePath, CefBrowserContextImpl*> PathMap;
|
||||
PathMap map_;
|
||||
|
||||
Vector all_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ImplManager);
|
||||
};
|
||||
|
||||
@@ -74,6 +123,7 @@ base::LazyInstance<ImplManager> g_manager = LAZY_INSTANCE_INITIALIZER;
|
||||
CefBrowserContextImpl::CefBrowserContextImpl(
|
||||
const CefRequestContextSettings& settings)
|
||||
: settings_(settings) {
|
||||
g_manager.Get().AddImpl(this);
|
||||
}
|
||||
|
||||
CefBrowserContextImpl::~CefBrowserContextImpl() {
|
||||
@@ -84,8 +134,7 @@ CefBrowserContextImpl::~CefBrowserContextImpl() {
|
||||
if (download_manager_delegate_.get())
|
||||
download_manager_delegate_.reset(NULL);
|
||||
|
||||
if (!cache_path_.empty())
|
||||
g_manager.Get().RemoveImpl(cache_path_);
|
||||
g_manager.Get().RemoveImpl(this, cache_path_);
|
||||
}
|
||||
|
||||
void CefBrowserContextImpl::Initialize() {
|
||||
@@ -102,7 +151,7 @@ void CefBrowserContextImpl::Initialize() {
|
||||
}
|
||||
|
||||
if (!cache_path_.empty())
|
||||
g_manager.Get().AddImpl(cache_path_, this);
|
||||
g_manager.Get().SetImplPath(this, cache_path_);
|
||||
|
||||
if (settings_.accept_language_list.length == 0) {
|
||||
// Use the global language list setting.
|
||||
@@ -110,6 +159,8 @@ void CefBrowserContextImpl::Initialize() {
|
||||
CefString(&CefContext::Get()->settings().accept_language_list);
|
||||
}
|
||||
|
||||
CefBrowserContext::Initialize();
|
||||
|
||||
// Initialize proxy configuration tracker.
|
||||
pref_proxy_config_tracker_.reset(
|
||||
ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
|
||||
@@ -123,10 +174,52 @@ void CefBrowserContextImpl::Initialize() {
|
||||
DCHECK(url_request_getter_.get());
|
||||
}
|
||||
|
||||
void CefBrowserContextImpl::AddProxy(const CefBrowserContextProxy* proxy) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!HasProxy(proxy));
|
||||
proxy_list_.push_back(proxy);
|
||||
}
|
||||
|
||||
void CefBrowserContextImpl::RemoveProxy(const CefBrowserContextProxy* proxy) {
|
||||
CEF_REQUIRE_UIT();
|
||||
bool found = false;
|
||||
ProxyList::iterator it = proxy_list_.begin();
|
||||
for (; it != proxy_list_.end(); ++it) {
|
||||
if (*it == proxy) {
|
||||
proxy_list_.erase(it);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DCHECK(found);
|
||||
}
|
||||
|
||||
bool CefBrowserContextImpl::HasProxy(
|
||||
const content::BrowserContext* context) const {
|
||||
CEF_REQUIRE_UIT();
|
||||
ProxyList::const_iterator it = proxy_list_.begin();
|
||||
for (; it != proxy_list_.end(); ++it) {
|
||||
if (*it == context)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<CefBrowserContextImpl> CefBrowserContextImpl::GetForCachePath(
|
||||
const base::FilePath& cache_path) {
|
||||
return g_manager.Get().GetImpl(cache_path);
|
||||
return g_manager.Get().GetImplForPath(cache_path);
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefBrowserContextImpl> CefBrowserContextImpl::GetForContext(
|
||||
content::BrowserContext* context) {
|
||||
return g_manager.Get().GetImplForContext(context);
|
||||
}
|
||||
|
||||
// static
|
||||
std::vector<CefBrowserContextImpl*> CefBrowserContextImpl::GetAll() {
|
||||
return g_manager.Get().GetAllImpl();
|
||||
}
|
||||
|
||||
base::FilePath CefBrowserContextImpl::GetPath() const {
|
||||
@@ -181,7 +274,8 @@ net::URLRequestContextGetter*
|
||||
}
|
||||
|
||||
content::BrowserPluginGuestManager* CefBrowserContextImpl::GetGuestManager() {
|
||||
return NULL;
|
||||
DCHECK(extensions::ExtensionsEnabled());
|
||||
return guest_view::GuestViewManager::FromBrowserContext(this);
|
||||
}
|
||||
|
||||
storage::SpecialStoragePolicy*
|
||||
@@ -207,10 +301,6 @@ content::PermissionManager* CefBrowserContextImpl::GetPermissionManager() {
|
||||
return permission_manager_.get();
|
||||
}
|
||||
|
||||
bool CefBrowserContextImpl::IsProxy() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const CefRequestContextSettings& CefBrowserContextImpl::GetSettings() const {
|
||||
return settings_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user