@@ -5,7 +5,8 @@ use crate::net::{Resource, StylesheetLoader};
55use crate :: node:: { ImageData , NodeFlags , RasterImageData , SpecialElementData , Status , TextBrush } ;
66use crate :: stylo_to_cursor_icon:: stylo_to_cursor_icon;
77use crate :: traversal:: TreeTraverser ;
8- use crate :: util:: { ImageType , resolve_url} ;
8+ use crate :: url:: DocumentUrl ;
9+ use crate :: util:: ImageType ;
910use crate :: {
1011 DEFAULT_CSS , DocumentConfig , DocumentMutator , ElementData , Node , NodeData , TextNodeData ,
1112} ;
@@ -24,6 +25,7 @@ use slab::Slab;
2425use std:: any:: Any ;
2526use std:: collections:: { BTreeMap , Bound , HashMap , HashSet } ;
2627use std:: ops:: { Deref , DerefMut } ;
28+ use std:: str:: FromStr ;
2729use std:: sync:: Arc ;
2830use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
2931use style:: Atom ;
@@ -43,7 +45,7 @@ use style::{
4345 media_queries:: { Device , MediaList } ,
4446 selector_parser:: SnapshotMap ,
4547 shared_lock:: { SharedRwLock , StylesheetGuards } ,
46- stylesheets:: { AllowImportRules , DocumentStyleSheet , Origin , Stylesheet , UrlExtraData } ,
48+ stylesheets:: { AllowImportRules , DocumentStyleSheet , Origin , Stylesheet } ,
4749 stylist:: Stylist ,
4850} ;
4951use taffy:: AvailableSpace ;
@@ -98,7 +100,7 @@ pub struct BaseDocument {
98100
99101 // Config
100102 /// Base url for resolving linked resources (stylesheets, images, fonts, etc)
101- pub ( crate ) base_url : Option < url:: Url > ,
103+ pub ( crate ) url : DocumentUrl ,
102104 // Devtool settings. Currently used to render debug overlays
103105 pub ( crate ) devtool_settings : DevtoolSettings ,
104106 // Viewport details such as the dimensions, HiDPI scale, and zoom factor,
@@ -208,6 +210,11 @@ impl BaseDocument {
208210 style_config:: set_bool ( "layout.unimplemented" , true ) ;
209211 style_config:: set_bool ( "layout.columns.enabled" , true ) ;
210212
213+ let base_url = config
214+ . base_url
215+ . and_then ( |url| DocumentUrl :: from_str ( & url) . ok ( ) )
216+ . unwrap_or_default ( ) ;
217+
211218 let font_ctx = config. font_ctx . unwrap_or_else ( || {
212219 let mut font_ctx = FontContext :: default ( ) ;
213220 font_ctx
@@ -236,7 +243,7 @@ impl BaseDocument {
236243 viewport,
237244 devtool_settings : DevtoolSettings :: default ( ) ,
238245 viewport_scroll : kurbo:: Point :: ZERO ,
239- base_url : None ,
246+ url : base_url ,
240247 ua_stylesheets : HashMap :: new ( ) ,
241248 nodes_to_stylesheet : BTreeMap :: new ( ) ,
242249 font_ctx,
@@ -300,7 +307,7 @@ impl BaseDocument {
300307
301308 /// Set base url for resolving linked resources (stylesheets, images, fonts, etc)
302309 pub fn set_base_url ( & mut self , url : & str ) {
303- self . base_url = Some ( Url :: parse ( url) . unwrap ( ) ) ;
310+ self . url = DocumentUrl :: from ( Url :: parse ( url) . unwrap ( ) ) ;
304311 }
305312
306313 pub fn guard ( & self ) -> & SharedRwLock {
@@ -483,11 +490,11 @@ impl BaseDocument {
483490 node
484491 }
485492
486- pub fn resolve_url ( & self , raw : & str ) -> url:: Url {
487- resolve_url ( & self . base_url , raw) . unwrap_or_else ( || {
493+ pub ( crate ) fn resolve_url ( & self , raw : & str ) -> url:: Url {
494+ self . url . resolve_relative ( raw) . unwrap_or_else ( || {
488495 panic ! (
489- "to be able to resolve {raw} with the base_url: {base_url :?}" ,
490- base_url = self . base_url
496+ "to be able to resolve {raw} with the base_url: {:?}" ,
497+ * self . url
491498 )
492499 } )
493500 }
@@ -522,11 +529,7 @@ impl BaseDocument {
522529 pub fn make_stylesheet ( & self , css : impl AsRef < str > , origin : Origin ) -> DocumentStyleSheet {
523530 let data = Stylesheet :: from_str (
524531 css. as_ref ( ) ,
525- UrlExtraData :: from ( self . base_url . clone ( ) . unwrap_or_else ( || {
526- "data:text/css;charset=utf-8;base64,"
527- . parse :: < Url > ( )
528- . unwrap ( )
529- } ) ) ,
532+ self . url . url_extra_data ( ) ,
530533 origin,
531534 ServoArc :: new ( self . guard . wrap ( MediaList :: empty ( ) ) ) ,
532535 self . guard . clone ( ) ,
0 commit comments