Auto merge of #6219 - zmike:favicons_and_stringlOWWW-MY-HEAD, r=pcwalton

Getting these down to the embedding API level required that I redo the bindings generator again, so this is more commits than anticipated.

@mbrubeck @Manishearth @pcwalton but NOT @larsbergstrom so don't even look at this.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6219)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-06-03 00:27:41 -05:00
commit b0f3417cff
26 changed files with 182 additions and 62 deletions

View file

@ -454,6 +454,14 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.composite_if_necessary(CompositingReason::Headless);
}
(Msg::NewFavicon(url), ShutdownState::NotShuttingDown) => {
self.window.set_favicon(url);
}
(Msg::HeadParsed, ShutdownState::NotShuttingDown) => {
self.window.head_parsed();
}
// When we are shutting_down, we need to avoid performing operations
// such as Paint that may crash because we have begun tearing down
// the rest of our resources.

View file

@ -180,6 +180,10 @@ pub enum Msg {
ViewportConstrained(PipelineId, ViewportConstraints),
/// A reply to the compositor asking if the output image is stable.
IsReadyToSaveImageReply(bool),
/// A favicon was detected
NewFavicon(Url),
/// <head> tag finished parsing
HeadParsed,
}
impl Debug for Msg {
@ -206,6 +210,8 @@ impl Debug for Msg {
Msg::PaintTaskExited(..) => write!(f, "PaintTaskExited"),
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
Msg::NewFavicon(..) => write!(f, "NewFavicon"),
Msg::HeadParsed => write!(f, "HeadParsed"),
}
}
}

View file

@ -468,6 +468,14 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
debug!("constellation got remove iframe message");
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));
}
ConstellationMsg::HeadParsed => {
debug!("constellation got head parsed message");
self.compositor_proxy.send(CompositorMsg::HeadParsed);
}
}
true
}

View file

@ -109,6 +109,8 @@ impl CompositorEventListener for NullCompositor {
Msg::CreatePng(..) |
Msg::PaintTaskExited(..) |
Msg::IsReadyToSaveImageReply(..) => {}
Msg::NewFavicon(..) => {}
Msg::HeadParsed => {}
}
true
}

View file

@ -110,6 +110,8 @@ pub trait WindowMethods {
fn load_end(&self, back: bool, forward: bool);
/// Called when the browser encounters an error while loading a URL
fn load_error(&self, code: NetError, url: String);
/// Called when the <head> tag has finished parsing
fn head_parsed(&self);
/// Returns the hidpi factor of the monitor.
fn hidpi_factor(&self) -> ScaleFactor<ScreenPx, DevicePixel, f32>;
@ -138,4 +140,7 @@ pub trait WindowMethods {
/// Does this window support a clipboard
fn supports_clipboard(&self) -> bool;
/// Add a favicon
fn set_favicon(&self, url: Url);
}

View file

@ -248,6 +248,10 @@ pub enum Msg {
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
/// Notification that this iframe should be removed.
RemoveIFrame(PipelineId, SubpageId),
/// Favicon detected
NewFavicon(Url),
/// <head> tag finished parsing
HeadParsed,
}
#[derive(Clone, Eq, PartialEq)]

View file

@ -17,6 +17,8 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg;
use cssparser::RGBA;
use util::str::{self, DOMString};
@ -107,6 +109,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
let window = window_from_node(*self).root();
let document = window.r().Document().root();
document.r().set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY);
let ConstellationChan(ref chan) = window.r().constellation_chan();
let event = ConstellationMsg::HeadParsed;
chan.send(event).unwrap();
}
fn after_set_attr(&self, attr: JSRef<Attr>) {

View file

@ -25,6 +25,8 @@ use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use layout_interface::{LayoutChan, Msg};
use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg;
use script_traits::StylesheetLoadResponder;
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
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> {
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
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"));
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) {
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) => {
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 {
fn handle_stylesheet_url(self, href: &str);
fn handle_favicon_url(self, href: &str);
}
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)
}
}
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> {