Privatize Window

This commit is contained in:
Tim Taubert 2014-10-13 00:06:48 +02:00
parent 8825296869
commit da7590d108
9 changed files with 57 additions and 25 deletions

View file

@ -83,7 +83,7 @@ impl<'a> GlobalRef<'a> {
/// thread. /// thread.
pub fn script_chan<'b>(&'b self) -> &'b ScriptChan { pub fn script_chan<'b>(&'b self) -> &'b ScriptChan {
match *self { match *self {
Window(ref window) => &window.script_chan, Window(ref window) => window.script_chan(),
Worker(ref worker) => worker.script_chan(), Worker(ref worker) => worker.script_chan(),
} }
} }

View file

@ -660,7 +660,7 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut
IDLInterface::get_prototype_depth(None::<window::Window>)) IDLInterface::get_prototype_depth(None::<window::Window>))
.unwrap() .unwrap()
.root(); .root();
win.browser_context.borrow().as_ref().unwrap().window_proxy() win.browser_context().as_ref().unwrap().window_proxy()
} }
} }

View file

@ -218,8 +218,8 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
} }
// This is wrong. https://html.spec.whatwg.org/multipage/forms.html#planned-navigation // This is wrong. https://html.spec.whatwg.org/multipage/forms.html#planned-navigation
let ScriptChan(ref script_chan) = win.script_chan; let ScriptChan(ref script_chan) = *win.script_chan();
script_chan.send(TriggerLoadMsg(win.page.id, load_data)); script_chan.send(TriggerLoadMsg(win.page().id, load_data));
} }
fn get_form_dataset(self, _submitter: Option<FormSubmitter>) -> Vec<FormDatum> { fn get_form_dataset(self, _submitter: Option<FormSubmitter>) -> Vec<FormDatum> {

View file

@ -171,7 +171,7 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {
fn GetContentWindow(self) -> Option<Temporary<Window>> { fn GetContentWindow(self) -> Option<Temporary<Window>> {
self.size.get().and_then(|size| { self.size.get().and_then(|size| {
let window = window_from_node(self).root(); let window = window_from_node(self).root();
let children = window.page.children.borrow(); let children = window.page().children.borrow();
let child = children.iter().find(|child| { let child = children.iter().find(|child| {
child.subpage_id.unwrap() == size.subpage_id child.subpage_id.unwrap() == size.subpage_id
}); });

View file

@ -49,7 +49,7 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> {
let node: JSRef<Node> = NodeCast::from_ref(self); let node: JSRef<Node> = NodeCast::from_ref(self);
let document = node.owner_doc().root(); let document = node.owner_doc().root();
let window = document.window().root(); let window = document.window().root();
let image_cache = &window.image_cache_task; let image_cache = window.image_cache_task();
match value { match value {
None => { None => {
*self.image.borrow_mut() = None; *self.image.borrow_mut() = None;

View file

@ -109,7 +109,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
if "data" == name.as_slice() { if "data" == name.as_slice() {
let window = window_from_node(*self).root(); let window = window_from_node(*self).root();
self.process_data_url(window.image_cache_task.clone()); self.process_data_url(window.image_cache_task().clone());
} }
} }
} }

View file

@ -30,8 +30,8 @@ impl PerformanceTiming {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: JSRef<Window>) -> Temporary<PerformanceTiming> { pub fn new(window: JSRef<Window>) -> Temporary<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(window.navigationStart, let timing = PerformanceTiming::new_inherited(window.navigation_start(),
window.navigationStartPrecise); window.navigation_start_precise());
reflect_dom_object(box timing, &global::Window(window), reflect_dom_object(box timing, &global::Window(window),
PerformanceTimingBinding::Wrap) PerformanceTimingBinding::Wrap)
} }

View file

@ -40,7 +40,7 @@ use url::{Url, UrlParser};
use libc; use libc;
use serialize::base64::{FromBase64, ToBase64, STANDARD}; use serialize::base64::{FromBase64, ToBase64, STANDARD};
use std::collections::hashmap::HashMap; use std::collections::hashmap::HashMap;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, Ref, RefCell};
use std::cmp; use std::cmp;
use std::comm::{channel, Sender}; use std::comm::{channel, Sender};
use std::comm::Select; use std::comm::Select;
@ -57,9 +57,10 @@ use time;
pub struct TimerId(i32); pub struct TimerId(i32);
#[jstraceable] #[jstraceable]
#[privatize]
pub struct TimerHandle { pub struct TimerHandle {
handle: TimerId, handle: TimerId,
pub data: TimerData, data: TimerData,
cancel_chan: Option<Sender<()>>, cancel_chan: Option<Sender<()>>,
} }
@ -78,22 +79,23 @@ impl TimerHandle {
#[jstraceable] #[jstraceable]
#[must_root] #[must_root]
#[privatize]
pub struct Window { pub struct Window {
eventtarget: EventTarget, eventtarget: EventTarget,
pub script_chan: ScriptChan, script_chan: ScriptChan,
pub control_chan: ScriptControlChan, control_chan: ScriptControlChan,
console: MutNullableJS<Console>, console: MutNullableJS<Console>,
location: MutNullableJS<Location>, location: MutNullableJS<Location>,
navigator: MutNullableJS<Navigator>, navigator: MutNullableJS<Navigator>,
pub image_cache_task: ImageCacheTask, image_cache_task: ImageCacheTask,
pub active_timers: RefCell<HashMap<TimerId, TimerHandle>>, active_timers: RefCell<HashMap<TimerId, TimerHandle>>,
next_timer_handle: Cell<i32>, next_timer_handle: Cell<i32>,
pub compositor: Box<ScriptListener+'static>, compositor: Box<ScriptListener+'static>,
pub browser_context: RefCell<Option<BrowserContext>>, browser_context: RefCell<Option<BrowserContext>>,
pub page: Rc<Page>, page: Rc<Page>,
performance: MutNullableJS<Performance>, performance: MutNullableJS<Performance>,
pub navigationStart: u64, navigation_start: u64,
pub navigationStartPrecise: f64, navigation_start_precise: f64,
screen: MutNullableJS<Screen>, screen: MutNullableJS<Screen>,
} }
@ -103,9 +105,38 @@ impl Window {
(*js_info.as_ref().unwrap().js_context).ptr (*js_info.as_ref().unwrap().js_context).ptr
} }
pub fn script_chan<'a>(&'a self) -> &'a ScriptChan {
&self.script_chan
}
pub fn control_chan<'a>(&'a self) -> &'a ScriptControlChan {
&self.control_chan
}
pub fn image_cache_task<'a>(&'a self) -> &'a ImageCacheTask {
&self.image_cache_task
}
pub fn compositor<'a>(&'a self) -> &'a ScriptListener+'static {
&*self.compositor
}
pub fn browser_context(&self) -> Ref<Option<BrowserContext>> {
self.browser_context.borrow()
}
pub fn page<'a>(&'a self) -> &'a Page { pub fn page<'a>(&'a self) -> &'a Page {
&*self.page &*self.page
} }
pub fn navigation_start(&self) -> u64 {
self.navigation_start
}
pub fn navigation_start_precise(&self) -> f64 {
self.navigation_start_precise
}
pub fn get_url(&self) -> Url { pub fn get_url(&self) -> Url {
self.page().get_url() self.page().get_url()
} }
@ -124,9 +155,10 @@ impl Drop for Window {
// (ie. function value to invoke and all arguments to pass // (ie. function value to invoke and all arguments to pass
// to the function when calling it) // to the function when calling it)
#[jstraceable] #[jstraceable]
#[privatize]
pub struct TimerData { pub struct TimerData {
pub is_interval: bool, is_interval: bool,
pub funval: JSVal, funval: JSVal,
} }
// http://www.whatwg.org/html/#atob // http://www.whatwg.org/html/#atob
@ -543,8 +575,8 @@ impl Window {
next_timer_handle: Cell::new(0), next_timer_handle: Cell::new(0),
browser_context: RefCell::new(None), browser_context: RefCell::new(None),
performance: Default::default(), performance: Default::default(),
navigationStart: time::get_time().sec as u64, navigation_start: time::get_time().sec as u64,
navigationStartPrecise: time::precise_time_s(), navigation_start_precise: time::precise_time_s(),
screen: Default::default(), screen: Default::default(),
}; };

View file

@ -167,7 +167,7 @@ impl Page {
if self.damaged.get() { if self.damaged.get() {
let frame = self.frame(); let frame = self.frame();
let window = frame.as_ref().unwrap().window.root(); let window = frame.as_ref().unwrap().window.root();
self.reflow(goal, window.control_chan.clone(), &*window.compositor); self.reflow(goal, window.control_chan().clone(), window.compositor());
} else { } else {
self.avoided_reflows.set(self.avoided_reflows.get() + 1); self.avoided_reflows.set(self.avoided_reflows.get() + 1);
} }