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
Pref api #26793
Merged
+1,005
−275
Merged
Pref api #26793
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Embedding API: prefs r/w
- Loading branch information
commit 479afcfb8e9882f7b0c6e3b99d148654ea39e576
| @@ -7,6 +7,7 @@ extern crate log; | ||
|
|
||
| pub mod gl_glue; | ||
|
|
||
| pub use servo::config::prefs::{add_user_prefs, PrefValue}; | ||
| pub use servo::embedder_traits::{ | ||
| ContextMenuResult, MediaSessionPlaybackState, PermissionPrompt, PermissionRequest, PromptResult, | ||
| }; | ||
| @@ -19,6 +20,7 @@ use servo::compositing::windowing::{ | ||
| AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent, | ||
| WindowMethods, | ||
| }; | ||
| use servo::config::prefs::pref_map; | ||
| use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods}; | ||
| use servo::embedder_traits::{ | ||
| EmbedderMsg, EmbedderProxy, MediaSessionEvent, PromptDefinition, PromptOrigin, | ||
| @@ -36,6 +38,7 @@ use servo::webrender_surfman::WebrenderSurfman; | ||
| use servo::{self, gl, BrowserId, Servo}; | ||
| use servo_media::player::context as MediaPlayerContext; | ||
| use std::cell::RefCell; | ||
| use std::collections::HashMap; | ||
| use std::mem; | ||
| use std::os::raw::c_void; | ||
| use std::path::PathBuf; | ||
| @@ -55,14 +58,14 @@ pub use servo::embedder_traits::EventLoopWaker; | ||
|
|
||
| pub struct InitOptions { | ||
| pub args: Vec<String>, | ||
| pub url: Option<String>, | ||
| pub coordinates: Coordinates, | ||
| pub density: f32, | ||
| pub xr_discovery: Option<webxr::Discovery>, | ||
| pub enable_subpixel_text_antialiasing: bool, | ||
| pub gl_context_pointer: Option<*const c_void>, | ||
| pub native_display_pointer: Option<*const c_void>, | ||
| pub native_widget: *mut c_void, | ||
| pub prefs: Option<HashMap<String, PrefValue>>, | ||
| } | ||
paulrouget
Author
Contributor
|
||
|
|
||
| #[derive(Clone, Debug)] | ||
| @@ -173,6 +176,44 @@ pub fn is_uri_valid(url: &str) -> bool { | ||
| ServoUrl::parse(url).is_ok() | ||
| } | ||
|
|
||
| /// Retrieve a snapshot of the current preferences | ||
| pub fn get_prefs() -> HashMap<String, (PrefValue, bool)> { | ||
| pref_map() | ||
| .iter() | ||
| .map(|(key, value)| { | ||
| let is_default = pref_map().is_default(&key).unwrap(); | ||
| (key, (value, is_default)) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| /// Retrieve a preference. | ||
| pub fn get_pref(key: &str) -> (PrefValue, bool) { | ||
| if let Ok(is_default) = pref_map().is_default(&key) { | ||
| (pref_map().get(key), is_default) | ||
| } else { | ||
| (PrefValue::Missing, false) | ||
| } | ||
| } | ||
|
|
||
| /// Restore a preference to its default value. | ||
| pub fn reset_pref(key: &str) -> bool { | ||
| pref_map().reset(key).is_ok() | ||
| } | ||
|
|
||
| /// Restore all the preferences to their default values. | ||
| pub fn reset_all_prefs() { | ||
| pref_map().reset_all(); | ||
| } | ||
|
|
||
| /// Change the value of a preference. | ||
| pub fn set_pref(key: &str, val: PrefValue) -> Result<(), &'static str> { | ||
| pref_map() | ||
| .set(key, val) | ||
| .map(|_| ()) | ||
| .map_err(|_| "Pref set failed") | ||
| } | ||
|
|
||
| /// Initialize Servo. At that point, we need a valid GL context. | ||
| /// In the future, this will be done in multiple steps. | ||
| pub fn init( | ||
| @@ -195,16 +236,14 @@ pub fn init( | ||
| opts::from_cmdline_args(Options::new(), &args); | ||
| } | ||
|
|
||
| let embedder_url = init_opts.url.as_ref().and_then(|s| ServoUrl::parse(s).ok()); | ||
| let cmdline_url = opts::get().url.clone(); | ||
| if let Some(prefs) = init_opts.prefs { | ||
| add_user_prefs(prefs); | ||
| } | ||
|
|
||
| let pref_url = ServoUrl::parse(&pref!(shell.homepage)).ok(); | ||
| let blank_url = ServoUrl::parse("about:blank").ok(); | ||
|
|
||
| let url = embedder_url | ||
| .or(cmdline_url) | ||
| .or(pref_url) | ||
| .or(blank_url) | ||
| .unwrap(); | ||
| let url = pref_url.or(blank_url).unwrap(); | ||
|
|
||
| gl.clear_color(1.0, 1.0, 1.0, 1.0); | ||
| gl.clear(gl::COLOR_BUFFER_BIT); | ||
| @@ -8,6 +8,8 @@ extern crate lazy_static; | ||
| #[macro_use] | ||
| extern crate log; | ||
|
|
||
| mod prefs; | ||
|
|
||
| #[cfg(target_os = "windows")] | ||
| mod vslogger; | ||
|
|
||
| @@ -187,7 +189,7 @@ fn do_redirect_stdout_stderr(handler: LogHandlerFn) -> Result<(), ()> { | ||
|
|
||
| fn call<T, F>(f: F) -> T | ||
| where | ||
| F: Fn(&mut ServoGlue) -> Result<T, &'static str>, | ||
| F: FnOnce(&mut ServoGlue) -> Result<T, &'static str>, | ||
| { | ||
| match SERVO.with(|s| match s.borrow_mut().as_mut() { | ||
| Some(ref mut s) => (f)(s), | ||
| @@ -235,14 +237,14 @@ pub struct CHostCallbacks { | ||
| #[repr(C)] | ||
| pub struct CInitOptions { | ||
| pub args: *const c_char, | ||
| pub url: *const c_char, | ||
| pub width: i32, | ||
| pub height: i32, | ||
| pub density: f32, | ||
| pub enable_subpixel_text_antialiasing: bool, | ||
| pub vslogger_mod_list: *const *const c_char, | ||
| pub vslogger_mod_size: u32, | ||
| pub native_widget: *mut c_void, | ||
| pub prefs: *const prefs::CPrefList, | ||
| } | ||
|
|
||
| #[repr(C)] | ||
| @@ -427,15 +429,18 @@ unsafe fn init( | ||
| warn!("Error redirecting stdout/stderr: {}", reason); | ||
| } | ||
|
|
||
| let url = CStr::from_ptr(opts.url); | ||
| let url = url.to_str().map(|s| s.to_string()).ok(); | ||
|
|
||
| let coordinates = Coordinates::new(0, 0, opts.width, opts.height, opts.width, opts.height); | ||
|
|
||
| let prefs = if opts.prefs.is_null() { | ||
| None | ||
| } else { | ||
| Some((*opts.prefs).convert()) | ||
| }; | ||
|
|
||
| let opts = InitOptions { | ||
| args, | ||
| url, | ||
| coordinates, | ||
| prefs, | ||
| density: opts.density, | ||
| xr_discovery: None, | ||
| enable_subpixel_text_antialiasing: opts.enable_subpixel_text_antialiasing, | ||
| @@ -532,6 +537,9 @@ pub extern "C" fn resize(width: i32, height: i32) { | ||
| pub extern "C" fn perform_updates() { | ||
| catch_any_panic(|| { | ||
| debug!("perform_updates"); | ||
| // We might have allocated some memory to respond to a potential | ||
| // request, from the embedder, for a copy of Servo's preferences. | ||
| prefs::free_prefs(); | ||
paulrouget
Author
Contributor
|
||
| call(|s| s.perform_updates()); | ||
| }); | ||
| } | ||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
This is moved under the winit port. The embedder is in charge of parsing the command line and feeding the pref to servo.