35 lines
1.4 KiB
Rust
35 lines
1.4 KiB
Rust
//! WebKit data store management
|
|
//!
|
|
//! Port of `webkit_data.c` / `webkit_data.h` from the C project.
|
|
|
|
use webkit2gtk::*;
|
|
use std::path::PathBuf;
|
|
|
|
/// Get the data directory for WebKit storage.
|
|
pub fn webkit_data_get_dir() -> PathBuf {
|
|
let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string());
|
|
PathBuf::from(home).join(".sovereign_browser").join("webkit_data")
|
|
}
|
|
|
|
/// Configure the website data manager for a profile.
|
|
pub fn webkit_data_configure(web_context: &WebContext, pubkey_hex: &str) {
|
|
let data_dir = webkit_data_get_dir().join(pubkey_hex);
|
|
std::fs::create_dir_all(&data_dir).ok();
|
|
|
|
// Use WebsiteDataManager builder pattern.
|
|
// local_storage_directory is deprecated since WebKitGTK 2.40 in favour of
|
|
// passing the base directory, but the builder API is the only way to set
|
|
// per-profile storage in webkit2gtk 2.0.2 Rust bindings.
|
|
#[allow(deprecated)]
|
|
let _manager = WebsiteDataManager::builder()
|
|
.local_storage_directory(data_dir.join("localstorage").to_str().unwrap_or(""))
|
|
.build();
|
|
|
|
// Per-user favicon database so a switched user doesn't see the previous
|
|
// user's visited-site icons in the tab strip. Mirrors the C
|
|
// `webkit_web_context_set_favicon_database_directory()` (web_context.c:237).
|
|
let fav_dir = data_dir.join("favicons");
|
|
std::fs::create_dir_all(&fav_dir).ok();
|
|
web_context.set_favicon_database_directory(fav_dir.to_str());
|
|
}
|