From 18e065e2fe1899890f98f065b0a3e5a7e621ba93 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 1 Feb 2018 14:20:40 -0800 Subject: [PATCH] Tor Browser Context 1. context creating options: "isolated_storage", "tor_proxy" 2. setTorNewIdentity API 3. automatically launch tor when tor browser context created and tear it down when tor browser context destroyed fix #468 fix #464 fix #509 --- atom/browser/api/atom_api_session.cc | 43 ++++-- atom/browser/api/atom_api_session.h | 3 + atom/browser/api/atom_api_web_contents.cc | 8 ++ brave/browser/BUILD.gn | 16 +++ brave/browser/brave_browser_context.cc | 132 +++++++++++++++++- brave/browser/brave_browser_context.h | 30 ++++ brave/browser/brave_content_browser_client.cc | 23 +++ .../guest_view/tab_view/tab_view_guest.cc | 4 + .../net/proxy/proxy_config_service_tor.cc | 52 +++++++ .../net/proxy/proxy_config_service_tor.h | 45 ++++++ .../browser/profiles/profile_manager.cc | 6 +- lib/browser/api/extensions.js | 4 +- patches/master_patch.patch | 41 +++++- vendor/brightray/browser/browser_context.cc | 20 --- vendor/brightray/browser/browser_context.h | 9 -- 15 files changed, 388 insertions(+), 48 deletions(-) create mode 100644 brave/browser/net/proxy/proxy_config_service_tor.cc create mode 100644 brave/browser/net/proxy/proxy_config_service_tor.h diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index e77fd51b03..e5b0c871e8 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -295,18 +295,6 @@ void DoCacheActionInIO( on_get_backend.Run(net::OK); } -void SetProxyInIO(scoped_refptr getter, - const net::ProxyConfig& config, - const base::Closure& callback) { - auto proxy_service = getter->GetURLRequestContext()->proxy_service(); - proxy_service->ResetConfigService(base::WrapUnique( - new net::ProxyConfigServiceFixed(config))); - // Refetches and applies the new pac script if provided. - proxy_service->ForceReloadProxyConfig(); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, callback); -} - void SetCertVerifyProcInIO( const scoped_refptr& context_getter, const AtomCertVerifier::VerifyProc& proc) { @@ -468,8 +456,14 @@ void Session::FlushStorageData() { void Session::SetProxy(const net::ProxyConfig& config, const base::Closure& callback) { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&SetProxyInIO, request_context_getter_, config, callback)); + auto proxy_service = + request_context_getter_->GetURLRequestContext()->proxy_service(); + proxy_service->ResetConfigService(base::WrapUnique( + new net::ProxyConfigServiceFixed(config))); + // Refetches and applies the new pac script if provided. + proxy_service->ForceReloadProxyConfig(); + if (callback) + callback.Run(); } void Session::SetDownloadPath(const base::FilePath& path) { @@ -603,6 +597,25 @@ bool Session::Equal(Session* session) const { #endif } +bool Session::IsOffTheRecord() const { + brave::BraveBrowserContext* brave_browser_context = + brave::BraveBrowserContext::FromBrowserContext(profile_); + if (brave_browser_context->IsOffTheRecord()) + return true; + if (brave_browser_context->IsIsolatedStorage()) + return true; + return false; +} + +void Session::SetTorNewIdentity(const GURL& url, + const base::Closure& callback) const { + brave::BraveBrowserContext* brave_browser_context = + brave::BraveBrowserContext::FromBrowserContext(profile_); + if (!brave_browser_context->IsIsolatedStorage()) + return; + brave_browser_context->SetTorNewIdentity(url, callback); +} + // static mate::Handle Session::CreateFrom( v8::Isolate* isolate, content::BrowserContext* browser_context) { @@ -661,6 +674,8 @@ void Session::BuildPrototype(v8::Isolate* isolate, &Session::AllowNTLMCredentialsForDomains) .SetMethod("setEnableBrotli", &Session::SetEnableBrotli) .SetMethod("equal", &Session::Equal) + .SetMethod("isOffTheRecord", &Session::IsOffTheRecord) + .SetMethod("setTorNewIdentity", &Session::SetTorNewIdentity) .SetProperty("partition", &Session::Partition) .SetProperty("contentSettings", &Session::ContentSettings) .SetProperty("userPrefs", &Session::UserPrefs) diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index e6d1e6c867..3ad9ab3f20 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -93,6 +93,9 @@ class Session: public mate::TrackableObject, v8::Local SpellChecker(v8::Isolate* isolate); v8::Local Extensions(v8::Isolate* isolate); bool Equal(Session* session) const; + bool IsOffTheRecord() const; + void SetTorNewIdentity(const GURL& url, + const base::Closure& callback) const; protected: Session(v8::Isolate* isolate, Profile* browser_context); diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 42e65947b4..f3da510448 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -410,6 +410,14 @@ mate::Handle SessionFromOptions(v8::Isolate* isolate, if (options.Get("parent_partition", &parent_partition)) { session_options.SetString("parent_partition", parent_partition); } + bool isolated_storage; + if (options.Get("isolated_storage", &isolated_storage)) { + session_options.SetBoolean("isolated_storage", isolated_storage); + } + std::string tor_proxy; + if (options.Get("tor_proxy", &tor_proxy)) { + session_options.SetString("tor_proxy", tor_proxy); + } session = Session::FromPartition(isolate, partition, session_options); } else { // Use the default session if not specified. diff --git a/brave/browser/BUILD.gn b/brave/browser/BUILD.gn index f551dba28e..3527134b6c 100644 --- a/brave/browser/BUILD.gn +++ b/brave/browser/BUILD.gn @@ -43,6 +43,7 @@ source_set("browser") { deps = [ ":apis", + ":proxy", "//electron/atom/browser", "//electron:common", "//electron/muon/app", @@ -153,3 +154,18 @@ source_set("apis") { "component_updater", ] } + +source_set("proxy") { + configs += [ + "//electron/build:electron_config", + ] + + sources = [ + "net/proxy/proxy_config_service_tor.cc", + "net/proxy/proxy_config_service_tor.h", + ] + + deps = [ + "//net", + ] +} diff --git a/brave/browser/brave_browser_context.cc b/brave/browser/brave_browser_context.cc index be847b7deb..48ef700925 100644 --- a/brave/browser/brave_browser_context.cc +++ b/brave/browser/brave_browser_context.cc @@ -10,8 +10,10 @@ #include "base/path_service.h" #include "base/files/file_path.h" #include "base/files/file_util.h" +#include "base/process/launch.h" #include "base/trace_event/trace_event.h" #include "brave/browser/brave_permission_manager.h" +#include "brave/browser/net/proxy/proxy_config_service_tor.h" #include "chrome/browser/background_fetch/background_fetch_delegate_factory.h" #include "chrome/browser/background_fetch/background_fetch_delegate_impl.h" #include "chrome/browser/browser_process.h" @@ -41,17 +43,23 @@ #include "components/user_prefs/user_prefs.h" #include "components/zoom/zoom_event_manager.h" #include "components/webdata/common/webdata_constants.h" +#include "content/browser/storage_partition_impl_map.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/dom_storage_context.h" +#include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" #include "extensions/browser/pref_names.h" #include "extensions/features/features.h" #include "net/base/escape.h" #include "net/cookies/cookie_store.h" +#include "net/proxy/proxy_service.h" #include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "vendor/brightray/browser/browser_client.h" +#include "vendor/brightray/browser/net_log.h" #if BUILDFLAG(ENABLE_EXTENSIONS) #include "atom/browser/extensions/atom_browser_client_extensions_part.h" @@ -153,6 +161,8 @@ BraveBrowserContext::BraveBrowserContext( ready_(new base::WaitableEvent( base::WaitableEvent::ResetPolicy::MANUAL, base::WaitableEvent::InitialState::NOT_SIGNALED)), + isolated_storage_(false), + in_memory_(in_memory), io_task_runner_(std::move(io_task_runner)), delegate_(g_browser_process->profile_manager()) { std::string parent_partition; @@ -162,6 +172,21 @@ BraveBrowserContext::BraveBrowserContext( atom::AtomBrowserContext::From(parent_partition, false)); } + bool isolated_storage; + if (options.GetBoolean("isolated_storage", &isolated_storage)) { + isolated_storage_ = isolated_storage; + } + + std::string tor_proxy; + if (options.GetString("tor_proxy", &tor_proxy)) { + tor_proxy_ = GURL(tor_proxy); + if (!tor_process_.IsValid()) { + base::FilePath tor("/usr/local/bin/tor"); + base::CommandLine cmdline(tor); + tor_process_ = base::LaunchProcess(cmdline, base::LaunchOptions()); + } + } + if (in_memory) { original_context_ = static_cast( atom::AtomBrowserContext::From(partition, false)); @@ -185,6 +210,10 @@ BraveBrowserContext::BraveBrowserContext( BraveBrowserContext::~BraveBrowserContext() { MaybeSendDestroyedNotification(); + if (tor_process_.IsValid()) { + base::EnsureProcessTerminated(std::move(tor_process_)); + } + if (track_zoom_subscription_.get()) track_zoom_subscription_.reset(nullptr); @@ -305,6 +334,61 @@ content::BrowserPluginGuestManager* BraveBrowserContext::GetGuestManager() { return guest_view::GuestViewManager::FromBrowserContext(this); } +net::URLRequestContextGetter* +BraveBrowserContext::CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) { + if (isolated_storage_) { + scoped_refptr + url_request_context_getter = + new brightray::URLRequestContextGetter( + this, + static_cast(brightray::BrowserClient::Get()-> + GetNetLog()), + partition_path, + in_memory, + BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), + BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), + protocol_handlers, + std::move(request_interceptors)); + StoragePartitionDescriptor descriptor(partition_path, in_memory); + url_request_context_getter_map_[descriptor] = url_request_context_getter; + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(&BraveBrowserContext::TorSetProxy, + base::Unretained(this), + url_request_context_getter, + partition_path)); + return url_request_context_getter.get(); + } else { + return nullptr; + } +} + +net::URLRequestContextGetter* +BraveBrowserContext::CreateMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory) { + if (isolated_storage_) { + StoragePartitionDescriptor descriptor(partition_path, in_memory); + URLRequestContextGetterMap::iterator iter = + url_request_context_getter_map_.find(descriptor); + if (iter != url_request_context_getter_map_.end()) + return (iter->second).get(); + else + return nullptr; + } else { + return nullptr; + } +} + +bool BraveBrowserContext::IsOffTheRecord() const { + if (isolated_storage_) + return true; + return in_memory_; +} + void BraveBrowserContext::TrackZoomLevelsFromParent() { // Here we only want to use zoom levels stored in the main-context's default // storage partition. We're not interested in zoom levels in special @@ -363,6 +447,26 @@ void BraveBrowserContext::UpdateDefaultZoomLevel() { ->OnDefaultZoomLevelChanged(); } +void BraveBrowserContext::TorSetProxy( + scoped_refptr + url_request_context_getter, + const base::FilePath partition_path) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (!url_request_context_getter || !isolated_storage_) + return; + if (tor_proxy_.is_valid()) { + auto proxy_service = url_request_context_getter->GetURLRequestContext()-> + proxy_service(); + // Notice CreateRequestContextForStoragePartition will only be called once + // per partition_path so there is no need to cache password per origin + std::string origin = partition_path.DirName().BaseName().value(); + std::unique_ptr + config(new net::ProxyConfigServiceTor(tor_proxy_)); + config->SetUsername(origin); + proxy_service->ResetConfigService(std::move(config)); + } +} + content::PermissionManager* BraveBrowserContext::GetPermissionManager() { if (!permission_manager_.get()) permission_manager_.reset(new BravePermissionManager); @@ -402,6 +506,11 @@ BraveBrowserContext::CreateURLRequestJobFactory( extensions::CreateExtensionProtocolHandler(IsOffTheRecord(), info_map_)); #endif + if (!protocol_handler_interceptor_.get()) { + protocol_handler_interceptor_ = + ProtocolHandlerRegistryFactory::GetForBrowserContext(this) + ->CreateJobInterceptorFactory(); + } protocol_handler_interceptor_->Chain(std::move(job_factory)); return std::move(protocol_handler_interceptor_); } @@ -605,7 +714,7 @@ std::string BraveBrowserContext::partition_with_prefix() { if (canonical_partition.empty()) canonical_partition = "default"; - if (IsOffTheRecord()) + if (IsOffTheRecord() && !isolated_storage_) return canonical_partition; return kPersistPrefix + canonical_partition; @@ -643,6 +752,27 @@ void BraveBrowserContext::SetExitType(ExitType exit_type) { } } +void BraveBrowserContext::SetTorNewIdentity(const GURL& url, + const base::Closure& callback) { + GURL site_url(content::SiteInstance::GetSiteForURL(this, url)); + const std::string host = site_url.host(); + base::FilePath partition_path = this->GetPath().Append( + content::StoragePartitionImplMap::GetStoragePartitionPath(host, host)); + scoped_refptr url_request_context_getter; + StoragePartitionDescriptor descriptor(partition_path, true); + URLRequestContextGetterMap::iterator iter = + url_request_context_getter_map_.find(descriptor); + if (iter != url_request_context_getter_map_.end()) + url_request_context_getter = (iter->second); + else + return; + auto proxy_service = url_request_context_getter->GetURLRequestContext()-> + proxy_service(); + proxy_service->ForceReloadProxyConfig(); + if (callback) + callback.Run(); +} + scoped_refptr BraveBrowserContext::GetIOTaskRunner() { return io_task_runner_; diff --git a/brave/browser/brave_browser_context.h b/brave/browser/brave_browser_context.h index 6824e101cf..19a2e68359 100644 --- a/brave/browser/brave_browser_context.h +++ b/brave/browser/brave_browser_context.h @@ -5,6 +5,7 @@ #ifndef BRAVE_BROWSER_BRAVE_BROWSER_CONTEXT_H_ #define BRAVE_BROWSER_BRAVE_BROWSER_CONTEXT_H_ +#include #include #include #include @@ -12,6 +13,7 @@ #include "atom/browser/atom_browser_context.h" #include "content/public/browser/host_zoom_map.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" +#include "chrome/browser/profiles/storage_partition_descriptor.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" @@ -78,6 +80,15 @@ class BraveBrowserContext : public Profile { override { return nullptr; } + net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) override; + net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory) override; + bool IsOffTheRecord() const override; // Profile implementation: scoped_refptr GetIOTaskRunner() override; @@ -129,13 +140,26 @@ class BraveBrowserContext : public Profile { void SetExitType(ExitType exit_type) override; + bool IsIsolatedStorage() const { return isolated_storage_; } + + void SetTorNewIdentity(const GURL& url, const base::Closure& callback); + private: + typedef std::map, + StoragePartitionDescriptorLess> + URLRequestContextGetterMap; void OnPrefsLoaded(bool success); void TrackZoomLevelsFromParent(); void OnParentZoomLevelChanged( const content::HostZoomMap::ZoomLevelChange& change); void UpdateDefaultZoomLevel(); + void TorSetProxy( + scoped_refptr + url_request_context_getter, + const base::FilePath partition_path); + scoped_refptr pref_registry_; std::unique_ptr user_prefs_; std::unique_ptr user_prefs_registrar_; @@ -152,6 +176,12 @@ class BraveBrowserContext : public Profile { BraveBrowserContext* otr_context_; const std::string partition_; std::unique_ptr ready_; + bool isolated_storage_; + GURL tor_proxy_; + bool in_memory_; + base::Process tor_process_; + + URLRequestContextGetterMap url_request_context_getter_map_; scoped_refptr autofill_data_; #if defined(OS_WIN) diff --git a/brave/browser/brave_content_browser_client.cc b/brave/browser/brave_content_browser_client.cc index 0a651870e6..27ca0ac559 100644 --- a/brave/browser/brave_content_browser_client.cc +++ b/brave/browser/brave_content_browser_client.cc @@ -14,6 +14,7 @@ #include "base/lazy_instance.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" +#include "brave/browser/brave_browser_context.h" #include "brave/browser/notifications/platform_notification_service_impl.h" #include "brave/browser/password_manager/brave_password_manager_client.h" #include "brave/grit/brave_resources.h" @@ -228,6 +229,12 @@ std::string BraveContentBrowserClient::GetStoragePartitionIdForSite( partition_id = site.spec(); #endif + auto brave_browser_context = + BraveBrowserContext::FromBrowserContext(browser_context); + if (brave_browser_context && brave_browser_context->IsIsolatedStorage()) { + partition_id = site.spec(); + } + DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); return partition_id; } @@ -286,6 +293,17 @@ void BraveContentBrowserClient::GetStoragePartitionConfigForSite( // error about which StoragePartition they expect to be in and it is not // safe to continue. CHECK(can_be_default || !partition_domain->empty()); + + auto brave_browser_context = + BraveBrowserContext::FromBrowserContext(browser_context); + if (brave_browser_context && brave_browser_context->IsIsolatedStorage() && + !site.SchemeIs(extensions::kExtensionScheme)) { + if (!site.is_empty()) { + *partition_domain = site.host(); + *partition_name = site.host(); + } + *in_memory = brave_browser_context->IsOffTheRecord(); + } } content::WebContentsViewDelegate* @@ -682,6 +700,11 @@ void BraveContentBrowserClient::SiteInstanceDeleting( bool BraveContentBrowserClient::ShouldUseProcessPerSite( content::BrowserContext* browser_context, const GURL& effective_url) { + auto brave_browser_context = + BraveBrowserContext::FromBrowserContext(browser_context); + if (brave_browser_context && brave_browser_context->IsIsolatedStorage()) + return true; + Profile* profile = Profile::FromBrowserContext(browser_context); if (!profile) return false; diff --git a/brave/browser/guest_view/tab_view/tab_view_guest.cc b/brave/browser/guest_view/tab_view/tab_view_guest.cc index 29fc651ec7..40d289ac94 100644 --- a/brave/browser/guest_view/tab_view/tab_view_guest.cc +++ b/brave/browser/guest_view/tab_view/tab_view_guest.cc @@ -264,6 +264,10 @@ void TabViewGuest::CreateWebContents( partition_options.SetString("parent_partition", ""); } } + bool isolated_storage; + if (params.GetBoolean("isolated_storage", &isolated_storage)) { + partition_options.SetBoolean("isolated_storage", isolated_storage); + } atom::AtomBrowserContext* browser_context = brave::BraveBrowserContext::FromPartition(partition, partition_options); diff --git a/brave/browser/net/proxy/proxy_config_service_tor.cc b/brave/browser/net/proxy/proxy_config_service_tor.cc new file mode 100644 index 0000000000..23e787a534 --- /dev/null +++ b/brave/browser/net/proxy/proxy_config_service_tor.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2018 The Brave 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 "brave/browser/net/proxy/proxy_config_service_tor.h" + +#include + +#include "base/strings/string_number_conversions.h" +#include "base/strings/string_util.h" +#include "crypto/random.h" +#include "url/gurl.h" + +namespace net { + +const int kTorPasswordLength = 16; + +ProxyConfigServiceTor::ProxyConfigServiceTor(const GURL& url) + : url_(url) { + config_.proxy_rules().ParseFromString(url_.spec()); +} + +ProxyConfigServiceTor::~ProxyConfigServiceTor() {} + +ProxyConfigServiceTor::ConfigAvailability + ProxyConfigServiceTor::GetLatestProxyConfig(ProxyConfig* config) { + if (!url_.is_valid()) + return CONFIG_UNSET; + std::string password = GenerateNewPassword(); + std::string url = url_.spec(); + base::ReplaceFirstSubstringAfterOffset( + &url, 0, "//", "//" + username_ + ":" + password + "@"); + config_.proxy_rules().ParseFromString(url); + *config = config_; + return CONFIG_VALID; +} + +bool ProxyConfigServiceTor::SetUsername(const std::string& username) { + if (username.empty()) + return false; + username_ = username; + return true; +} + + +std::string ProxyConfigServiceTor::GenerateNewPassword() { + std::vector password(kTorPasswordLength); + crypto::RandBytes(password.data(), password.size()); + return base::HexEncode(password.data(), password.size()); +} + +} // namespace net diff --git a/brave/browser/net/proxy/proxy_config_service_tor.h b/brave/browser/net/proxy/proxy_config_service_tor.h new file mode 100644 index 0000000000..04d7a27bd3 --- /dev/null +++ b/brave/browser/net/proxy/proxy_config_service_tor.h @@ -0,0 +1,45 @@ +// Copyright (c) 2018 The Brave 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 BRAVE_BROWSER_NET_PROXY_PROXY_CONFIG_SERVICE_TOR_H_ +#define BRAVE_BROWSER_NET_PROXY_PROXY_CONFIG_SERVICE_TOR_H_ + +#include + +#include "base/compiler_specific.h" +#include "net/base/net_errors.h" +#include "net/base/net_export.h" +#include "net/proxy/proxy_config.h" +#include "net/proxy/proxy_config_service.h" + +class GURL; + +namespace net { + +// Implementation of ProxyConfigService that returns a tor specific result. +class NET_EXPORT ProxyConfigServiceTor : public ProxyConfigService { + public: + explicit ProxyConfigServiceTor(const GURL& url); + ~ProxyConfigServiceTor() override; + + // ProxyConfigService methods: + void AddObserver(Observer* observer) override {} + void RemoveObserver(Observer* observer) override {} + ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) override; + + // Set origin as username + bool SetUsername(const std::string& username); + + private: + // Generate a new 128 bit random tag + std::string GenerateNewPassword(); + + ProxyConfig config_; + GURL url_; + std::string username_; +}; + +} // namespace net + +#endif // BRAVE_BROWSER_NET_PROXY_PROXY_CONFIG_SERVICE_TOR_H_ diff --git a/chromium_src/chrome/browser/profiles/profile_manager.cc b/chromium_src/chrome/browser/profiles/profile_manager.cc index 99243d0769..f70144b38f 100644 --- a/chromium_src/chrome/browser/profiles/profile_manager.cc +++ b/chromium_src/chrome/browser/profiles/profile_manager.cc @@ -23,6 +23,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/trace_event/trace_event.h" +#include "brave/browser/brave_browser_context.h" #include "build/build_config.h" #include "atom/browser/atom_browser_context.h" #include "chrome/browser/browser_process.h" @@ -82,7 +83,10 @@ void ProfileManager::OnProfileCreated(Profile* profile, bool success, bool is_new_profile) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (!profile->IsOffTheRecord() && + auto brave_browser_context = + brave::BraveBrowserContext::FromBrowserContext(profile); + if ((!profile->IsOffTheRecord() || + brave_browser_context->IsIsolatedStorage())&& !GetProfileByPath(profile->GetPath())) { AddProfile(profile); } diff --git a/lib/browser/api/extensions.js b/lib/browser/api/extensions.js index b158084c41..3394c2307d 100644 --- a/lib/browser/api/extensions.js +++ b/lib/browser/api/extensions.js @@ -225,7 +225,9 @@ const createTab = function (createProperties, cb) { if (!error && createProperties.partition) { // createProperties.partition always takes precendence ses = session.fromPartition(createProperties.partition, { - parent_partition: createProperties.parent_partition + parent_partition: createProperties.parent_partition, + isolated_storage: createProperties.isolated_storage, + tor_proxy: createProperties.tor_proxy }) // don't pass the partition info through delete createProperties.partition diff --git a/patches/master_patch.patch b/patches/master_patch.patch index 51f2e4b2fb..e06af1cf1b 100644 --- a/patches/master_patch.patch +++ b/patches/master_patch.patch @@ -253,7 +253,7 @@ index 54e54a5a1f922b84746b2f62c900857206257a24..00e706352dd09a0c8a7d5773c966ea2e return ps; diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc -index 59761b2d81799cc48ffa8b6b7f64c3d3e53f34b1..01c8ebbad98aacba021196cc138d1280aea42050 100644 +index f5f81901489121699fb7b18174f016918ae889f2..01b149aa75ca2e417ab6a857881f0add6b5f1822 100644 --- a/chrome/browser/printing/print_view_manager_base.cc +++ b/chrome/browser/printing/print_view_manager_base.cc @@ -71,13 +71,13 @@ using PrintSettingsCallback = @@ -1642,6 +1642,30 @@ index 40549b7e067f24731733f69440be4da97c104084..8d8dbe70d45408a2c92eb3a4b491f132 } void RenderWidgetTargeter::ViewWillBeDestroyed(RenderWidgetHostViewBase* view) { +diff --git a/content/browser/storage_partition_impl_map.h b/content/browser/storage_partition_impl_map.h +index ce0951bacd4dab08db92f6a87087279fcc7e4f09..10c7976815635c945079344e63ecf7f9f9932eaf 100644 +--- a/content/browser/storage_partition_impl_map.h ++++ b/content/browser/storage_partition_impl_map.h +@@ -22,6 +22,10 @@ class FilePath; + class SequencedTaskRunner; + } // namespace base + ++namespace brave { ++class BraveBrowserContext; ++} // namespace brave ++ + namespace content { + + class BrowserContext; +@@ -64,6 +68,8 @@ class CONTENT_EXPORT StoragePartitionImplMap + FRIEND_TEST_ALL_PREFIXES(StoragePartitionConfigTest, OperatorLess); + FRIEND_TEST_ALL_PREFIXES(StoragePartitionImplMapTest, GarbageCollect); + ++ friend class brave::BraveBrowserContext; ++ + // Each StoragePartition is uniquely identified by which partition domain + // it belongs to (such as an app or the browser itself), the user supplied + // partition name and the bit indicating whether it should be persisted on diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 829401d6438671f55a9caf3a8f5eb5dc38234332..8ea576f35c95b7a0dbe050788a8d6b302ba75550 100644 --- a/content/browser/web_contents/web_contents_impl.cc @@ -1757,7 +1781,7 @@ index 0a6b0176a982782fd1472f607f811dd6c183c3fe..052ca73677cad3b10b494bf2ab823a04 (*map_type)[key] = value; ResetKeyIterator(); diff --git a/content/public/app/mojo/content_renderer_manifest.json b/content/public/app/mojo/content_renderer_manifest.json -index 5efdd84bc0862047e218b31a281232caee905beb..aaada991eb3ee26a6effdf8c0b871a6ce1c17e0b 100644 +index a0e53cf8b199fba071a83c0c45283696bf8c224d..ffeafa9d9bb22c51b862fc62ac5fc3a29280402d 100644 --- a/content/public/app/mojo/content_renderer_manifest.json +++ b/content/public/app/mojo/content_renderer_manifest.json @@ -47,6 +47,7 @@ @@ -2407,6 +2431,19 @@ index 86b4ac0d109fca5da44501b6fdb08d97b05fc28d..3294267b3e97cbc5c28a95473245fbc6 } else { socket_.reset(new SOCKSClientSocket( std::move(transport_socket_handle_), socks_params_->destination(), +diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc +index 369a1ca0c222526b3daf5250d221e43c37c2e2a3..ff58dc77128ece681a757bebb91f424f82ee14c0 100644 +--- a/net/proxy/proxy_service.cc ++++ b/net/proxy/proxy_service.cc +@@ -1476,7 +1476,7 @@ void ProxyService::ResetConfigService( + + void ProxyService::ForceReloadProxyConfig() { + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); +- ResetProxyConfig(false); ++ ResetProxyConfig(true); + ApplyProxyConfigIfAvailable(); + } + diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index 389315a25d7da30d71b59e3803ab795bc4c18e1c..79797fe7e674f9f6d2a65de542f262a945454f16 100644 --- a/net/url_request/url_request_job.h diff --git a/vendor/brightray/browser/browser_context.cc b/vendor/brightray/browser/browser_context.cc index 8d1e7f9f4f..d0c73f47ec 100644 --- a/vendor/brightray/browser/browser_context.cc +++ b/vendor/brightray/browser/browser_context.cc @@ -143,10 +143,6 @@ std::unique_ptr BrowserContext::CreateZoomLevelDeleg return std::unique_ptr(); } -bool BrowserContext::IsOffTheRecord() const { - return in_memory_; -} - content::ResourceContext* BrowserContext::GetResourceContext() { return resource_context_.get(); } @@ -175,25 +171,9 @@ content::BackgroundSyncController* BrowserContext::GetBackgroundSyncController() return nullptr; } -net::URLRequestContextGetter* -BrowserContext::CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) { - return nullptr; -} - net::URLRequestContextGetter* BrowserContext::CreateMediaRequestContext() { return url_request_getter_.get(); } -net::URLRequestContextGetter* -BrowserContext::CreateMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory) { - return nullptr; -} - } // namespace brightray diff --git a/vendor/brightray/browser/browser_context.h b/vendor/brightray/browser/browser_context.h index 0caf81b5f0..4e12ada814 100644 --- a/vendor/brightray/browser/browser_context.h +++ b/vendor/brightray/browser/browser_context.h @@ -36,7 +36,6 @@ class BrowserContext : public content::BrowserContext, // content::BrowserContext: std::unique_ptr CreateZoomLevelDelegate( const base::FilePath& partition_path) override; - bool IsOffTheRecord() const override; content::ResourceContext* GetResourceContext() override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; content::BrowserPluginGuestManager* GetGuestManager() override; @@ -47,15 +46,7 @@ class BrowserContext : public content::BrowserContext, net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) override; - net::URLRequestContextGetter* CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) override; net::URLRequestContextGetter* CreateMediaRequestContext() override; - net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory) override; URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get();