doc(resources): Preferences, HstsPreloadList, RippyPNG (#33775)

* Set to default if Preferences and HstsPreloadList are empty

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Add documentation of Preferences, HstsPreloadList, RippyPNG

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Add warn log when setting prefs to default

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Add error log instead

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Add error log to HSTS preload list

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Apply suggestions from code review

Address a couple wording nits

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

---------

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Ngo Iok Ui (Wu Yu Wei) 2024-10-11 03:19:41 +09:00 committed by GitHub
parent fd19409f31
commit b58cee48ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View file

@ -9,7 +9,7 @@ use std::sync::LazyLock;
use embedder_traits::resources::{self, Resource}; use embedder_traits::resources::{self, Resource};
use gen::Prefs; use gen::Prefs;
use log::warn; use log::{error, warn};
use serde_json::{self, Value}; use serde_json::{self, Value};
use crate::pref_util::Preferences; use crate::pref_util::Preferences;
@ -17,7 +17,10 @@ pub use crate::pref_util::{PrefError, PrefValue};
static PREFS: LazyLock<Preferences<'static, Prefs>> = LazyLock::new(|| { static PREFS: LazyLock<Preferences<'static, Prefs>> = LazyLock::new(|| {
let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences)) let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences))
.expect("Failed to initialize config preferences."); .unwrap_or_else(|_| {
error!("Preference json file is invalid. Setting Preference to default values");
Prefs::default()
});
let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS); let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS);
for (key, value) in result.iter() { for (key, value) in result.iter() {
set_stylo_pref_ref(&key, &value); set_stylo_pref_ref(&key, &value);

View file

@ -10,7 +10,7 @@ use base::cross_process_instant::CrossProcessInstant;
use embedder_traits::resources::{self, Resource}; use embedder_traits::resources::{self, Resource};
use headers::{HeaderMapExt, StrictTransportSecurity}; use headers::{HeaderMapExt, StrictTransportSecurity};
use http::HeaderMap; use http::HeaderMap;
use log::info; use log::{error, info};
use net_traits::pub_domains::reg_suffix; use net_traits::pub_domains::reg_suffix;
use net_traits::IncludeSubdomains; use net_traits::IncludeSubdomains;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -88,7 +88,10 @@ impl HstsList {
pub fn from_servo_preload() -> HstsList { pub fn from_servo_preload() -> HstsList {
let list = resources::read_string(Resource::HstsPreloadList); let list = resources::read_string(Resource::HstsPreloadList);
HstsList::from_preload(&list).expect("Servo HSTS preload file is invalid") HstsList::from_preload(&list).unwrap_or_else(|| {
error!("HSTS preload file is invalid. Setting HSTS list to default values");
HstsList::default()
})
} }
pub fn is_host_secure(&self, host: &str) -> bool { pub fn is_host_secure(&self, host: &str) -> bool {

View file

@ -55,9 +55,13 @@ pub fn sandbox_access_files_dirs() -> Vec<PathBuf> {
} }
pub enum Resource { pub enum Resource {
/// A json file of [`Preferences`](servo_config::pref_util::Preferences) configuration.
/// It can be empty but lots of features will be disabled.
Preferences, Preferences,
BluetoothBlocklist, BluetoothBlocklist,
DomainList, DomainList,
/// A preloaded list of HTTP Strict Transport Security. It can be an empty list and
/// [`HstsList::default()`](net::hsts::HstsList) will be called.
HstsPreloadList, HstsPreloadList,
BadCertHTML, BadCertHTML,
NetErrorHTML, NetErrorHTML,
@ -65,6 +69,12 @@ pub enum Resource {
ServoCSS, ServoCSS,
PresentationalHintsCSS, PresentationalHintsCSS,
QuirksModeCSS, QuirksModeCSS,
/// A placeholder image to display if we couldn't get the requested image.
///
/// ## Safety
///
/// Servo will crash if this is an invalid image. Check `resources/rippy.png` in Servo codebase to see what
/// a default rippy png should look like.
RippyPNG, RippyPNG,
MediaControlsCSS, MediaControlsCSS,
MediaControlsJS, MediaControlsJS,