Skip to content

Commit 246884c

Browse files
fix: provide paths for all NetworkContextFilePaths keys (electron#31777)
* fix: provide paths for all NetworkContextFilePaths keys * chore: include chrome features header * chore: build browser_features * yolo * add pref service * fix: include sandbox policy features * fix pref key * fix: gate pref key to OS_WIN Co-authored-by: VerteDinde <[email protected]>
1 parent 65e4f75 commit 246884c

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

chromium_src/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ static_library("chrome") {
1717
"//chrome/browser/accessibility/accessibility_ui.h",
1818
"//chrome/browser/app_mode/app_mode_utils.cc",
1919
"//chrome/browser/app_mode/app_mode_utils.h",
20+
"//chrome/browser/browser_features.cc",
21+
"//chrome/browser/browser_features.h",
2022
"//chrome/browser/browser_process.cc",
2123
"//chrome/browser/browser_process.h",
2224
"//chrome/browser/devtools/devtools_contents_resizing_strategy.cc",

shell/browser/net/network_context_service.cc

+27-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <utility>
88

9+
#include "chrome/browser/browser_features.h"
910
#include "chrome/common/chrome_constants.h"
1011
#include "content/public/browser/network_service_instance.h"
1112
#include "content/public/browser/shared_cors_origin_access_list.h"
@@ -19,6 +20,21 @@
1920

2021
namespace electron {
2122

23+
namespace {
24+
25+
bool ShouldTriggerNetworkDataMigration() {
26+
#if defined(OS_WIN)
27+
// On Windows, if sandbox enabled means data must be migrated.
28+
if (SystemNetworkContextManager::IsNetworkSandboxEnabled())
29+
return true;
30+
#endif // defined(OS_WIN)
31+
if (base::FeatureList::IsEnabled(features::kTriggerNetworkDataMigration))
32+
return true;
33+
return false;
34+
}
35+
36+
} // namespace
37+
2238
NetworkContextService::NetworkContextService(content::BrowserContext* context)
2339
: browser_context_(static_cast<ElectronBrowserContext*>(context)),
2440
proxy_config_monitor_(browser_context_->prefs()) {}
@@ -70,7 +86,11 @@ void NetworkContextService::ConfigureNetworkContextParams(
7086

7187
network_context_params->file_paths =
7288
network::mojom::NetworkContextFilePaths::New();
73-
network_context_params->file_paths->data_path = path;
89+
network_context_params->file_paths->data_path =
90+
path.Append(chrome::kNetworkDataDirname);
91+
network_context_params->file_paths->unsandboxed_data_path = path;
92+
network_context_params->file_paths->trigger_migration =
93+
ShouldTriggerNetworkDataMigration();
7494

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

103+
network_context_params->file_paths->http_server_properties_file_name =
104+
base::FilePath(chrome::kNetworkPersistentStateFilename);
105+
106+
network_context_params->file_paths->trust_token_database_name =
107+
base::FilePath(chrome::kTrustTokenFilename);
108+
83109
network_context_params->restore_old_session_cookies = false;
84110
network_context_params->persist_session_cookies = false;
85111

shell/browser/net/system_network_context_manager.cc

+22
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "chrome/common/chrome_paths.h"
1919
#include "chrome/common/chrome_switches.h"
2020
#include "components/os_crypt/os_crypt.h"
21+
#include "components/prefs/pref_service.h"
2122
#include "content/public/browser/browser_thread.h"
2223
#include "content/public/browser/network_service_instance.h"
2324
#include "content/public/common/content_features.h"
@@ -50,6 +51,14 @@
5051

5152
namespace {
5253

54+
#if defined(OS_WIN)
55+
namespace {
56+
57+
const char kNetworkServiceSandboxEnabled[] = "net.network_service_sandbox";
58+
59+
}
60+
#endif // defined(OS_WIN)
61+
5362
// The global instance of the SystemNetworkContextmanager.
5463
SystemNetworkContextManager* g_system_network_context_manager = nullptr;
5564

@@ -220,6 +229,19 @@ void SystemNetworkContextManager::DeleteInstance() {
220229
delete g_system_network_context_manager;
221230
}
222231

232+
// c.f.
233+
// 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
234+
bool SystemNetworkContextManager::IsNetworkSandboxEnabled() {
235+
#if defined(OS_WIN)
236+
auto* local_state = g_browser_process->local_state();
237+
if (local_state && local_state->HasPrefPath(kNetworkServiceSandboxEnabled)) {
238+
return local_state->GetBoolean(kNetworkServiceSandboxEnabled);
239+
}
240+
#endif // defined(OS_WIN)
241+
// If no policy is specified, then delegate to global sandbox configuration.
242+
return sandbox::policy::features::IsNetworkSandboxEnabled();
243+
}
244+
223245
SystemNetworkContextManager::SystemNetworkContextManager(
224246
PrefService* pref_service)
225247
: proxy_config_monitor_(pref_service) {

shell/browser/net/system_network_context_manager.h

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "base/memory/ref_counted.h"
99
#include "chrome/browser/net/proxy_config_monitor.h"
1010
#include "mojo/public/cpp/bindings/remote.h"
11+
#include "sandbox/policy/features.h"
1112
#include "services/network/public/cpp/shared_url_loader_factory.h"
1213
#include "services/network/public/mojom/network_context.mojom.h"
1314
#include "services/network/public/mojom/network_service.mojom.h"
@@ -49,6 +50,13 @@ class SystemNetworkContextManager {
4950
// Destroys the global SystemNetworkContextManager instance.
5051
static void DeleteInstance();
5152

53+
// c.f.
54+
// 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
55+
// Returns whether the network sandbox is enabled. This depends on policy but
56+
// also feature status from sandbox. Called before there is an instance of
57+
// SystemNetworkContextManager.
58+
static bool IsNetworkSandboxEnabled();
59+
5260
// Configures default set of parameters for configuring the network context.
5361
void ConfigureDefaultNetworkContextParams(
5462
network::mojom::NetworkContextParams* network_context_params);

0 commit comments

Comments
 (0)