auto merge of #4657 : glennw/servo/cef-close, r=larsbergstrom

This commit is contained in:
bors-servo 2015-01-19 07:57:47 -07:00
commit f3dfe04fa4
2 changed files with 20 additions and 3 deletions

View file

@ -17,7 +17,9 @@ use glfw_app;
use libc::c_int; use libc::c_int;
use servo_util::opts; use servo_util::opts;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::sync::atomic::{AtomicInt, SeqCst};
thread_local!(pub static ID_COUNTER: AtomicInt = AtomicInt::new(0))
thread_local!(pub static BROWSERS: RefCell<Vec<CefBrowser>> = RefCell::new(vec!())) thread_local!(pub static BROWSERS: RefCell<Vec<CefBrowser>> = RefCell::new(vec!()))
pub enum ServoBrowser { pub enum ServoBrowser {
@ -83,6 +85,7 @@ pub struct ServoCefBrowser {
/// Whether the on-created callback has fired yet. /// Whether the on-created callback has fired yet.
pub callback_executed: Cell<bool>, pub callback_executed: Cell<bool>,
id: int,
servo_browser: RefCell<ServoBrowser>, servo_browser: RefCell<ServoBrowser>,
message_queue: RefCell<Vec<WindowEvent>>, message_queue: RefCell<Vec<WindowEvent>>,
} }
@ -100,6 +103,10 @@ impl ServoCefBrowser {
ServoBrowser::Invalid ServoBrowser::Invalid
}; };
let id = ID_COUNTER.with(|counter| {
counter.fetch_add(1, SeqCst)
});
ServoCefBrowser { ServoCefBrowser {
frame: frame, frame: frame,
host: host, host: host,
@ -107,6 +114,7 @@ impl ServoCefBrowser {
callback_executed: Cell::new(false), callback_executed: Cell::new(false),
servo_browser: RefCell::new(servo_browser), servo_browser: RefCell::new(servo_browser),
message_queue: RefCell::new(vec!()), message_queue: RefCell::new(vec!()),
id: id,
} }
} }
} }
@ -170,6 +178,15 @@ pub fn update() {
}); });
} }
pub fn close(browser: CefBrowser) {
BROWSERS.with(|browsers| {
let mut browsers = browsers.borrow_mut();
browsers.iter()
.position(|&ref n| n.downcast().id == browser.downcast().id)
.map(|e| browsers.remove(e));
});
}
pub fn browser_callback_after_created(browser: CefBrowser) { pub fn browser_callback_after_created(browser: CefBrowser) {
if browser.downcast().client.is_null_cef_object() { if browser.downcast().client.is_null_cef_object() {
return return

View file

@ -6,7 +6,7 @@ use eutil::Downcast;
use interfaces::{CefBrowser, CefBrowserHost, CefClient, cef_browser_host_t, cef_client_t}; use interfaces::{CefBrowser, CefBrowserHost, CefClient, cef_browser_host_t, cef_client_t};
use types::{cef_mouse_button_type_t, cef_mouse_event, cef_rect_t, cef_key_event}; use types::{cef_mouse_button_type_t, cef_mouse_event, cef_rect_t, cef_key_event};
use types::cef_key_event_type_t::{KEYEVENT_CHAR, KEYEVENT_KEYDOWN, KEYEVENT_KEYUP, KEYEVENT_RAWKEYDOWN}; use types::cef_key_event_type_t::{KEYEVENT_CHAR, KEYEVENT_KEYDOWN, KEYEVENT_KEYUP, KEYEVENT_RAWKEYDOWN};
use browser::ServoCefBrowserExtensions; use browser::{mod, ServoCefBrowserExtensions};
use compositing::windowing::{WindowEvent, MouseWindowEvent}; use compositing::windowing::{WindowEvent, MouseWindowEvent};
use geom::point::TypedPoint2D; use geom::point::TypedPoint2D;
@ -37,8 +37,8 @@ cef_class_impl! {
this.downcast().send_window_event(WindowEvent::Resize(size)); this.downcast().send_window_event(WindowEvent::Resize(size));
} }
fn close_browser(&_this, _force: c_int) -> () { fn close_browser(&this, _force: c_int) -> () {
// TODO: Clean shutdown. browser::close(this.downcast().browser.borrow_mut().take().unwrap());
} }
fn send_focus_event(&this, focus: c_int) -> () { fn send_focus_event(&this, focus: c_int) -> () {