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;
|
2014-12-10 19:40:03 +03:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
pub struct ServoCefFrame {
|
|
|
|
pub title_visitor: RefCell<Option<CefStringVisitor>>,
|
|
|
|
pub url: RefCell<String>,
|
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 {
|
|
|
|
title_visitor: RefCell::new(None),
|
|
|
|
url: RefCell::new(String::new()),
|
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();
|
|
|
|
let event = WindowEvent::LoadUrl(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 {{
|
2014-12-10 19:40:03 +03:00
|
|
|
let this = this.downcast();
|
2015-03-18 20:25:00 +03:00
|
|
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
|
|
|
let url = this.url.borrow();
|
|
|
|
(*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();
|
|
|
|
*this.title_visitor.borrow_mut() = Some(visitor);
|
2015-01-13 22:27:48 +03:00
|
|
|
this.browser.borrow().as_ref().unwrap().get_title_for_main_frame();
|
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 set_url(&self, url: &[u16]);
|
|
|
|
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 set_url(&self, url: &[u16]) {
|
|
|
|
let frame = self.downcast();
|
|
|
|
*frame.url.borrow_mut() = String::from_utf16(url).unwrap();
|
|
|
|
}
|
|
|
|
fn load(&self) {
|
|
|
|
let event = WindowEvent::LoadUrl(self.downcast().url.borrow().clone());
|
|
|
|
self.downcast().browser.borrow_mut().as_mut().unwrap().send_window_event(event);
|
|
|
|
}
|
2015-01-28 04:15:50 +03:00
|
|
|
}
|