forked from mirrors/gecko-dev
		
	 ddd49dfd1c
			
		
	
	
		ddd49dfd1c
		
	
	
	
	
		
			
			Because of #2122 I cannot write test for this right now because it will be failing randomly due to that iframe issue. However, if it doesn't fail due to that issue a test like this:
```html
<html>
  <head>
    <meta charset="utf8" />
    <script src="harness.js"></script>
    <title>Iframe contentDocument test.</title>
  </head>
  <body>
    <iframe src="test_iframe_contentDocument_inner.html" id="iframe"></iframe>
    <script>
      waitForExplicitFinish();
      var timeout = 100;
      var iframe = document.getElementById('iframe');
      function test_contentWindow() {
        if (!iframe.contentWindow) {
          // Iframe not loaded yet, try again.
          // No load event for iframe, insert bug number here.
          setTimeout(test_contentWindow, timeout);
          return;
        }
        is(iframe.contentDocument.getElementById('test').textContent, 'value');
        finish();
      }
      test_contentWindow();
    </script>
  </body>
</html>
```
where inner is simply:
```html
<html><body><div id="test">value</div></body></html>
```
passes.
I have added `SameOrigin` method to the `UrlHelper`. I wanted to reuse it in [`constellation.rs` same_script check](f0184a2d01/components/compositing/constellation.rs (L625)) but I it didn't want to compile saying
```
error: unresolved import `dom::urlhelper::UrlHelper`. Maybe a missing `extern crate dom`?
```
So I didn't include it in this PR for now.
There is more discussion about the cross origin iframes in [another issue](https://github.com/servo/servo/issues/3939). In this PR I just added same origin check.
Source-Repo: https://github.com/servo/servo
Source-Revision: 85a2f0b66a32cfd6022b3e6cec6ec06f3b59baf1
		
	
			
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			1.2 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 servo_util::str::DOMString;
 | |
| use url::Url;
 | |
| 
 | |
| pub struct UrlHelper;
 | |
| 
 | |
| impl UrlHelper {
 | |
|     pub fn Href(url: &Url) -> DOMString {
 | |
|         url.serialize()
 | |
|     }
 | |
| 
 | |
|     pub fn Search(url: &Url) -> DOMString {
 | |
|         match url.query {
 | |
|             None => "".to_string(),
 | |
|             Some(ref query) if query.as_slice() == "" => "".to_string(),
 | |
|             Some(ref query) => format!("?{}", query)
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     pub fn Hash(url: &Url) -> DOMString {
 | |
|         match url.fragment {
 | |
|             None => "".to_string(),
 | |
|             Some(ref hash) if hash.as_slice() == "" => "".to_string(),
 | |
|             Some(ref hash) => format!("#{}", hash)
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /// https://html.spec.whatwg.org/multipage/browsers.html#same-origin
 | |
|     pub fn SameOrigin(urlA: &Url, urlB: &Url) -> bool {
 | |
|         if urlA.host() != urlB.host() {
 | |
|             return false
 | |
|         }
 | |
|         if urlA.scheme != urlB.scheme {
 | |
|             return false
 | |
|         }
 | |
|         if urlA.port() != urlB.port() {
 | |
|             return false
 | |
|         }
 | |
|         return true
 | |
|     }
 | |
| }
 |