gecko-dev/servo/ports/cef/frame.rs
Paul Rouget 633c2172a9 servo: Merge #17425 - cleanup embedder/compositor/constellation/script messages (from paulrouget:attach-pipeline-2); r=asajeffrey
Fix: #17226 #17200 #17201

This is work in progress. Some tests still fail.
I'd like to get early feedback as it's a pretty large PR.

There is nothing fundamentally new. Basically, I added TopLevelBrowsingContrextId to the relevant messages between the embedder, the compositor and the constellation, and enforced the PipelineId to be attached to each ScriptMsg (see #17201).

I unaliased all the ScriptMsg. It was getting difficult to understand the nature of the message as ScriptMsg was used aliased CompositorMsg sometimes (CompositorMsg is an actually type of message already). I renamed constellation_chan to script_to_constellation_chan, again, for clarification.

This cleanup code is necessary for #15934 and for tabs support.

/cc @asajeffrey can I ask you to look at this? No need for a formal review, I need feedback at this stage.

Source-Repo: https://github.com/servo/servo
Source-Revision: 74558990b258cb55f230ebe8ec3fc557fd286f94

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : e254fc37d5b07b98c035873e2269f89acb3fafa0
2017-08-15 02:20:10 -05:00

73 lines
2.6 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use browser::ServoCefBrowserExtensions;
use eutil::Downcast;
use interfaces::{CefBrowser, CefFrame, CefStringVisitor, cef_frame_t, cef_string_visitor_t};
use types::{cef_string_t, cef_string_userfree_t};
use compositing::windowing::WindowEvent;
use servo::servo_url::ServoUrl;
use std::cell::RefCell;
pub struct ServoCefFrame {
pub url: RefCell<String>,
pub title: RefCell<Vec<u16>>,
/// A reference to the browser.
pub browser: RefCell<Option<CefBrowser>>,
}
impl ServoCefFrame {
pub fn new() -> ServoCefFrame {
ServoCefFrame {
url: RefCell::new(String::new()),
title: RefCell::new(vec![]),
browser: RefCell::new(None),
}
}
}
full_cef_class_impl! {
ServoCefFrame : CefFrame, cef_frame_t {
fn load_url(&this, url: *const cef_string_t [&[u16]],) -> () {{
let this = this.downcast();
let url = String::from_utf16(url).unwrap();
*this.url.borrow_mut() = url.clone();
let id = this.browser.borrow().as_ref().unwrap().get_browser_id();
let url = ServoUrl::parse(&url).or(ServoUrl::parse("about:blank")).unwrap();
let event = WindowEvent::LoadUrl(id, url);
this.browser.borrow_mut().as_mut().unwrap().send_window_event(event);
}}
fn get_url(&this,) -> cef_string_userfree_t {{
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let url = this.downcast().url.borrow();
(*url).clone()
}}
fn get_text(&this, visitor: *mut cef_string_visitor_t [CefStringVisitor],) -> () {{
let this = this.downcast();
let str = &*this.title.borrow();
visitor.visit(str)
}}
}
}
pub trait ServoCefFrameExtensions {
fn set_browser(&self, browser: CefBrowser);
fn load(&self);
}
impl ServoCefFrameExtensions for CefFrame {
fn set_browser(&self, browser: CefBrowser) {
*self.downcast().browser.borrow_mut() = Some(browser)
}
fn load(&self) {
let id = self.downcast().browser.borrow().as_ref().unwrap().get_browser_id();
let url = self.downcast().url.borrow();
let url = ServoUrl::parse(&*url).or(ServoUrl::parse("about:blank")).unwrap();
let event = WindowEvent::LoadUrl(id, url);
self.downcast().browser.borrow_mut().as_mut().unwrap().send_window_event(event);
}
}