diff --git a/BUILD.gn b/BUILD.gn
index 6b0b0eb2a9..1d200201d1 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -19,6 +19,7 @@ import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
import("//v8/gni/v8.gni")
import("//third_party/icu/config.gni")
import("//media/cdm/library_cdm/cdm_paths.gni")
+import("//mojo/public/tools/bindings/mojom.gni")
import("//electron/build/config.gni")
group("electron") {
@@ -55,7 +56,10 @@ group("electron") {
}
if (use_aura && (is_win || is_linux)) {
- data_deps += [ "app:service_manifests" ]
+ data_deps += [
+ "//chrome/app:service_manifests",
+ "//chrome/app:chrome_renderer_manifest",
+ ]
}
}
@@ -84,7 +88,7 @@ grit("brave_resources") {
]
deps = [
- "app:brave_content_manifest_overlays",
+ "//chrome/app:chrome_content_manifest_overlays",
"//chrome/browser/safe_browsing",
]
@@ -239,6 +243,7 @@ source_set("common") {
"//base",
"//components/url_formatter",
"//content/public/child",
+ ":mojo_bindings",
]
if (enable_extensions) {
@@ -246,6 +251,17 @@ source_set("common") {
"brave/common/extensions/api",
]
}
+
+}
+
+mojom("mojo_bindings") {
+ sources = [
+ "brave/common/tor/tor.mojom",
+ ]
+
+ public_deps = [
+ "//mojo/public/mojom/base",
+ ]
}
source_set("utility") {
@@ -266,6 +282,7 @@ source_set("utility") {
"//components/cookie_config",
"//services/proxy_resolver:lib",
"//third_party/protobuf:protobuf_lite",
+ ":tor",
]
if (use_glib) {
@@ -291,6 +308,19 @@ source_set("utility") {
]
}
+source_set("tor") {
+ sources = [
+ "brave/utility/tor/tor_launcher_impl.cc",
+ "brave/utility/tor/tor_launcher_impl.h",
+ "brave/utility/tor/tor_service.cc",
+ "brave/utility/tor/tor_service.h",
+ ]
+
+ deps = [
+ ":mojo_bindings",
+ ]
+}
+
source_set("renderer") {
public_configs = [
"build:electron_config",
diff --git a/app/BUILD.gn b/app/BUILD.gn
index 210a921dc6..73854a269c 100644
--- a/app/BUILD.gn
+++ b/app/BUILD.gn
@@ -6,33 +6,9 @@ import("//build/config/ui.gni")
import("//tools/grit/grit_rule.gni")
import("//services/service_manager/public/service_manifest.gni")
-service_manifest("brave_content_packaged_services_manifest_overlay") {
- source = "//chrome/browser/chrome_content_packaged_services_manifest_overlay.json"
- packaged_services = [
- "//chrome/utility:profile_import_manifest",
- ]
-}
-
-group("brave_content_manifest_overlays") {
- deps = [
- "//chrome/app:chrome_content_manifest_overlays",
- ":brave_content_packaged_services_manifest_overlay",
- ]
-}
-
-if (use_aura) {
- service_manifest("brave_content_packaged_services_manifest") {
- source_manifest = "//content/public/app:packaged_services_manifest"
- overlays = [ ":brave_content_packaged_services_manifest_overlay" ]
- }
-
- group("service_manifests") {
- data_deps = [
- "//chrome/app:service_manifests",
- "//chrome/app:chrome_renderer_manifest",
- ":brave_content_packaged_services_manifest_overlay",
- ]
- }
+service_manifest("tor_launcher_manifest") {
+ name = "tor_launcher"
+ source = "//electron//brave/utility/tor/tor_manifest.json"
}
grit("brave_strings") {
diff --git a/app/brave_strings.grd b/app/brave_strings.grd
index c876b789a2..c2c3c8f200 100644
--- a/app/brave_strings.grd
+++ b/app/brave_strings.grd
@@ -20,6 +20,9 @@ Brave. These strings will be translated for each locale that Brave supports -->
Brave
+
+ Tor Launcher
+
diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc
index db0a260094..9711c7489c 100644
--- a/atom/browser/api/atom_api_session.cc
+++ b/atom/browser/api/atom_api_session.cc
@@ -40,6 +40,7 @@
#include "base/time/time.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/browser/brave_permission_manager.h"
+#include "brave/browser/tor/tor_launcher_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
@@ -177,6 +178,19 @@ struct Converter {
}
};
+template<>
+struct Converter {
+ static v8::Local ToV8(
+ v8::Isolate* isolate, brave::TorLauncherFactory::TorProcessState val) {
+ if (val == brave::TorLauncherFactory::TorProcessState::LAUNCH_SUCCEEDED)
+ return mate::StringToV8(isolate, "launch-succeeded");
+ else if (val == brave::TorLauncherFactory::TorProcessState::LAUNCH_FAILED)
+ return mate::StringToV8(isolate, "launch-failed");
+ else if (val == brave::TorLauncherFactory::TorProcessState::CRASHED)
+ return mate::StringToV8(isolate, "crashed");
+ }
+};
+
} // namespace mate
namespace atom {
@@ -215,14 +229,14 @@ class ResolveProxyHelper {
const GURL& url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- net::ProxyResolutionService* proxy_service =
+ net::ProxyResolutionService* proxy_resolution_service =
context_getter->GetURLRequestContext()->proxy_resolution_service();
net::CompletionCallback completion_callback =
base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted,
base::Unretained(this));
// Start the request.
- int result = proxy_service->ResolveProxy(
+ int result = proxy_resolution_service->ResolveProxy(
url, "GET", &proxy_info_, completion_callback,
&pac_req_, nullptr, net::NetLogWithSource());
@@ -293,20 +307,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_resolution_service();
- proxy_service->ResetConfigService(
- base::WrapUnique(new net::ProxyConfigServiceFixed(
- net::ProxyConfigWithAnnotation(config, NO_TRAFFIC_ANNOTATION_YET))));
- // 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) {
@@ -464,10 +464,24 @@ void Session::FlushStorageData() {
storage_partition->Flush();
}
+void SetProxyInIO(scoped_refptr getter,
+ const net::ProxyConfig& config,
+ const base::Closure& callback) {
+ auto proxy_resolution_service =
+ getter->GetURLRequestContext()->proxy_resolution_service();
+ proxy_resolution_service->ResetConfigService(base::WrapUnique(
+ new net::ProxyConfigServiceFixed(
+ net::ProxyConfigWithAnnotation(config, NO_TRAFFIC_ANNOTATION_YET))));
+ // Refetches and applies the new pac script if provided.
+ proxy_resolution_service->ForceReloadProxyConfig();
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE, callback);
+}
+
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));
+ base::Bind(&SetProxyInIO, request_context_getter_, config, callback));
}
void Session::SetDownloadPath(const base::FilePath& path) {
@@ -601,6 +615,62 @@ 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->IsTorBrowserContext()) {
+ LOG(ERROR) << __func__ << " only available for tor browser context";
+ return;
+ }
+ brave_browser_context->SetTorNewIdentity(url, callback);
+}
+
+void Session::RelaunchTor() const {
+ brave::BraveBrowserContext* brave_browser_context =
+ brave::BraveBrowserContext::FromBrowserContext(profile_);
+ if (!brave_browser_context->IsTorBrowserContext()) {
+ LOG(ERROR) << __func__ << " only available for tor browser context";
+ return;
+ }
+ brave_browser_context->RelaunchTor();
+}
+
+int64_t Session::GetTorPid() const {
+ brave::BraveBrowserContext* brave_browser_context =
+ brave::BraveBrowserContext::FromBrowserContext(profile_);
+ if (!brave_browser_context->IsTorBrowserContext()) {
+ LOG(ERROR) << __func__ << " only available for tor browser context";
+ return -1;
+ }
+ return brave_browser_context->GetTorPid();
+}
+
+void Session::SetTorLauncherCallback(mate::Arguments* args) {
+ brave::TorLauncherFactory::TorLauncherCallback callback;
+ if (!args->GetNext(&callback)) {
+ args->ThrowError("`callback(result, pid)` is a required field");
+ return;
+ }
+ brave::BraveBrowserContext* brave_browser_context =
+ brave::BraveBrowserContext::FromBrowserContext(profile_);
+ if (!brave_browser_context->IsTorBrowserContext()) {
+ LOG(ERROR) << __func__ << " only available for tor browser context";
+ return;
+ }
+ brave_browser_context->SetTorLauncherCallback(callback);
+}
+
// static
mate::Handle Session::CreateFrom(
v8::Isolate* isolate, content::BrowserContext* browser_context) {
@@ -659,6 +729,11 @@ void Session::BuildPrototype(v8::Isolate* isolate,
&Session::AllowNTLMCredentialsForDomains)
.SetMethod("setEnableBrotli", &Session::SetEnableBrotli)
.SetMethod("equal", &Session::Equal)
+ .SetMethod("isOffTheRecord", &Session::IsOffTheRecord)
+ .SetMethod("setTorNewIdentity", &Session::SetTorNewIdentity)
+ .SetMethod("relaunchTor", &Session::RelaunchTor)
+ .SetMethod("setTorLauncherCallback", &Session::SetTorLauncherCallback)
+ .SetMethod("getTorPid", &Session::GetTorPid)
.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 a652ca4877..187e9a6165 100644
--- a/atom/browser/api/atom_api_session.h
+++ b/atom/browser/api/atom_api_session.h
@@ -93,6 +93,12 @@ 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;
+ void RelaunchTor() const;
+ void SetTorLauncherCallback(mate::Arguments* args);
+ int64_t GetTorPid() 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 f8e0025bef..edf00725e3 100644
--- a/atom/browser/api/atom_api_web_contents.cc
+++ b/atom/browser/api/atom_api_web_contents.cc
@@ -413,6 +413,18 @@ 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);
+ }
+ std::string tor_path;
+ if (options.Get("tor_path", &tor_path)) {
+ session_options.SetString("tor_path", tor_path);
+ }
session = Session::FromPartition(isolate, partition, session_options);
} else {
// Use the default session if not specified.
diff --git a/atom/browser/extensions/atom_extensions_network_delegate.h b/atom/browser/extensions/atom_extensions_network_delegate.h
index 3ab0d6114f..e9b10d0952 100644
--- a/atom/browser/extensions/atom_extensions_network_delegate.h
+++ b/atom/browser/extensions/atom_extensions_network_delegate.h
@@ -30,20 +30,24 @@ class AtomExtensionsNetworkDelegate : public atom::AtomNetworkDelegate {
static void SetAcceptAllCookies(bool accept);
+ protected:
+ int OnBeforeURLRequest(net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ GURL* new_url) override;
+ int OnBeforeStartTransaction(net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ net::HttpRequestHeaders* headers) override;
+ void OnBeforeRedirect(net::URLRequest* request,
+ const GURL& new_location) override;
+
private:
// NetworkDelegate implementation.
int OnBeforeURLRequestInternal(
net::URLRequest* request,
GURL* new_url);
- int OnBeforeURLRequest(net::URLRequest* request,
- const net::CompletionCallback& callback,
- GURL* new_url) override;
int OnBeforeStartTransactionInternal(
net::URLRequest* request,
net::HttpRequestHeaders* headers);
- int OnBeforeStartTransaction(net::URLRequest* request,
- const net::CompletionCallback& callback,
- net::HttpRequestHeaders* headers) override;
void OnStartTransaction(net::URLRequest* request,
const net::HttpRequestHeaders& headers) override;
int OnHeadersReceivedInternal(
@@ -57,8 +61,6 @@ class AtomExtensionsNetworkDelegate : public atom::AtomNetworkDelegate {
const net::HttpResponseHeaders* original_response_headers,
scoped_refptr* override_response_headers,
GURL* allowed_unsafe_redirect_url) override;
- void OnBeforeRedirect(net::URLRequest* request,
- const GURL& new_location) override;
void OnResponseStarted(net::URLRequest* request, int net_error) override;
void OnCompleted(net::URLRequest* request,
bool started,
diff --git a/atom/utility/atom_content_utility_client.cc b/atom/utility/atom_content_utility_client.cc
index b8ed31ea59..2dc999fe5e 100644
--- a/atom/utility/atom_content_utility_client.cc
+++ b/atom/utility/atom_content_utility_client.cc
@@ -10,7 +10,9 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
+#include "brave/common/tor/tor.mojom.h"
#include "brave/utility/importer/brave_profile_import_service.h"
+#include "brave/utility/tor/tor_service.h"
#include "chrome/common/importer/profile_import.mojom.h"
#include "components/services/unzip/public/interfaces/constants.mojom.h"
#include "components/services/unzip/unzip_service.h"
@@ -129,6 +131,12 @@ void AtomContentUtilityClient::RegisterServices(
base::BindRepeating(&unzip::UnzipService::CreateService);
services->emplace(unzip::mojom::kServiceName, service_info);
}
+
+ service_manager::EmbeddedServiceInfo tor_info;
+ tor_info.factory =
+ base::Bind(&TorService::CreateService);
+ services->emplace(tor::mojom::kTorServiceName,
+ tor_info);
}
// static
diff --git a/brave/browser/BUILD.gn b/brave/browser/BUILD.gn
index ead7f6fd62..871e775aa6 100644
--- a/brave/browser/BUILD.gn
+++ b/brave/browser/BUILD.gn
@@ -45,6 +45,8 @@ source_set("browser") {
deps = [
":apis",
+ ":proxy",
+ ":tor",
"//electron/atom/browser",
"//electron:common",
"//electron/muon/app",
@@ -156,3 +158,36 @@ source_set("apis") {
"component_updater",
]
}
+
+source_set("proxy") {
+ configs += [
+ "//electron/build:electron_config",
+ ]
+
+ sources = [
+ "net/proxy_resolution/proxy_config_service_tor.cc",
+ "net/proxy_resolution/proxy_config_service_tor.h",
+ "net/tor_proxy_network_delegate.cc",
+ "net/tor_proxy_network_delegate.h",
+ ]
+
+ deps = [
+ "//net",
+ "//third_party/blink/public:blink_headers",
+ ]
+}
+
+source_set("tor") {
+ configs += [
+ "//electron/build:electron_config",
+ ]
+
+ sources = [
+ "tor/tor_launcher_factory.cc",
+ "tor/tor_launcher_factory.h",
+ ]
+
+ deps = [
+ "//third_party/blink/public:blink_headers",
+ ]
+}
diff --git a/brave/browser/brave_browser_context.cc b/brave/browser/brave_browser_context.cc
index b79c3aea23..aa1b0fd0b5 100644
--- a/brave/browser/brave_browser_context.cc
+++ b/brave/browser/brave_browser_context.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include
+#include
#include
#include
@@ -12,6 +14,7 @@
#include "base/files/file_util.h"
#include "base/trace_event/trace_event.h"
#include "brave/browser/brave_permission_manager.h"
+#include "brave/browser/net/tor_proxy_network_delegate.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"
@@ -44,17 +47,25 @@
#include "components/zoom/zoom_event_manager.h"
#include "components/webdata_services/web_data_service_wrapper.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 "content/public/common/service_manager_connection.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "extensions/browser/pref_names.h"
#include "extensions/buildflags/buildflags.h"
#include "net/base/escape.h"
#include "net/cookies/cookie_store.h"
+#include "net/proxy_resolution/proxy_resolution_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"
@@ -169,6 +180,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;
@@ -178,6 +191,22 @@ 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_ = tor_proxy;
+ }
+
+ base::FilePath::StringType tor_path;
+ if (options.GetString("tor_path", &tor_path) && tor_proxy_.length()) {
+ tor_launcher_factory_.reset(new TorLauncherFactory(tor_path, tor_proxy_));
+ tor_launcher_factory_->LaunchTorProcess();
+ }
+
if (in_memory) {
original_context_ = static_cast(
atom::AtomBrowserContext::From(partition, false));
@@ -317,6 +346,60 @@ 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),
+ protocol_handlers,
+ std::move(request_interceptors));
+ StoragePartitionDescriptor descriptor(partition_path, in_memory);
+ // Inherits web requests handlers from default parition
+ auto default_network_delegate = GetDefaultStoragePartition(this)->
+ GetURLRequestContext()->GetURLRequestContext()->network_delegate();
+ url_request_context_getter->GetURLRequestContext()
+ ->set_network_delegate(default_network_delegate);
+ url_request_context_getter_map_[descriptor] = url_request_context_getter;
+ 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
@@ -392,9 +475,14 @@ net::URLRequestContextGetter* BraveBrowserContext::GetRequestContext() {
net::NetworkDelegate* BraveBrowserContext::CreateNetworkDelegate() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- return new extensions::AtomExtensionsNetworkDelegate(this,
- info_map_,
- g_browser_process->extension_event_router_forwarder());
+ if (isolated_storage_)
+ return new brave::TorProxyNetworkDelegate(this,
+ info_map_,
+ g_browser_process->extension_event_router_forwarder());
+ else
+ return new extensions::AtomExtensionsNetworkDelegate(this,
+ info_map_,
+ g_browser_process->extension_event_router_forwarder());
}
std::unique_ptr
@@ -414,6 +502,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_);
}
@@ -596,7 +689,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;
@@ -634,6 +727,52 @@ 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_resolution_service =
+ url_request_context_getter->GetURLRequestContext()->
+ proxy_resolution_service();
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&net::ProxyConfigServiceTor::TorSetProxy,
+ proxy_resolution_service,
+ tor_proxy_,
+ host,
+ &tor_proxy_map_,
+ true),
+ callback);
+}
+
+void BraveBrowserContext::RelaunchTor() const {
+ if (tor_launcher_factory_.get())
+ tor_launcher_factory_->RelaunchTorProcess();
+}
+
+void BraveBrowserContext::SetTorLauncherCallback(
+ const TorLauncherFactory::TorLauncherCallback& callback) {
+ if (tor_launcher_factory_.get())
+ tor_launcher_factory_->SetLauncherCallback(callback);
+}
+
+int64_t BraveBrowserContext::GetTorPid() const {
+ if (tor_launcher_factory_.get())
+ return tor_launcher_factory_->GetTorPid();
+ else
+ return -1;
+}
+
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 cfcb8d5751..1cecd17c91 100644
--- a/brave/browser/brave_browser_context.h
+++ b/brave/browser/brave_browser_context.h
@@ -5,13 +5,17 @@
#ifndef BRAVE_BROWSER_BRAVE_BROWSER_CONTEXT_H_
#define BRAVE_BROWSER_BRAVE_BROWSER_CONTEXT_H_
+#include