2014-12-10 19:40:03 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2015-08-20 16:43:56 +03:00
|
|
|
use browser::ServoCefBrowserExtensions;
|
2014-12-10 19:40:03 +03:00
|
|
|
use eutil::Downcast;
|
2015-01-13 22:27:48 +03:00
|
|
|
use interfaces::{CefBrowser, CefFrame, CefStringVisitor, cef_frame_t, cef_string_visitor_t};
|
2014-12-10 19:40:03 +03:00
|
|
|
use types::{cef_string_t, cef_string_userfree_t};
|
|
|
|
|
2014-12-18 04:45:49 +03:00
|
|
|
use compositing::windowing::WindowEvent;
|
2017-08-15 10:20:10 +03:00
|
|
|
use servo::servo_url::ServoUrl;
|
2014-12-10 19:40:03 +03:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
pub struct ServoCefFrame {
|
|
|
|
pub url: RefCell<String>,
|
2017-07-12 19:50:45 +03:00
|
|
|
pub title: RefCell<Vec<u16>>,
|
2015-01-13 22:27:48 +03:00
|
|
|
|
|
|
|
/// A reference to the browser.
|
|
|
|
pub browser: RefCell<Option<CefBrowser>>,
|
2014-12-10 19:40:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ServoCefFrame {
|
|
|
|
pub fn new() -> ServoCefFrame {
|
|
|
|
ServoCefFrame {
|
|
|
|
url: RefCell::new(String::new()),
|
2017-07-12 19:50:45 +03:00
|
|
|
title: RefCell::new(vec![]),
|
2015-01-13 22:27:48 +03:00
|
|
|
browser: RefCell::new(None),
|
2014-12-10 19:40:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
full_cef_class_impl! {
|
2014-12-10 19:40:03 +03:00
|
|
|
ServoCefFrame : CefFrame, cef_frame_t {
|
2015-01-28 04:15:50 +03:00
|
|
|
fn load_url(&this, url: *const cef_string_t [&[u16]],) -> () {{
|
2014-12-10 19:40:03 +03:00
|
|
|
let this = this.downcast();
|
2015-01-28 04:15:50 +03:00
|
|
|
let url = String::from_utf16(url).unwrap();
|
|
|
|
*this.url.borrow_mut() = url.clone();
|
2017-08-15 10:20:10 +03:00
|
|
|
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);
|
2015-01-13 22:27:48 +03:00
|
|
|
this.browser.borrow_mut().as_mut().unwrap().send_window_event(event);
|
2015-01-28 04:15:50 +03:00
|
|
|
}}
|
|
|
|
fn get_url(&this,) -> cef_string_userfree_t {{
|
2015-03-18 20:25:00 +03:00
|
|
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
2015-11-06 23:01:40 +03:00
|
|
|
let url = this.downcast().url.borrow();
|
2015-03-18 20:25:00 +03:00
|
|
|
(*url).clone()
|
2015-01-28 04:15:50 +03:00
|
|
|
}}
|
|
|
|
fn get_text(&this, visitor: *mut cef_string_visitor_t [CefStringVisitor],) -> () {{
|
2014-12-10 19:40:03 +03:00
|
|
|
let this = this.downcast();
|
2017-07-12 19:50:45 +03:00
|
|
|
let str = &*this.title.borrow();
|
|
|
|
visitor.visit(str)
|
2015-01-28 04:15:50 +03:00
|
|
|
}}
|
2014-12-10 19:40:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 22:27:48 +03:00
|
|
|
pub trait ServoCefFrameExtensions {
|
|
|
|
fn set_browser(&self, browser: CefBrowser);
|
2015-05-27 22:17:32 +03:00
|
|
|
fn load(&self);
|
2015-01-13 22:27:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ServoCefFrameExtensions for CefFrame {
|
|
|
|
fn set_browser(&self, browser: CefBrowser) {
|
|
|
|
*self.downcast().browser.borrow_mut() = Some(browser)
|
|
|
|
}
|
2015-05-27 22:17:32 +03:00
|
|
|
fn load(&self) {
|
2017-08-15 10:20:10 +03:00
|
|
|
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);
|
2015-05-27 22:17:32 +03:00
|
|
|
self.downcast().browser.borrow_mut().as_mut().unwrap().send_window_event(event);
|
|
|
|
}
|
2015-01-28 04:15:50 +03:00
|
|
|
}
|