forked from mirrors/gecko-dev
		
	 6ff0a01710
			
		
	
	
		6ff0a01710
		
	
	
	
	
		
			
			Rebased and improved version of #4967. Source-Repo: https://github.com/servo/servo Source-Revision: 72f8898990f06e7f505eeaf9cfa671740c60395d
		
			
				
	
	
		
			70 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| /* 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::codegen::Bindings::LocationBinding;
 | |
| use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
 | |
| use dom::bindings::global::GlobalRef;
 | |
| use dom::bindings::js::{JS, JSRef, Temporary};
 | |
| use dom::bindings::utils::{Reflector, reflect_dom_object};
 | |
| use dom::urlhelper::UrlHelper;
 | |
| use dom::window::Window;
 | |
| use dom::window::WindowHelpers;
 | |
| 
 | |
| use util::str::DOMString;
 | |
| use url::Url;
 | |
| 
 | |
| #[dom_struct]
 | |
| pub struct Location {
 | |
|     reflector_: Reflector,
 | |
|     window: JS<Window>,
 | |
| }
 | |
| 
 | |
| impl Location {
 | |
|     fn new_inherited(window: JSRef<Window>) -> Location {
 | |
|         Location {
 | |
|             reflector_: Reflector::new(),
 | |
|             window: JS::from_rooted(window)
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     pub fn new(window: JSRef<Window>) -> Temporary<Location> {
 | |
|         reflect_dom_object(box Location::new_inherited(window),
 | |
|                            GlobalRef::Window(window),
 | |
|                            LocationBinding::Wrap)
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl<'a> LocationMethods for JSRef<'a, Location> {
 | |
|     // https://html.spec.whatwg.org/multipage/browsers.html#dom-location-assign
 | |
|     fn Assign(self, url: DOMString) {
 | |
|         self.window.root().r().load_url(url);
 | |
|     }
 | |
| 
 | |
|     fn Href(self) -> DOMString {
 | |
|         UrlHelper::Href(&self.get_url())
 | |
|     }
 | |
| 
 | |
|     fn Stringify(self) -> DOMString {
 | |
|         self.Href()
 | |
|     }
 | |
| 
 | |
|     fn Search(self) -> DOMString {
 | |
|         UrlHelper::Search(&self.get_url())
 | |
|     }
 | |
| 
 | |
|     fn Hash(self) -> DOMString {
 | |
|         UrlHelper::Hash(&self.get_url())
 | |
|     }
 | |
| }
 | |
| 
 | |
| trait PrivateLocationHelpers {
 | |
|     fn get_url(self) -> Url;
 | |
| }
 | |
| 
 | |
| impl<'a> PrivateLocationHelpers for JSRef<'a, Location> {
 | |
|     fn get_url(self) -> Url {
 | |
|         let window = self.window.root();
 | |
|         window.r().get_url()
 | |
|     }
 | |
| }
 |