electron/brightray/browser/browser_context.cc
Jeremy Apthorp e012801420 feat: upgrade to Chromium 68.0.3440.128 and Node 10.11.0 (#14677)
* Update to Chromium 68.0.3440.128 and Node 10.10.0

* update v8, ffmpeg, chromium, crashpad, boringssl, and webrtc patches

* fix SSL_get_tlsext_status_type patch

* pass encryption_modes_supported to CdmInfo

* kNoSandbox moved into service_manager

* bump CHROME_VERSION_STRING

TODO: automatically pull in the real chrome version

* PathService -> base::PathService

* net::X509Certificate::Equals -> net::X509Certificate::EqualsExcludingChain

* use content::ChildProcessTerminationInfo

* GetHandle() -> GetProcess().Handle()

* ScopedNestableTaskAllower doesn't take an argument

* net::HttpAuthCache::ClearEntriesAddedWithin -> ClearAllEntries

* std::unique_ptr<WebContents>

* blink::WebFullscreenOptions

* OnAudioStateChanged doesn't take a WebContents

* content::RESULT_CODE_NORMAL_EXIT -> service_manager::RESULT_CODE_NORMAL_EXIT

* MessageLoopCurrent

* WasResized -> SynchronizeVisualProperties

* SetTimeStamp takes a base::TimeTicks

* ExecuteScriptInIsolatedWorld is single-script only

* DispatchNonPersistentCloseEvent takes a callback now

* expose URLRequestContextGetter::{Add,Remove}Observer

* test: remove no longer existing Chromium test deps

cc_blink_unittests has been removed in
https://chromium-review.googlesource.com/1053765

mojo_common_unittests has been removed in
https://chromium-review.googlesource.com/1028000

* SetFdLimit -> IncreaseFdLimitTo

NOTE: the behaviour of this API has changed slightly, and we should
mention that in the notes.

* MessageLoop::QuitWhenIdleClosure -> RunLoop::QuitCurrentWhenIdleClosureDeprecated

* certificate_transparency moved out of net/

pending a clearer decision about what to do with CT

in the mean time, copy CreateLogVerifiersForKnownLogs from deleted chromium source

* add secure_origin_whitelist to chrome source list

NOTE: is this something we actually want? cc @deepak1556

* DrainBackgroundTasks -> DrainTasks

* use new node options parser

* fix disable_scroll_begin_dcheck.patch

* ViewsDelegate::CreateWebContents went away

see https://chromium-review.googlesource.com/c/chromium/src/+/1031314

* kZygoteProcess moved into service_manager

* test: minor improvements to the Node spec

 - reformat some parts
 - better failures reporting with `expect`
 - skip some tests instead of marking them as passed

* chromium removed *_posix.cc from the source filters

* test: fix :electron_tests compilation

* better crash diagnostics in ffmpeg test

* fix: enable back a DCHECK in viz::ServerSharedBitmapManager

Fixes #14327.
Backports https://chromium-review.googlesource.com/802574.

* chore: update linux sysroots

* chore: remove obsolete "install-sysroot.py" script

* test: fix frame-subscriber test on Mac

* disable OSR for now

* test: make before-input-event test more robust

* test: make run-as-node --inspect test more robust on windows

* roll node to v10.11.0

* avoid duplicate files when building a zip

* disable failing assert in beginFrameSubscription dirty-rectangle test

* experiment with is_cfi = false

* fix: build torque with x64 toolchain

Co-Authored-By: Alexey Kuzmin <github@alexeykuzmin.com>

* test: disable the "app.relaunch" test on Linux

* chore: bump node to get header tar file

* chore: bump node to fix tar.py line endings
2018-10-04 12:02:14 +10:00

207 lines
6.2 KiB
C++

// 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.
#include "brightray/browser/browser_context.h"
#include <memory>
#include <utility>
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "brightray/browser/brightray_paths.h"
#include "brightray/browser/browser_client.h"
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "brightray/browser/zoom_level_delegate.h"
#include "brightray/common/application_info.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/escape.h"
using content::BrowserThread;
namespace brightray {
namespace {
// Convert string to lower case and escape it.
std::string MakePartitionName(const std::string& input) {
return net::EscapePath(base::ToLowerASCII(input));
}
} // namespace
// static
void BrowserContextDeleter::Destruct(const BrowserContext* browser_context) {
browser_context->OnDestruct();
}
// static
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
// static
scoped_refptr<BrowserContext> BrowserContext::Get(const std::string& partition,
bool in_memory) {
PartitionKey key(partition, in_memory);
if (browser_context_map_[key].get())
return WrapRefCounted(browser_context_map_[key].get());
return nullptr;
}
BrowserContext::BrowserContext(const std::string& partition, bool in_memory)
: in_memory_(in_memory), weak_factory_(this) {
if (!base::PathService::Get(DIR_USER_DATA, &path_)) {
base::PathService::Get(DIR_APP_DATA, &path_);
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
base::PathService::Override(DIR_USER_DATA, path_);
}
if (!in_memory_ && !partition.empty())
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
.Append(base::FilePath::FromUTF8Unsafe(
MakePartitionName(partition)));
content::BrowserContext::Initialize(this, path_);
io_handle_ = new URLRequestContextGetter::Handle(GetWeakPtr());
browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr();
}
BrowserContext::~BrowserContext() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
NotifyWillBeDestroyed(this);
ShutdownStoragePartitions();
io_handle_->ShutdownOnUIThread();
}
void BrowserContext::OnDestruct() const {
if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
delete this;
} else {
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
}
}
void BrowserContext::InitPrefs() {
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
base::ThreadRestrictions::ScopedAllowIO allow_io;
PrefServiceFactory prefs_factory;
scoped_refptr<JsonPrefStore> pref_store =
base::MakeRefCounted<JsonPrefStore>(prefs_path);
pref_store->ReadPrefs(); // Synchronous.
prefs_factory.set_user_prefs(pref_store);
auto registry = WrapRefCounted(new PrefRegistrySimple);
RegisterInternalPrefs(registry.get());
RegisterPrefs(registry.get());
prefs_ = prefs_factory.Create(registry.get());
}
void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) {
InspectableWebContentsImpl::RegisterPrefs(registry);
MediaDeviceIDSalt::RegisterPrefs(registry);
ZoomLevelDelegate::RegisterPrefs(registry);
}
URLRequestContextGetter* BrowserContext::GetRequestContext() {
return static_cast<URLRequestContextGetter*>(
GetDefaultStoragePartition(this)->GetURLRequestContext());
}
net::URLRequestContextGetter* BrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector protocol_interceptors) {
return io_handle_
->CreateMainRequestContextGetter(protocol_handlers,
std::move(protocol_interceptors))
.get();
}
std::string BrowserContext::GetMediaDeviceIDSalt() {
if (!media_device_id_salt_.get())
media_device_id_salt_.reset(new MediaDeviceIDSalt(prefs_.get()));
return media_device_id_salt_->GetSalt();
}
base::FilePath BrowserContext::GetPath() const {
return path_;
}
std::unique_ptr<content::ZoomLevelDelegate>
BrowserContext::CreateZoomLevelDelegate(const base::FilePath& partition_path) {
if (!IsOffTheRecord()) {
return std::make_unique<ZoomLevelDelegate>(prefs(), partition_path);
}
return std::unique_ptr<content::ZoomLevelDelegate>();
}
bool BrowserContext::IsOffTheRecord() const {
return in_memory_;
}
content::ResourceContext* BrowserContext::GetResourceContext() {
return io_handle_->GetResourceContext();
}
content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() {
return nullptr;
}
content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() {
return nullptr;
}
content::PushMessagingService* BrowserContext::GetPushMessagingService() {
return nullptr;
}
content::SSLHostStateDelegate* BrowserContext::GetSSLHostStateDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate* BrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
BrowserContext::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
BrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
net::URLRequestContextGetter*
BrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
NOTREACHED();
return nullptr;
}
net::URLRequestContextGetter* BrowserContext::CreateMediaRequestContext() {
return io_handle_->GetMainRequestContextGetter().get();
}
net::URLRequestContextGetter*
BrowserContext::CreateMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
NOTREACHED();
return nullptr;
}
} // namespace brightray