8000 fix: provide paths for all NetworkContextFilePaths keys by MarshallOfSound · Pull Request #31777 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

< 8000 bdi class="js-issue-title markdown-title">fix: provide paths for all NetworkContextFilePaths keys #31777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chromium_src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ static_library("chrome") {
"//chrome/browser/accessibility/accessibility_ui.h",
"//chrome/browser/app_mode/app_mode_utils.cc",
"//chrome/browser/app_mode/app_mode_utils.h",
"//chrome/browser/browser_features.cc",
"//chrome/browser/browser_features.h",
"//chrome/browser/browser_process.cc",
"//chrome/browser/browser_process.h",
"//chrome/browser/devtools/devtools_contents_resizing_strategy.cc",
Expand Down
28 changes: 27 additions & 1 deletion shell/browser/net/network_context_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <utility>

#include "chrome/browser/browser_features.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
Expand All @@ -19,6 +20,21 @@

namespace electron {

namespace {

bool ShouldTriggerNetworkDataMigration() {
#if defined(OS_WIN)
// On Windows, if sandbox enabled means data must be migrated.
if (SystemNetworkContextManager::IsNetworkSandboxEnabled())
return true;
#endif // defined(OS_WIN)
if (base::FeatureList::IsEnabled(features::kTriggerNetworkDataMigration))
return true;
return false;
}

} // namespace

NetworkContextService::NetworkContextService(content::BrowserContext* context)
: browser_context_(static_cast<ElectronBrowserContext*>(context)),
proxy_config_monitor_(browser_context_->prefs()) {}
Expand Down Expand Up @@ -70,7 +86,11 @@ void NetworkContextService::ConfigureNetworkContextParams(

network_context_params->file_paths =
network::mojom::NetworkContextFilePaths::New();
network_context_params->file_paths->data_path = path;
network_context_params->file_paths->data_path =
path.Append(chrome::kNetworkDataDirname);
network_context_params->file_paths->unsandboxed_data_path = path;
network_context_params->file_paths->trigger_migration =
ShouldTriggerNetworkDataMigration();

// Currently this just contains HttpServerProperties
network_context_params->file_paths->http_server_properties_file_name =
Expand All @@ -80,6 +100,12 @@ void NetworkContextService::ConfigureNetworkContextParams(
network_context_params->file_paths->cookie_database_name =
base::FilePath(chrome::kCookieFilename);

network_context_params->file_paths->http_server_properties_file_name =
base::FilePath(chrome::kNetworkPersistentStateFilename);

network_context_params->file_paths->trust_token_database_name =
base::FilePath(chrome::kTrustTokenFilename);

network_context_params->restore_old_session_cookies = false;
network_context_params->persist_session_cookies = false;

Expand Down
22 changes: 22 additions & 0 deletions shell/browser/net/system_network_context_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "components/os_crypt/os_crypt.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/common/content_features.h"
Expand Down Expand Up @@ -50,6 +51,14 @@

namespace {

#if defined(OS_WIN)
namespace {

const char kNetworkServiceSandboxEnabled[] = "net.network_service_sandbox";

}
#endif // defined(OS_WIN)

// The global instance of the SystemNetworkContextmanager.
SystemNetworkContextManager* g_system_network_context_manager = nullptr;

Expand Down Expand Up @@ -220,6 +229,19 @@ void SystemNetworkContextManager::DeleteInstance() {
delete g_system_network_context_manager;
}

// c.f.
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/net/system_network_context_manager.cc;l=730-740;drc=15a616c8043551a7cb22c4f73a88e83afb94631c;bpv=1;bpt=1
bool SystemNetworkContextManager::IsNetworkSandboxEnabled() {
#if defined(OS_WIN)
auto* local_state = g_browser_process->local_state();
if (local_state && local_state->HasPrefPath(kNetworkServiceSandboxEnabled)) {
return local_state->GetBoolean(kNetworkServiceSandboxEnabled);
}
#endif // defined(OS_WIN)
// If no policy is specified, then delegate to global sandbox configuration.
return sandbox::policy::features::IsNetworkSandboxEnabled();
}

SystemNetworkContextManager::SystemNetworkContextManager(
PrefService* pref_service)
: proxy_config_monitor_(pref_service) {
Expand Down
8 changes: 8 additions & 0 deletions shell/browser/net/system_network_context_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/net/proxy_config_monitor.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "sandbox/policy/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
Expand Down Expand Up @@ -49,6 +50,13 @@ class SystemNetworkContextManager {
// Destroys the global SystemNetworkContextManager instance.
static void DeleteInstance();

// c.f.
// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/net/system_network_context_manager.cc;l=730-740;drc=15a616c8043551a7cb22c4f73a88e83afb94631c;bpv=1;bpt=1
// Returns whether the network sandbox is enabled. This depends on policy but
// also feature status from sandbox. Called before there is an instance of
// SystemNetworkContextManager.
static bool IsNetworkSandboxEnabled();

// Configures default set of parameters for configuring the network context.
void ConfigureDefaultNetworkContextParams(
network::mojom::NetworkContextParams* network_context_params);
Expand Down
0