aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/window.rs')
-rw-r--r--src/components/script/dom/window.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs
index 0e553ac54fa..e8d4a121dcd 100644
--- a/src/components/script/dom/window.rs
+++ b/src/components/script/dom/window.rs
@@ -16,11 +16,12 @@ use dom::navigator::Navigator;
use dom::performance::Performance;
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
-use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
+use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
use servo_msg::compositor_msg::ScriptListener;
use servo_net::image_cache_task::ImageCacheTask;
use servo_util::str::DOMString;
use servo_util::task::{spawn_named};
+use servo_util::url::parse_url;
use js::jsapi::JSContext;
use js::jsapi::{JS_GC, JS_GetRuntime};
@@ -70,9 +71,9 @@ pub struct Window {
pub location: Option<JS<Location>>,
pub navigator: Option<JS<Navigator>>,
pub image_cache_task: ImageCacheTask,
- pub active_timers: HashMap<TimerId, TimerHandle>,
+ pub active_timers: Box<HashMap<TimerId, TimerHandle>>,
pub next_timer_handle: i32,
- pub compositor: Untraceable<~ScriptListener>,
+ pub compositor: Untraceable<Box<ScriptListener>>,
pub browser_context: Option<BrowserContext>,
pub page: Rc<Page>,
pub performance: Option<JS<Performance>>,
@@ -292,6 +293,7 @@ pub trait WindowHelpers {
fn damage_and_reflow(&self, damage: DocumentDamageLevel);
fn wait_until_safe_to_modify_dom(&self);
fn init_browser_context(&mut self, doc: &JSRef<Document>);
+ fn load_url(&self, href: DOMString);
}
trait PrivateWindowHelpers {
@@ -316,6 +318,19 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
fn init_browser_context(&mut self, doc: &JSRef<Document>) {
self.browser_context = Some(BrowserContext::new(doc));
}
+
+ /// Commence a new URL load which will either replace this window or scroll to a fragment.
+ fn load_url(&self, href: DOMString) {
+ let base_url = Some(self.page().get_url());
+ debug!("current page url is {:?}", base_url);
+ let url = parse_url(href, base_url);
+ let ScriptChan(ref script_chan) = self.script_chan;
+ if href.starts_with("#") {
+ script_chan.send(TriggerFragmentMsg(self.page.id, url));
+ } else {
+ script_chan.send(TriggerLoadMsg(self.page.id, url));
+ }
+ }
}
impl<'a> PrivateWindowHelpers for JSRef<'a, Window> {
@@ -382,10 +397,10 @@ impl Window {
pub fn new(cx: *JSContext,
page: Rc<Page>,
script_chan: ScriptChan,
- compositor: ~ScriptListener,
+ compositor: Box<ScriptListener>,
image_cache_task: ImageCacheTask)
-> JS<Window> {
- let win = ~Window {
+ let win = box Window {
eventtarget: EventTarget::new_inherited(WindowTypeId),
script_chan: script_chan,
console: None,
@@ -394,7 +409,7 @@ impl Window {
location: None,
navigator: None,
image_cache_task: image_cache_task,
- active_timers: HashMap::new(),
+ active_timers: box HashMap::new(),
next_timer_handle: 0,
browser_context: None,
performance: None,