Allow setting userscripts directly without the need of files (#35388)

* Allow settings userscripts through preferences

Signed-off-by: Tony <legendmastertony@gmail.com>

* mach fmt instead of cargo fmt

Signed-off-by: Tony <legendmastertony@gmail.com>

* Fix pref loading not working for array values

Signed-off-by: Tony <legendmastertony@gmail.com>

* Use pref! in userscripts instead

Signed-off-by: Tony <legendmastertony@gmail.com>

* Implement the model jdm suggested
- Remove userscripts from all places and move it to servoshell
- Add in `UserContentManager` struct and passing it through `Servo::new`
all the way down to script thread

Signed-off-by: Tony <legendmastertony@gmail.com>

* Apply suggestions from code review and format

Signed-off-by: Tony <legendmastertony@gmail.com>

* Revert unrelated change

Signed-off-by: Tony <legendmastertony@gmail.com>

---------

Signed-off-by: Tony <legendmastertony@gmail.com>
Signed-off-by: Tony <68118705+Legend-Master@users.noreply.github.com>
This commit is contained in:
Tony 2025-03-27 11:00:08 +08:00 committed by GitHub
parent 53a2e61fec
commit 5a76906d64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 143 additions and 51 deletions

View file

@ -26,6 +26,7 @@ use crossbeam_channel::{Sender, unbounded};
use cssparser::{Parser, ParserInput, SourceLocation};
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
use dom_struct::dom_struct;
use embedder_traits::user_content_manager::{UserContentManager, UserScript};
use embedder_traits::{
AlertResponse, ConfirmResponse, EmbedderMsg, PromptResponse, SimpleDialog, Theme,
WebDriverJSError, WebDriverJSResult,
@ -373,10 +374,9 @@ pub(crate) struct Window {
/// Unminify Css.
unminify_css: bool,
/// Where to load userscripts from, if any. An empty string will load from
/// the resources/user-agent-js directory, and if the option isn't passed userscripts
/// won't be loaded.
userscripts_path: Option<String>,
/// User content manager
#[no_trace]
user_content_manager: UserContentManager,
/// Window's GL context from application
#[ignore_malloc_size_of = "defined in script_thread"]
@ -624,8 +624,8 @@ impl Window {
&self.compositor_api
}
pub(crate) fn get_userscripts_path(&self) -> Option<String> {
self.userscripts_path.clone()
pub(crate) fn userscripts(&self) -> &[UserScript] {
self.user_content_manager.scripts()
}
pub(crate) fn get_player_context(&self) -> WindowGLContext {
@ -2797,7 +2797,7 @@ impl Window {
unminify_js: bool,
unminify_css: bool,
local_script_source: Option<String>,
userscripts_path: Option<String>,
user_content_manager: UserContentManager,
user_agent: Cow<'static, str>,
player_context: WindowGLContext,
#[cfg(feature = "webgpu")] gpu_id_hub: Arc<IdentityHub>,
@ -2884,7 +2884,7 @@ impl Window {
has_sent_idle_message: Cell::new(false),
relayout_event,
unminify_css,
userscripts_path,
user_content_manager,
player_context,
throttled: Cell::new(false),
layout_marker: DomRefCell::new(Rc::new(Cell::new(true))),