mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
auto merge of #1270 : evilpie/servo/url, r=jdm
I wasn't sure how to store @window in Location, so I just made it use @Page for now. I was going to implement stringifier, but sadly some of the webidl stuff is like 1 year out of sync.
This commit is contained in:
commit
f6646e17bf
8 changed files with 229 additions and 22 deletions
|
@ -280,6 +280,9 @@ DOMInterfaces = {
|
||||||
'workers': True,
|
'workers': True,
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
'Location': {
|
||||||
|
},
|
||||||
|
|
||||||
'MozChannel': [
|
'MozChannel': [
|
||||||
{
|
{
|
||||||
'nativeType': 'nsIChannel',
|
'nativeType': 'nsIChannel',
|
||||||
|
|
21
src/components/script/dom/bindings/codegen/Location.webidl
Normal file
21
src/components/script/dom/bindings/codegen/Location.webidl
Normal file
|
@ -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
src/components/script/dom/bindings/codegen/URLUtils.webidl
Normal file
32
src/components/script/dom/bindings/codegen/URLUtils.webidl
Normal file
|
@ -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;
|
||||||
|
};
|
|
@ -14,8 +14,8 @@
|
||||||
[Replaceable] readonly attribute WindowProxy self;*/
|
[Replaceable] readonly attribute WindowProxy self;*/
|
||||||
[Unforgeable] readonly attribute Document document;
|
[Unforgeable] readonly attribute Document document;
|
||||||
attribute DOMString name;
|
attribute DOMString name;
|
||||||
/*[PutForwards=href, Unforgeable] readonly attribute Location location;
|
/* [PutForwards=href, Unforgeable] */ readonly attribute Location location;
|
||||||
readonly attribute History history;
|
/* readonly attribute History history;
|
||||||
[Replaceable] readonly attribute BarProp locationbar;
|
[Replaceable] readonly attribute BarProp locationbar;
|
||||||
[Replaceable] readonly attribute BarProp menubar;
|
[Replaceable] readonly attribute BarProp menubar;
|
||||||
[Replaceable] readonly attribute BarProp personalbar;
|
[Replaceable] readonly attribute BarProp personalbar;
|
||||||
|
|
|
@ -29,7 +29,7 @@ use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||||
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
||||||
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
||||||
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
||||||
use js::jsapi::{JSString};
|
use js::jsapi::{JSString, JS_CallTracer, JSTRACE_OBJECT};
|
||||||
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||||
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
use js::{JSPROP_ENUMERATE, JSVAL_NULL, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
||||||
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
|
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
|
||||||
|
@ -588,6 +588,24 @@ pub trait Traceable {
|
||||||
fn trace(&self, trc: *mut JSTracer);
|
fn trace(&self, trc: *mut JSTracer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fixed_stack_segment]
|
||||||
|
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
|
||||||
|
unsafe {
|
||||||
|
do description.to_c_str().with_ref |name| {
|
||||||
|
(*tracer).debugPrinter = ptr::null();
|
||||||
|
(*tracer).debugPrintIndex = -1;
|
||||||
|
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||||
|
debug!("tracing {:s}", description);
|
||||||
|
JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(),
|
||||||
|
JSTRACE_OBJECT as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trace_option<T: Reflectable>(tracer: *mut JSTracer, description: &str, option: Option<@mut T>) {
|
||||||
|
option.map(|some| trace_reflector(tracer, description, some.reflector()));
|
||||||
|
}
|
||||||
|
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
pub fn initialize_global(global: *JSObject) {
|
pub fn initialize_global(global: *JSObject) {
|
||||||
let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);
|
let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);
|
||||||
|
|
134
src/components/script/dom/location.rs
Normal file
134
src/components/script/dom/location.rs
Normal file
|
@ -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_
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,12 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::WindowBinding;
|
use dom::bindings::codegen::WindowBinding;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, Traceable};
|
use dom::bindings::utils::{Reflectable, Reflector, Traceable};
|
||||||
|
use dom::bindings::utils::{trace_option, trace_reflector};
|
||||||
use dom::bindings::utils::DOMString;
|
use dom::bindings::utils::DOMString;
|
||||||
use dom::document::AbstractDocument;
|
use dom::document::AbstractDocument;
|
||||||
use dom::eventtarget::{EventTarget, WindowTypeId};
|
use dom::eventtarget::{EventTarget, WindowTypeId};
|
||||||
use dom::node::{AbstractNode, ScriptView};
|
use dom::node::{AbstractNode, ScriptView};
|
||||||
|
use dom::location::Location;
|
||||||
use dom::navigator::Navigator;
|
use dom::navigator::Navigator;
|
||||||
|
|
||||||
use layout_interface::ReflowForDisplay;
|
use layout_interface::ReflowForDisplay;
|
||||||
|
@ -16,8 +18,8 @@ use servo_msg::compositor_msg::ScriptListener;
|
||||||
use servo_net::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
|
|
||||||
use js::glue::*;
|
use js::glue::*;
|
||||||
use js::jsapi::{JSObject, JSContext, JS_DefineProperty, JS_CallTracer};
|
use js::jsapi::{JSObject, JSContext, JS_DefineProperty};
|
||||||
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JSTracer, JSTRACE_OBJECT};
|
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JSTracer};
|
||||||
use js::{JSVAL_NULL, JSPROP_ENUMERATE};
|
use js::{JSVAL_NULL, JSPROP_ENUMERATE};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -43,6 +45,7 @@ pub struct Window {
|
||||||
script_chan: ScriptChan,
|
script_chan: ScriptChan,
|
||||||
compositor: @ScriptListener,
|
compositor: @ScriptListener,
|
||||||
timer_chan: SharedChan<TimerControlMsg>,
|
timer_chan: SharedChan<TimerControlMsg>,
|
||||||
|
location: Option<@mut Location>,
|
||||||
navigator: Option<@mut Navigator>,
|
navigator: Option<@mut Navigator>,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
active_timers: ~HashSet<i32>,
|
active_timers: ~HashSet<i32>,
|
||||||
|
@ -116,6 +119,13 @@ impl Window {
|
||||||
None
|
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 {
|
pub fn Navigator(&mut self) -> @mut Navigator {
|
||||||
if self.navigator.is_none() {
|
if self.navigator.is_none() {
|
||||||
self.navigator = Some(Navigator::new(self));
|
self.navigator = Some(Navigator::new(self));
|
||||||
|
@ -215,6 +225,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
SharedChan::new(timer_chan)
|
SharedChan::new(timer_chan)
|
||||||
},
|
},
|
||||||
|
location: None,
|
||||||
navigator: None,
|
navigator: None,
|
||||||
image_cache_task: image_cache_task,
|
image_cache_task: image_cache_task,
|
||||||
active_timers: ~HashSet::new(),
|
active_timers: ~HashSet::new(),
|
||||||
|
@ -241,24 +252,11 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Traceable for Window {
|
impl Traceable for Window {
|
||||||
#[fixed_stack_segment]
|
|
||||||
fn trace(&self, tracer: *mut JSTracer) {
|
fn trace(&self, tracer: *mut JSTracer) {
|
||||||
debug!("tracing window");
|
debug!("tracing window");
|
||||||
unsafe {
|
|
||||||
match self.page.frame {
|
self.page.frame.map(|frame| trace_reflector(tracer, "document", frame.document.reflector()));
|
||||||
Some(frame) => {
|
trace_option(tracer, "location", self.location);
|
||||||
(*tracer).debugPrinter = ptr::null();
|
trace_option(tracer, "navigator", self.navigator);
|
||||||
(*tracer).debugPrintIndex = -1;
|
|
||||||
do "document".to_c_str().with_ref |name| {
|
|
||||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
|
||||||
debug!("tracing document");
|
|
||||||
JS_CallTracer(tracer as *JSTracer,
|
|
||||||
frame.document.reflector().get_jsobject(),
|
|
||||||
JSTRACE_OBJECT as u32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,7 @@ pub mod dom {
|
||||||
pub mod htmlulistelement;
|
pub mod htmlulistelement;
|
||||||
pub mod htmlvideoelement;
|
pub mod htmlvideoelement;
|
||||||
pub mod htmlunknownelement;
|
pub mod htmlunknownelement;
|
||||||
|
pub mod location;
|
||||||
pub mod mouseevent;
|
pub mod mouseevent;
|
||||||
pub mod namespace;
|
pub mod namespace;
|
||||||
pub mod navigator;
|
pub mod navigator;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue