mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
parent
05212b702d
commit
12f20f1ecc
10 changed files with 69 additions and 1 deletions
|
@ -454,6 +454,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
||||||
self.composite_if_necessary(CompositingReason::Headless);
|
self.composite_if_necessary(CompositingReason::Headless);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(Msg::NewFavicon(url), ShutdownState::NotShuttingDown) => {
|
||||||
|
self.window.set_favicon(url);
|
||||||
|
}
|
||||||
|
|
||||||
// When we are shutting_down, we need to avoid performing operations
|
// When we are shutting_down, we need to avoid performing operations
|
||||||
// such as Paint that may crash because we have begun tearing down
|
// such as Paint that may crash because we have begun tearing down
|
||||||
// the rest of our resources.
|
// the rest of our resources.
|
||||||
|
|
|
@ -180,6 +180,8 @@ pub enum Msg {
|
||||||
ViewportConstrained(PipelineId, ViewportConstraints),
|
ViewportConstrained(PipelineId, ViewportConstraints),
|
||||||
/// A reply to the compositor asking if the output image is stable.
|
/// A reply to the compositor asking if the output image is stable.
|
||||||
IsReadyToSaveImageReply(bool),
|
IsReadyToSaveImageReply(bool),
|
||||||
|
/// A favicon was detected
|
||||||
|
NewFavicon(Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Msg {
|
impl Debug for Msg {
|
||||||
|
@ -206,6 +208,7 @@ impl Debug for Msg {
|
||||||
Msg::PaintTaskExited(..) => write!(f, "PaintTaskExited"),
|
Msg::PaintTaskExited(..) => write!(f, "PaintTaskExited"),
|
||||||
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
|
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
|
||||||
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
|
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
|
||||||
|
Msg::NewFavicon(..) => write!(f, "NewFavicon"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,6 +468,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
||||||
debug!("constellation got remove iframe message");
|
debug!("constellation got remove iframe message");
|
||||||
self.handle_remove_iframe_msg(containing_pipeline_id, subpage_id);
|
self.handle_remove_iframe_msg(containing_pipeline_id, subpage_id);
|
||||||
}
|
}
|
||||||
|
ConstellationMsg::NewFavicon(url) => {
|
||||||
|
debug!("constellation got new favicon message");
|
||||||
|
self.compositor_proxy.send(CompositorMsg::NewFavicon(url));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ impl CompositorEventListener for NullCompositor {
|
||||||
Msg::CreatePng(..) |
|
Msg::CreatePng(..) |
|
||||||
Msg::PaintTaskExited(..) |
|
Msg::PaintTaskExited(..) |
|
||||||
Msg::IsReadyToSaveImageReply(..) => {}
|
Msg::IsReadyToSaveImageReply(..) => {}
|
||||||
|
Msg::NewFavicon(..) => {}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,4 +138,7 @@ pub trait WindowMethods {
|
||||||
|
|
||||||
/// Does this window support a clipboard
|
/// Does this window support a clipboard
|
||||||
fn supports_clipboard(&self) -> bool;
|
fn supports_clipboard(&self) -> bool;
|
||||||
|
|
||||||
|
/// Add a favicon
|
||||||
|
fn set_favicon(&self, url: Url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,8 @@ pub enum Msg {
|
||||||
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
|
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
|
||||||
/// Notification that this iframe should be removed.
|
/// Notification that this iframe should be removed.
|
||||||
RemoveIFrame(PipelineId, SubpageId),
|
RemoveIFrame(PipelineId, SubpageId),
|
||||||
|
/// Favicon detected
|
||||||
|
NewFavicon(Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
|
|
|
@ -25,6 +25,8 @@ use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use dom::window::WindowHelpers;
|
use dom::window::WindowHelpers;
|
||||||
use layout_interface::{LayoutChan, Msg};
|
use layout_interface::{LayoutChan, Msg};
|
||||||
|
use msg::constellation_msg::ConstellationChan;
|
||||||
|
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||||
use script_traits::StylesheetLoadResponder;
|
use script_traits::StylesheetLoadResponder;
|
||||||
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
|
@ -85,6 +87,19 @@ fn is_stylesheet(value: &Option<String>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Favicon spec usage in accordance with CEF implementation:
|
||||||
|
/// only url of icon is required/used
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#rel-icon
|
||||||
|
fn is_favicon(value: &Option<String>) -> bool {
|
||||||
|
match *value {
|
||||||
|
Some(ref value) => {
|
||||||
|
value.split(HTML_SPACE_CHARACTERS)
|
||||||
|
.any(|s| s.eq_ignore_ascii_case("icon"))
|
||||||
|
},
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
|
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
|
||||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
|
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
|
||||||
|
@ -105,7 +120,14 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
let rel = get_attr(element, &atom!("rel"));
|
let rel = get_attr(element, &atom!("rel"));
|
||||||
|
|
||||||
match (rel, attr.local_name()) {
|
match (rel, attr.local_name()) {
|
||||||
(ref rel, &atom!("href")) | (ref rel, &atom!("media")) => {
|
(ref rel, &atom!("href")) => {
|
||||||
|
if is_stylesheet(rel) {
|
||||||
|
self.handle_stylesheet_url(&attr.value());
|
||||||
|
} else if is_favicon(rel) {
|
||||||
|
self.handle_favicon_url(&attr.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ref rel, &atom!("media")) => {
|
||||||
if is_stylesheet(rel) {
|
if is_stylesheet(rel) {
|
||||||
self.handle_stylesheet_url(&attr.value());
|
self.handle_stylesheet_url(&attr.value());
|
||||||
}
|
}
|
||||||
|
@ -136,6 +158,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
(ref rel, Some(ref href)) if is_stylesheet(rel) => {
|
(ref rel, Some(ref href)) if is_stylesheet(rel) => {
|
||||||
self.handle_stylesheet_url(href);
|
self.handle_stylesheet_url(href);
|
||||||
}
|
}
|
||||||
|
(ref rel, Some(ref href)) if is_favicon(rel) => {
|
||||||
|
self.handle_favicon_url(href);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +169,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
|
|
||||||
trait PrivateHTMLLinkElementHelpers {
|
trait PrivateHTMLLinkElementHelpers {
|
||||||
fn handle_stylesheet_url(self, href: &str);
|
fn handle_stylesheet_url(self, href: &str);
|
||||||
|
fn handle_favicon_url(self, href: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> {
|
impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> {
|
||||||
|
@ -174,6 +200,19 @@ impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> {
|
||||||
Err(e) => debug!("Parsing url {} failed: {}", href, e)
|
Err(e) => debug!("Parsing url {} failed: {}", href, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_favicon_url(self, href: &str) {
|
||||||
|
let window = window_from_node(self).root();
|
||||||
|
let window = window.r();
|
||||||
|
match UrlParser::new().base_url(&window.get_url()).parse(href) {
|
||||||
|
Ok(url) => {
|
||||||
|
let ConstellationChan(ref chan) = window.constellation_chan();
|
||||||
|
let event = ConstellationMsg::NewFavicon(url.clone());
|
||||||
|
chan.send(event).unwrap();
|
||||||
|
}
|
||||||
|
Err(e) => debug!("Parsing url {} failed: {}", href, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> {
|
impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
|
|
|
@ -316,6 +316,9 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_favicon(&self, _: Url) {
|
||||||
|
}
|
||||||
|
|
||||||
fn load_start(&self, back: bool, forward: bool) {
|
fn load_start(&self, back: bool, forward: bool) {
|
||||||
// FIXME(pcwalton): The status code 200 is a lie.
|
// FIXME(pcwalton): The status code 200 is a lie.
|
||||||
let browser = self.cef_browser.borrow();
|
let browser = self.cef_browser.borrow();
|
||||||
|
|
|
@ -559,6 +559,9 @@ impl WindowMethods for Window {
|
||||||
self.window.set_cursor(glutin_cursor);
|
self.window.set_cursor(glutin_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_favicon(&self, _: Url) {
|
||||||
|
}
|
||||||
|
|
||||||
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -707,6 +710,9 @@ impl WindowMethods for Window {
|
||||||
fn set_cursor(&self, _: Cursor) {
|
fn set_cursor(&self, _: Cursor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_favicon(&self, _: Url) {
|
||||||
|
}
|
||||||
|
|
||||||
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,6 +838,9 @@ impl WindowMethods for Window {
|
||||||
fn set_cursor(&self, _: Cursor) {
|
fn set_cursor(&self, _: Cursor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_favicon(&self, _: Url) {
|
||||||
|
}
|
||||||
|
|
||||||
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue