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
|
|
|
|
2013-07-24 11:56:55 +00:00
|
|
|
#include "browser/download_manager_delegate.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"
|
2013-11-17 22:42:56 +00:00
|
|
|
#include "browser/url_request_context_getter.h"
|
2013-04-08 16:41:30 +00:00
|
|
|
#include "common/application_info.h"
|
2013-03-13 20:45:00 +00:00
|
|
|
|
2013-08-14 12:08:59 +00:00
|
|
|
#include "base/environment.h"
|
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"
|
|
|
|
#include "base/prefs/pref_service_builder.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"
|
|
|
|
|
2013-08-14 12:08:59 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "base/nix/xdg_util.h"
|
|
|
|
#endif
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
|
|
|
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:
|
2013-03-13 19:12:05 +00:00
|
|
|
virtual net::HostResolver* GetHostResolver() OVERRIDE {
|
|
|
|
return getter_->host_resolver();
|
|
|
|
}
|
2013-11-17 22:42:56 +00:00
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
|
|
|
|
return getter_->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
// FIXME: We should probably allow clients to override this to implement more
|
|
|
|
// restrictive policies.
|
2013-10-07 20:25:17 +00:00
|
|
|
virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-17 22:42:56 +00:00
|
|
|
|
|
|
|
// FIXME: We should probably allow clients to override this to implement more
|
|
|
|
// restrictive policies.
|
2013-10-07 20:25:17 +00:00
|
|
|
virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
URLRequestContextGetter* getter_;
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
|
2013-08-15 20:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserContext::Initialize() {
|
2013-10-07 19:21:43 +00:00
|
|
|
base::FilePath path;
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
scoped_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
path = base::nix::GetXDGDirectory(env.get(),
|
|
|
|
base::nix::kXdgConfigHomeEnvVar,
|
|
|
|
base::nix::kDotConfigDir);
|
|
|
|
#else
|
|
|
|
CHECK(PathService::Get(base::DIR_APP_DATA, &path));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
|
|
|
|
2013-05-14 18:43:42 +00:00
|
|
|
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
2013-03-29 21:28:49 +00:00
|
|
|
PrefServiceBuilder builder;
|
|
|
|
builder.WithUserFilePrefs(prefs_path,
|
2013-11-17 22:42:56 +00:00
|
|
|
JsonPrefStore::GetTaskRunnerForFile(
|
|
|
|
prefs_path, content::BrowserThread::GetBlockingPool()));
|
2013-03-29 21:28:49 +00:00
|
|
|
|
|
|
|
auto registry = make_scoped_refptr(new PrefRegistrySimple);
|
2013-04-08 17:53:53 +00:00
|
|
|
RegisterInternalPrefs(registry);
|
2013-03-29 21:28:49 +00:00
|
|
|
RegisterPrefs(registry);
|
|
|
|
|
|
|
|
prefs_.reset(builder.Create(registry));
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserContext::~BrowserContext() {
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers) {
|
2013-03-13 19:12:05 +00:00
|
|
|
DCHECK(!url_request_getter_);
|
2013-11-17 22:42:56 +00:00
|
|
|
auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread(
|
2013-11-17 23:16:41 +00:00
|
|
|
content::BrowserThread::IO);
|
2013-11-17 22:42:56 +00:00
|
|
|
auto file_loop = content::BrowserThread::UnsafeGetMessageLoopForThread(
|
2013-11-17 23:16:41 +00:00
|
|
|
content::BrowserThread::FILE);
|
2013-03-27 12:53:53 +00:00
|
|
|
url_request_getter_ = new URLRequestContextGetter(
|
2013-03-13 19:12:05 +00:00
|
|
|
GetPath(),
|
2013-11-17 22:42:56 +00:00
|
|
|
io_loop,
|
|
|
|
file_loop,
|
2013-08-23 12:19:37 +00:00
|
|
|
base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)),
|
2013-03-27 12:53:53 +00:00
|
|
|
protocol_handlers);
|
2013-03-13 19:12:05 +00:00
|
|
|
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
|
|
|
return url_request_getter_.get();
|
|
|
|
}
|
|
|
|
|
2013-07-17 14:21:33 +00:00
|
|
|
scoped_ptr<NetworkDelegate> BrowserContext::CreateNetworkDelegate() {
|
|
|
|
return make_scoped_ptr(new NetworkDelegate).Pass();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserContext::IsOffTheRecord() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
void BrowserContext::RequestMIDISysExPermission(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const GURL& requesting_frame,
|
|
|
|
const MIDISysExPermissionCallback& callback) {
|
2013-10-07 19:26:11 +00:00
|
|
|
callback.Run(false);
|
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
content::ResourceContext* BrowserContext::GetResourceContext() {
|
|
|
|
return resource_context_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() {
|
2013-07-24 11:56:55 +00:00
|
|
|
if (!download_manager_delegate_)
|
|
|
|
download_manager_delegate_.reset(new DownloadManagerDelegate);
|
|
|
|
return download_manager_delegate_.get();
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
content::GeolocationPermissionContext*
|
|
|
|
BrowserContext::GetGeolocationPermissionContext() {
|
2013-03-13 19:12:05 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:42:56 +00:00
|
|
|
} // namespace brightray
|