2013-03-13 19:12:05 +00:00
|
|
|
// 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-CHROMIUM file.
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
#include "browser/browser_context.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-01-19 00:59:57 +00:00
|
|
|
#include "browser/brightray_paths.h"
|
2013-04-08 17:53:53 +00:00
|
|
|
#include "browser/inspectable_web_contents_impl.h"
|
2013-07-17 14:21:33 +00:00
|
|
|
#include "browser/network_delegate.h"
|
2015-05-22 06:50:41 +00:00
|
|
|
#include "browser/permission_manager.h"
|
2015-10-12 13:09:39 +00:00
|
|
|
#include "browser/special_storage_policy.h"
|
2013-04-08 16:41:30 +00:00
|
|
|
#include "common/application_info.h"
|
2013-03-13 20:45:00 +00:00
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
2013-03-29 21:28:49 +00:00
|
|
|
#include "base/prefs/json_pref_store.h"
|
|
|
|
#include "base/prefs/pref_registry_simple.h"
|
|
|
|
#include "base/prefs/pref_service.h"
|
2014-06-26 20:25:30 +00:00
|
|
|
#include "base/prefs/pref_service_factory.h"
|
2015-09-05 11:46:55 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/resource_context.h"
|
|
|
|
#include "content/public/browser/storage_partition.h"
|
2015-09-05 11:46:55 +00:00
|
|
|
#include "net/base/escape.h"
|
2015-06-08 16:07:48 +00:00
|
|
|
#include "net/ssl/client_cert_store.h"
|
|
|
|
|
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/ssl/client_cert_store_nss.h"
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
#include "net/ssl/client_cert_store_win.h"
|
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
#include "net/ssl/client_cert_store_mac.h"
|
|
|
|
#endif
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-13 07:09:26 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2015-09-05 11:46:55 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Convert string to lower case and escape it.
|
|
|
|
std::string MakePartitionName(const std::string& input) {
|
2015-12-07 11:55:01 +00:00
|
|
|
return net::EscapePath(base::ToLowerASCII(input));
|
2015-09-05 11:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
class BrowserContext::ResourceContext : public content::ResourceContext {
|
2013-11-17 22:42:56 +00:00
|
|
|
public:
|
2013-03-13 19:12:05 +00:00
|
|
|
ResourceContext() : getter_(nullptr) {}
|
|
|
|
|
|
|
|
void set_url_request_context_getter(URLRequestContextGetter* getter) {
|
|
|
|
getter_ = getter;
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
private:
|
2015-06-05 04:07:27 +00:00
|
|
|
net::HostResolver* GetHostResolver() override {
|
2013-03-13 19:12:05 +00:00
|
|
|
return getter_->host_resolver();
|
|
|
|
}
|
2013-11-17 22:42:56 +00:00
|
|
|
|
2015-06-05 04:07:27 +00:00
|
|
|
net::URLRequestContext* GetRequestContext() override {
|
2013-03-13 19:12:05 +00:00
|
|
|
return getter_->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
2015-06-08 16:07:48 +00:00
|
|
|
scoped_ptr<net::ClientCertStore> CreateClientCertStore() override {
|
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS(
|
|
|
|
net::ClientCertStoreNSS::PasswordDelegateFactory()));
|
|
|
|
#elif defined(OS_WIN)
|
2015-06-10 11:30:35 +00:00
|
|
|
return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
|
2015-06-08 16:07:48 +00:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
|
|
|
|
#elif defined(USE_OPENSSL)
|
|
|
|
return scoped_ptr<net::ClientCertStore>();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
URLRequestContextGetter* getter_;
|
|
|
|
};
|
|
|
|
|
2015-09-05 14:34:42 +00:00
|
|
|
// static
|
|
|
|
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
|
|
|
|
|
|
|
// static
|
|
|
|
scoped_refptr<BrowserContext> BrowserContext::From(
|
|
|
|
const std::string& partition, bool in_memory) {
|
|
|
|
PartitionKey key(partition, in_memory);
|
|
|
|
if (browser_context_map_[key].get())
|
|
|
|
return make_scoped_refptr(browser_context_map_[key].get());
|
|
|
|
|
|
|
|
auto browser_context = BrowserContext::Create(partition, in_memory);
|
2015-10-06 07:19:38 +00:00
|
|
|
browser_context->InitPrefs();
|
2015-09-05 14:34:42 +00:00
|
|
|
browser_context_map_[key] = browser_context->weak_factory_.GetWeakPtr();
|
|
|
|
return browser_context;
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:52:50 +00:00
|
|
|
BrowserContext::BrowserContext(const std::string& partition, bool in_memory)
|
|
|
|
: in_memory_(in_memory),
|
2015-09-05 14:34:42 +00:00
|
|
|
resource_context_(new ResourceContext),
|
2015-10-12 13:09:39 +00:00
|
|
|
storage_policy_(new SpecialStoragePolicy),
|
2015-09-05 14:34:42 +00:00
|
|
|
weak_factory_(this) {
|
2015-01-19 00:59:57 +00:00
|
|
|
if (!PathService::Get(DIR_USER_DATA, &path_)) {
|
2015-01-19 01:19:25 +00:00
|
|
|
PathService::Get(DIR_APP_DATA, &path_);
|
2015-01-19 00:59:57 +00:00
|
|
|
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
|
|
|
PathService::Override(DIR_USER_DATA, path_);
|
|
|
|
}
|
2013-10-07 19:21:43 +00:00
|
|
|
|
2015-09-05 12:52:50 +00:00
|
|
|
if (!in_memory_ && !partition.empty())
|
2015-09-05 11:46:55 +00:00
|
|
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition)));
|
2015-10-06 07:19:38 +00:00
|
|
|
}
|
2015-08-26 21:40:02 +00:00
|
|
|
|
2015-10-06 07:19:38 +00:00
|
|
|
void BrowserContext::InitPrefs() {
|
2013-05-14 18:43:42 +00:00
|
|
|
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
2014-06-26 20:25:30 +00:00
|
|
|
base::PrefServiceFactory prefs_factory;
|
|
|
|
prefs_factory.SetUserPrefsFile(prefs_path,
|
2013-11-17 22:42:56 +00:00
|
|
|
JsonPrefStore::GetTaskRunnerForFile(
|
2014-12-07 06:16:00 +00:00
|
|
|
prefs_path, BrowserThread::GetBlockingPool()).get());
|
2013-03-29 21:28:49 +00:00
|
|
|
|
|
|
|
auto registry = make_scoped_refptr(new PrefRegistrySimple);
|
2014-12-07 06:16:00 +00:00
|
|
|
RegisterInternalPrefs(registry.get());
|
|
|
|
RegisterPrefs(registry.get());
|
2013-03-29 21:28:49 +00:00
|
|
|
|
2014-12-07 06:16:00 +00:00
|
|
|
prefs_ = prefs_factory.Create(registry.get());
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserContext::~BrowserContext() {
|
2014-08-13 07:09:26 +00:00
|
|
|
BrowserThread::DeleteSoon(BrowserThread::IO,
|
|
|
|
FROM_HERE,
|
|
|
|
resource_context_.release());
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 17:53:53 +00:00
|
|
|
void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) {
|
|
|
|
InspectableWebContentsImpl::RegisterPrefs(registry);
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
net::URLRequestContextGetter* BrowserContext::CreateRequestContext(
|
2015-08-11 10:29:55 +00:00
|
|
|
NetLog* net_log,
|
2014-06-26 20:27:22 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
2014-12-07 06:16:00 +00:00
|
|
|
DCHECK(!url_request_getter_.get());
|
2013-03-27 12:53:53 +00:00
|
|
|
url_request_getter_ = new URLRequestContextGetter(
|
2014-08-20 06:39:09 +00:00
|
|
|
this,
|
2016-04-14 01:29:14 +00:00
|
|
|
network_controller_handle(),
|
2015-08-11 10:29:55 +00:00
|
|
|
net_log,
|
2013-03-13 19:12:05 +00:00
|
|
|
GetPath(),
|
2015-08-26 21:40:02 +00:00
|
|
|
in_memory_,
|
2014-08-13 07:09:26 +00:00
|
|
|
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
|
|
|
|
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
|
2014-06-26 20:27:22 +00:00
|
|
|
protocol_handlers,
|
2016-03-08 11:59:29 +00:00
|
|
|
std::move(protocol_interceptors));
|
2013-03-13 19:12:05 +00:00
|
|
|
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
|
|
|
return url_request_getter_.get();
|
|
|
|
}
|
|
|
|
|
2014-08-20 06:39:09 +00:00
|
|
|
net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() {
|
|
|
|
return new NetworkDelegate;
|
2013-07-17 14:21:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 19:21:43 +00:00
|
|
|
base::FilePath BrowserContext::GetPath() const {
|
2013-06-04 18:17:16 +00:00
|
|
|
return path_;
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 02:56:45 +00:00
|
|
|
scoped_ptr<content::ZoomLevelDelegate> BrowserContext::CreateZoomLevelDelegate(
|
|
|
|
const base::FilePath& partition_path) {
|
|
|
|
return scoped_ptr<content::ZoomLevelDelegate>();
|
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
bool BrowserContext::IsOffTheRecord() const {
|
2015-08-26 21:40:02 +00:00
|
|
|
return in_memory_;
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter* BrowserContext::GetRequestContext() {
|
|
|
|
return GetDefaultStoragePartition(this)->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess(
|
|
|
|
int renderer_child_id) {
|
2013-03-13 19:12:05 +00:00
|
|
|
return GetRequestContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() {
|
|
|
|
return GetRequestContext();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
net::URLRequestContextGetter*
|
|
|
|
BrowserContext::GetMediaRequestContextForRenderProcess(
|
|
|
|
int renderer_child_id) {
|
2013-03-13 19:12:05 +00:00
|
|
|
return GetRequestContext();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
net::URLRequestContextGetter*
|
|
|
|
BrowserContext::GetMediaRequestContextForStoragePartition(
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory) {
|
2013-03-13 19:12:05 +00:00
|
|
|
return GetRequestContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::ResourceContext* BrowserContext::GetResourceContext() {
|
|
|
|
return resource_context_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() {
|
2014-12-17 21:13:19 +00:00
|
|
|
return nullptr;
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 10:43:01 +00:00
|
|
|
content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() {
|
2014-12-17 21:13:19 +00:00
|
|
|
return nullptr;
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:31:02 +00:00
|
|
|
storage::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() {
|
2015-10-12 13:09:39 +00:00
|
|
|
return storage_policy_.get();
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 10:43:01 +00:00
|
|
|
content::PushMessagingService* BrowserContext::GetPushMessagingService() {
|
2014-12-17 21:13:19 +00:00
|
|
|
return nullptr;
|
2014-07-27 10:44:39 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 08:38:27 +00:00
|
|
|
content::SSLHostStateDelegate* BrowserContext::GetSSLHostStateDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-22 06:50:41 +00:00
|
|
|
content::PermissionManager* BrowserContext::GetPermissionManager() {
|
|
|
|
if (!permission_manager_.get())
|
|
|
|
permission_manager_.reset(new PermissionManager);
|
|
|
|
return permission_manager_.get();
|
|
|
|
}
|
|
|
|
|
2016-03-08 14:28:28 +00:00
|
|
|
content::BackgroundSyncController* BrowserContext::GetBackgroundSyncController() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
} // namespace brightray
|