mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Expand the Parser trait to allow anonymous CORS to be applied.
Depends on D5106 Differential Revision: https://phabricator.services.mozilla.com/D5341
This commit is contained in:
parent
b96d44e329
commit
6d57cbd881
3 changed files with 38 additions and 7 deletions
|
@ -201,6 +201,20 @@ impl SpecifiedImageUrl {
|
||||||
use gecko_bindings::structs::root::mozilla::CORSMode_CORS_NONE;
|
use gecko_bindings::structs::root::mozilla::CORSMode_CORS_NONE;
|
||||||
Self::from_css_url_with_cors(url, CORSMode_CORS_NONE)
|
Self::from_css_url_with_cors(url, CORSMode_CORS_NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_css_url_with_cors_anonymous(url: CssUrl) -> Self {
|
||||||
|
use gecko_bindings::structs::root::mozilla::CORSMode_CORS_ANONYMOUS;
|
||||||
|
Self::from_css_url_with_cors(url, CORSMode_CORS_ANONYMOUS)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provides an alternate method for parsing that associates the URL
|
||||||
|
/// with anonymous CORS headers.
|
||||||
|
pub fn parse_with_cors_anonymous<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
CssUrl::parse(context, input).map(Self::from_css_url_with_cors_anonymous)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for SpecifiedImageUrl {
|
impl Parse for SpecifiedImageUrl {
|
||||||
|
|
|
@ -71,7 +71,12 @@ impl Parse for ClippingShape {
|
||||||
return Ok(ShapeSource::Path(p));
|
return Ok(ShapeSource::Path(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::parse_internal(context, input)
|
|
||||||
|
if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
|
||||||
|
return Ok(ShapeSource::ImageOrUrl(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::parse_common(context, input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +86,11 @@ impl Parse for FloatAreaShape {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
Self::parse_internal(context, input)
|
if let Ok(image) = input.try(|i| Image::parse_with_cors_anonymous(context, i)) {
|
||||||
|
return Ok(ShapeSource::ImageOrUrl(image));
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::parse_common(context, input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +100,7 @@ where
|
||||||
ImageOrUrl: Parse,
|
ImageOrUrl: Parse,
|
||||||
{
|
{
|
||||||
/// The internal parser for ShapeSource.
|
/// The internal parser for ShapeSource.
|
||||||
fn parse_internal<'i, 't>(
|
fn parse_common<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
@ -99,10 +108,6 @@ where
|
||||||
return Ok(ShapeSource::None);
|
return Ok(ShapeSource::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(image_or_url) = input.try(|i| ImageOrUrl::parse(context, i)) {
|
|
||||||
return Ok(ShapeSource::ImageOrUrl(image_or_url));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_component<U: Parse>(
|
fn parse_component<U: Parse>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
|
|
|
@ -166,6 +166,18 @@ impl Image {
|
||||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides an alternate method for parsing that associates the URL
|
||||||
|
/// with anonymous CORS headers.
|
||||||
|
pub fn parse_with_cors_anonymous<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Image, ParseError<'i>> {
|
||||||
|
if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) {
|
||||||
|
return Ok(generic::Image::Url(url));
|
||||||
|
}
|
||||||
|
Self::parse(context, input)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Gradient {
|
impl Parse for Gradient {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue