Skip to content

Commit

Permalink
basic location
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Nov 24, 2013
1 parent 94df5d1 commit ccc7fa7
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/script/dom/bindings/codegen/Bindings.conf
Expand Up @@ -280,6 +280,9 @@ DOMInterfaces = {
'workers': True,
}],

'Location': {
},

'MozChannel': [
{
'nativeType': 'nsIChannel',
Expand Down
21 changes: 21 additions & 0 deletions src/components/script/dom/bindings/codegen/Location.webidl
@@ -0,0 +1,21 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/#the-location-interface
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce
* and create derivative works of this document.
*/

// No support for [Unforgeable] on interfaces yet
//[Unforgeable]
interface Location {
void assign(DOMString url);
void replace(DOMString url);
void reload();
};
Location implements URLUtils;
32 changes: 32 additions & 0 deletions src/components/script/dom/bindings/codegen/URLUtils.webidl
@@ -0,0 +1,32 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://url.spec.whatwg.org/#urlutils
*
* To the extent possible under law, the editors have waived all copyright
* and related or neighboring rights to this work. In addition, as of 17
* February 2013, the editors have made this specification available under
* the Open Web Foundation Agreement Version 1.0, which is available at
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
*/

[NoInterfaceObject]
interface URLUtils {
[SetterThrows]
/* stringifier */ attribute DOMString href;
readonly attribute DOMString origin;

attribute DOMString protocol;
attribute DOMString username;
attribute DOMString password;
attribute DOMString host;
attribute DOMString hostname;
attribute DOMString port;
attribute DOMString pathname;
attribute DOMString search;
// attribute URLQuery? query;
attribute DOMString hash;
};
4 changes: 2 additions & 2 deletions src/components/script/dom/bindings/codegen/Window.webidl
Expand Up @@ -14,8 +14,8 @@
[Replaceable] readonly attribute WindowProxy self;*/
[Unforgeable] readonly attribute Document document;
attribute DOMString name;
/*[PutForwards=href, Unforgeable] readonly attribute Location location;
readonly attribute History history;
/* [PutForwards=href, Unforgeable] */ readonly attribute Location location;
/* readonly attribute History history;
[Replaceable] readonly attribute BarProp locationbar;
[Replaceable] readonly attribute BarProp menubar;
[Replaceable] readonly attribute BarProp personalbar;
Expand Down
134 changes: 134 additions & 0 deletions src/components/script/dom/location.rs
@@ -0,0 +1,134 @@
/* 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/. */

use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::{DOMString, Fallible};
use dom::bindings::codegen::LocationBinding;
use dom::window::Window;

use script_task::{Page};

pub struct Location {
reflector_: Reflector, //XXXjdm cycle: window->Location->window
page: @mut Page
}

impl Location {
pub fn new_inherited(page: @mut Page) -> Location {
Location {
reflector_: Reflector::new(),
page: page
}
}

pub fn new(window: &Window, page: @mut Page) -> @mut Location {
reflect_dom_object(@mut Location::new_inherited(page), window, LocationBinding::Wrap)
}

pub fn Assign(&self, _url: DOMString) {

}

pub fn Replace(&self, _url: DOMString) {

}

pub fn Reload(&self) {

}

pub fn Href(&self) -> DOMString {
self.page.url.get_ref().first().to_str()
}

pub fn SetHref(&self, _href: DOMString) -> Fallible<()> {
Ok(())
}

pub fn Origin(&self) -> DOMString {
~""
}

pub fn Protocol(&self) -> DOMString {
~""
}

pub fn SetProtocol(&self, _protocol: DOMString) {

}

pub fn Username(&self) -> DOMString {
~""
}

pub fn SetUsername(&self, _username: DOMString) {

}

pub fn Password(&self) -> DOMString {
~""
}

pub fn SetPassword(&self, _password: DOMString) {

}

pub fn Host(&self) -> DOMString {
~""
}

pub fn SetHost(&self, _host: DOMString) {

}

pub fn Hostname(&self) -> DOMString {
~""
}

pub fn SetHostname(&self, _hostname: DOMString) {

}

pub fn Port(&self) -> DOMString {
~""
}

pub fn SetPort(&self, _port: DOMString) {

}

pub fn Pathname(&self) -> DOMString {
~""
}

pub fn SetPathname(&self, _pathname: DOMString) {

}

pub fn Search(&self) -> DOMString {
~""
}

pub fn SetSearch(&self, _search: DOMString) {

}

pub fn Hash(&self) -> DOMString {
~""
}

pub fn SetHash(&self, _hash: DOMString) {

}
}

impl Reflectable for Location {
fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector_
}

fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
&mut self.reflector_
}
}
10 changes: 10 additions & 0 deletions src/components/script/dom/window.rs
Expand Up @@ -8,6 +8,7 @@ use dom::bindings::utils::DOMString;
use dom::document::AbstractDocument;
use dom::eventtarget::{EventTarget, WindowTypeId};
use dom::node::{AbstractNode, ScriptView};
use dom::location::Location;
use dom::navigator::Navigator;

use layout_interface::ReflowForDisplay;
Expand Down Expand Up @@ -43,6 +44,7 @@ pub struct Window {
script_chan: ScriptChan,
compositor: @ScriptListener,
timer_chan: SharedChan<TimerControlMsg>,
location: Option<@mut Location>,
navigator: Option<@mut Navigator>,
image_cache_task: ImageCacheTask,
active_timers: ~HashSet<i32>,
Expand Down Expand Up @@ -116,6 +118,13 @@ impl Window {
None
}

pub fn Location(&mut self) -> @mut Location {
if self.location.is_none() {
self.location = Some(Location::new(self, self.page));
}
self.location.unwrap()
}

pub fn Navigator(&mut self) -> @mut Navigator {
if self.navigator.is_none() {
self.navigator = Some(Navigator::new(self));
Expand Down Expand Up @@ -215,6 +224,7 @@ impl Window {
}
SharedChan::new(timer_chan)
},
location: None,
navigator: None,
image_cache_task: image_cache_task,
active_timers: ~HashSet::new(),
Expand Down
1 change: 1 addition & 0 deletions src/components/script/script.rc
Expand Up @@ -130,6 +130,7 @@ pub mod dom {
pub mod htmlulistelement;
pub mod htmlvideoelement;
pub mod htmlunknownelement;
pub mod location;
pub mod mouseevent;
pub mod namespace;
pub mod navigator;
Expand Down

0 comments on commit ccc7fa7

Please sign in to comment.