diff options
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r-- | components/script/dom/window.rs | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 9401eae5a46..ebd9550d117 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -28,7 +28,10 @@ use dom::crypto::Crypto; use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration}; use dom::document::Document; use dom::element::Element; +use dom::event::Event; use dom::eventtarget::EventTarget; +use dom::history::History; +use dom::htmliframeelement::build_mozbrowser_custom_event; use dom::location::Location; use dom::navigator::Navigator; use dom::node::{Node, from_untrusted_node_address, window_from_node}; @@ -43,11 +46,11 @@ use js::jsapi::{JS_GetRuntime, JS_GC, MutableHandleValue, SetWindowProxy}; use js::rust::CompileOptionsWrapper; use js::rust::Runtime; use libc; -use msg::constellation_msg::{FrameType, LoadData, PanicMsg, PipelineId, SubpageId, WindowSizeType}; +use msg::constellation_msg::{FrameType, LoadData, PipelineId, SubpageId, WindowSizeType}; +use net_traits::ResourceThreads; use net_traits::bluetooth_thread::BluetoothMethodMsg; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread}; use net_traits::storage_thread::StorageType; -use net_traits::{ResourceThreads, CustomResponseSender}; use num_traits::ToPrimitive; use open; use profile_traits::mem; @@ -63,7 +66,7 @@ use script_runtime::{ScriptChan, ScriptPort, maybe_take_panic_result}; use script_thread::SendableMainThreadScriptChan; use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper}; use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; -use script_traits::{ConstellationControlMsg, UntrustedNodeAddress}; +use script_traits::{ConstellationControlMsg, MozBrowserEvent, UntrustedNodeAddress}; use script_traits::{DocumentState, MsDuration, TimerEvent, TimerEventId}; use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource, WindowSizeData}; use std::ascii::AsciiExt; @@ -92,7 +95,7 @@ use task_source::networking::NetworkingTaskSource; use task_source::user_interaction::UserInteractionTaskSource; use time; use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle, OneshotTimers, TimerCallback}; -#[cfg(any(target_os = "macos", target_os = "linux"))] +#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] use tinyfiledialogs::{self, MessageBoxIcon}; use url::Url; use util::geometry::{self, MAX_RECT}; @@ -155,9 +158,8 @@ pub struct Window { image_cache_thread: ImageCacheThread, #[ignore_heap_size_of = "channels are hard"] image_cache_chan: ImageCacheChan, - #[ignore_heap_size_of = "channels are hard"] - custom_message_chan: IpcSender<CustomResponseSender>, browsing_context: MutNullableHeap<JS<BrowsingContext>>, + history: MutNullableHeap<JS<History>>, performance: MutNullableHeap<JS<Performance>>, navigation_start: u64, navigation_start_precise: f64, @@ -266,9 +268,6 @@ pub struct Window { /// A list of scroll offsets for each scrollable element. scroll_offsets: DOMRefCell<HashMap<UntrustedNodeAddress, Point2D<f32>>>, - - #[ignore_heap_size_of = "Defined in ipc-channel"] - panic_chan: IpcSender<PanicMsg>, } impl Window { @@ -302,7 +301,7 @@ impl Window { self.history_traversal_task_source.clone() } - pub fn file_reading_task_source(&self) -> Box<ScriptChan + Send> { + pub fn file_reading_task_source(&self) -> FileReadingTaskSource { self.file_reading_task_source.clone() } @@ -314,10 +313,6 @@ impl Window { self.image_cache_chan.clone() } - pub fn custom_message_chan(&self) -> IpcSender<CustomResponseSender> { - self.custom_message_chan.clone() - } - pub fn get_next_worker_id(&self) -> WorkerId { let worker_id = self.next_worker_id.get(); let WorkerId(id_num) = worker_id; @@ -366,14 +361,14 @@ impl Window { } } -#[cfg(any(target_os = "macos", target_os = "linux"))] +#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] fn display_alert_dialog(message: &str) { tinyfiledialogs::message_box_ok("Alert!", message, MessageBoxIcon::Warning); } -#[cfg(not(any(target_os = "macos", target_os = "linux")))] +#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] fn display_alert_dialog(_message: &str) { - // tinyfiledialogs not supported on Windows + // tinyfiledialogs not supported on Android } // https://html.spec.whatwg.org/multipage/#atob @@ -455,13 +450,15 @@ impl WindowMethods for Window { // Right now, just print to the console // Ensure that stderr doesn't trample through the alert() we use to // communicate test results (see executorservo.py in wptrunner). - let stderr = stderr(); - let mut stderr = stderr.lock(); - let stdout = stdout(); - let mut stdout = stdout.lock(); - writeln!(&mut stdout, "ALERT: {}", s).unwrap(); - stdout.flush().unwrap(); - stderr.flush().unwrap(); + { + let stderr = stderr(); + let mut stderr = stderr.lock(); + let stdout = stdout(); + let mut stdout = stdout.lock(); + writeln!(&mut stdout, "ALERT: {}", s).unwrap(); + stdout.flush().unwrap(); + stderr.flush().unwrap(); + } let (sender, receiver) = ipc::channel().unwrap(); self.constellation_chan().send(ConstellationMsg::Alert(self.pipeline(), s.to_string(), sender)).unwrap(); @@ -482,6 +479,11 @@ impl WindowMethods for Window { self.browsing_context().active_document() } + // https://html.spec.whatwg.org/multipage/#dom-history + fn History(&self) -> Root<History> { + self.history.or_init(|| History::new(self)) + } + // https://html.spec.whatwg.org/multipage/#dom-location fn Location(&self) -> Root<Location> { self.Document().GetLocation().unwrap() @@ -1034,6 +1036,12 @@ impl Window { recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) } + /// Advances the layout animation clock by `delta` milliseconds, and then + /// forces a reflow. + pub fn advance_animation_clock(&self, delta: i32) { + self.layout_chan.send(Msg::AdvanceClockMs(delta)).unwrap(); + } + /// Reflows the page unconditionally if possible and not suppressed. This /// method will wait for the layout thread to complete (but see the `TODO` /// below). If there is no window size yet, the page is presumed invisible @@ -1422,10 +1430,6 @@ impl Window { &self.scheduler_chan } - pub fn panic_chan(&self) -> &IpcSender<PanicMsg> { - &self.panic_chan - } - pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle { self.timers.schedule_callback(callback, duration, @@ -1594,6 +1598,13 @@ impl Window { _ => false, } } + + #[allow(unsafe_code)] + pub fn dispatch_mozbrowser_event(&self, event: MozBrowserEvent) { + assert!(PREFS.is_mozbrowser_enabled()); + let custom_event = build_mozbrowser_custom_event(&self, event); + custom_event.upcast::<Event>().fire(self.upcast()); + } } impl Window { @@ -1605,7 +1616,6 @@ impl Window { history_task_source: HistoryTraversalTaskSource, file_task_source: FileReadingTaskSource, image_cache_chan: ImageCacheChan, - custom_message_chan: IpcSender<CustomResponseSender>, image_cache_thread: ImageCacheThread, resource_threads: ResourceThreads, bluetooth_thread: IpcSender<BluetoothMethodMsg>, @@ -1615,7 +1625,6 @@ impl Window { constellation_chan: IpcSender<ConstellationMsg>, control_chan: IpcSender<ConstellationControlMsg>, scheduler_chan: IpcSender<TimerEventRequest>, - panic_chan: IpcSender<PanicMsg>, timer_event_chan: IpcSender<TimerEvent>, layout_chan: Sender<Msg>, id: PipelineId, @@ -1641,7 +1650,6 @@ impl Window { history_traversal_task_source: history_task_source, file_reading_task_source: file_task_source, image_cache_chan: image_cache_chan, - custom_message_chan: custom_message_chan, console: Default::default(), crypto: Default::default(), navigator: Default::default(), @@ -1649,6 +1657,7 @@ impl Window { mem_profiler_chan: mem_profiler_chan, time_profiler_chan: time_profiler_chan, devtools_chan: devtools_chan, + history: Default::default(), browsing_context: Default::default(), performance: Default::default(), navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64, @@ -1686,7 +1695,6 @@ impl Window { ignore_further_async_events: Arc::new(AtomicBool::new(false)), error_reporter: error_reporter, scroll_offsets: DOMRefCell::new(HashMap::new()), - panic_chan: panic_chan, }; WindowBinding::Wrap(runtime.cx(), win) |