Rewild Your Web
at main 53 lines 2.0 kB view raw
1--- original 2+++ modified 3@@ -2,8 +2,9 @@ 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 6 7+use std::collections::HashMap; 8 use std::env::consts::ARCH; 9-use std::sync::{RwLock, RwLockReadGuard}; 10+use std::sync::{LazyLock, RwLock, RwLockReadGuard}; 11 12 use serde::{Deserialize, Serialize}; 13 use servo_config_macro::ServoPreferences; 14@@ -12,11 +13,16 @@ 15 16 static PREFERENCES: RwLock<Preferences> = RwLock::new(Preferences::const_default()); 17 18+/// Registry for embedder preferences, keyed by namespaced name (e.g., "browserhtml.theme"). 19+/// This allows embedder preferences to be accessed through the same API as core preferences. 20+static EMBEDDER_PREFS: LazyLock<RwLock<HashMap<String, PrefValue>>> = 21+ LazyLock::new(|| RwLock::new(HashMap::new())); 22+ 23 pub trait PreferencesObserver: Send + Sync { 24 fn prefs_changed(&self, _changes: &[(&'static str, PrefValue)]) {} 25 } 26 27-static OBSERVERS: RwLock<Vec<Box<dyn PreferencesObserver>>> = RwLock::new(Vec::new()); 28+pub(crate) static OBSERVERS: RwLock<Vec<Box<dyn PreferencesObserver>>> = RwLock::new(Vec::new()); 29 30 #[inline] 31 /// Get the current set of global preferences for Servo. 32@@ -62,6 +68,21 @@ 33 } 34 } 35 36+/// Get an embedder preference by its namespaced name (e.g., "browserhtml.theme"). 37+/// Returns `None` if the preference is not registered. 38+pub fn get_embedder_pref(name: &str) -> Option<PrefValue> { 39+ EMBEDDER_PREFS.read().unwrap().get(name).cloned() 40+} 41+ 42+/// Set an embedder preference by its namespaced name. 43+/// This is called internally by the embedder_prefs notification system. 44+pub fn set_embedder_pref(name: &str, value: PrefValue) { 45+ EMBEDDER_PREFS 46+ .write() 47+ .unwrap() 48+ .insert(name.to_string(), value); 49+} 50+ 51 /// A convenience macro for accessing a preference value using its static path. 52 /// Passing an invalid path is a compile-time error. 53 #[macro_export]