Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
servo: Merge #15438 - Add ImmutableOrigin to allow for serializing or…
Browse files Browse the repository at this point in the history
…igins (from asajeffrey:url-serializable-origin); r=jdm

<!-- Please describe your changes on the following line: -->

This PR adds a serializable type `ImmutableOrigin` and a non-serializable type `MutableOrigin`. The immutable type represents an origin with `null` domain, and the mutable type represents an origin with a mutable domain. This separation is needed for implementing setting `document.domain`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14892.
- [X] These changes do not require tests because it's a refactoring which will enable other features.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 78e8c31a4d1890260dda83f2db85672f693c1e97
  • Loading branch information
cbrewster committed Feb 22, 2017
1 parent 8e471a6 commit 110b95b
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 152 deletions.
3 changes: 3 additions & 0 deletions servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions servo/components/net/http_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use net_traits::response::{HttpsState, Response, ResponseBody, ResponseType};
use openssl;
use openssl::ssl::error::{OpensslError, SslError};
use resource_thread::AuthCache;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::collections::HashSet;
use std::error::Error;
use std::io::{self, Read, Write};
Expand All @@ -51,7 +51,6 @@ use std::thread;
use time;
use time::Tm;
use unicase::UniCase;
use url::Origin as UrlOrigin;
use uuid;

fn read_block<R: Read>(reader: &mut R) -> Result<Data, ()> {
Expand Down Expand Up @@ -389,7 +388,7 @@ fn send_response_to_devtools(devtools_chan: &Sender<DevtoolsControlMsg>,
let _ = devtools_chan.send(DevtoolsControlMsg::FromChrome(msg));
}

fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, origin: &UrlOrigin) -> Option<Basic> {
fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, origin: &ImmutableOrigin) -> Option<Basic> {
if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(&origin.ascii_serialization()) {
let user_name = auth_entry.user_name.clone();
let password = Some(auth_entry.password.clone());
Expand Down Expand Up @@ -767,7 +766,7 @@ fn http_redirect_fetch(request: Rc<Request>,

// Step 9
if cors_flag && !same_origin {
*request.origin.borrow_mut() = Origin::Origin(UrlOrigin::new_opaque());
*request.origin.borrow_mut() = Origin::Origin(ImmutableOrigin::new_opaque());
}

// Step 10
Expand Down
7 changes: 3 additions & 4 deletions servo/components/net_traits/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use ReferrerPolicy;
use hyper::header::Headers;
use hyper::method::Method;
use msg::constellation_msg::PipelineId;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::cell::{Cell, RefCell};
use std::default::Default;
use url::Origin as UrlOrigin;

/// An [initiator](https://fetch.spec.whatwg.org/#concept-request-initiator)
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
Expand Down Expand Up @@ -55,10 +54,10 @@ pub enum Destination {
}

/// A request [origin](https://fetch.spec.whatwg.org/#concept-request-origin)
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, HeapSizeOf)]
pub enum Origin {
Client,
Origin(UrlOrigin),
Origin(ImmutableOrigin),
}

/// A [referer](https://fetch.spec.whatwg.org/#concept-request-referrer)
Expand Down
6 changes: 3 additions & 3 deletions servo/components/script/dom/bindings/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use selectors::matching::ElementSelectorFlags;
use serde::{Deserialize, Serialize};
use servo_atoms::Atom;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use smallvec::SmallVec;
use std::cell::{Cell, RefCell, UnsafeCell};
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
Expand All @@ -104,7 +104,6 @@ use style::stylesheets::SupportsRule;
use style::values::specified::Length;
use style::viewport::ViewportRule;
use time::Duration;
use url::Origin as UrlOrigin;
use uuid::Uuid;
use webrender_traits::{WebGLBufferId, WebGLError, WebGLFramebufferId, WebGLProgramId};
use webrender_traits::{WebGLRenderbufferId, WebGLShaderId, WebGLTextureId};
Expand Down Expand Up @@ -317,9 +316,10 @@ unsafe impl<A: JSTraceable, B: JSTraceable, C: JSTraceable> JSTraceable for (A,
}
}

unsafe_no_jsmanaged_fields!(bool, f32, f64, String, ServoUrl, AtomicBool, AtomicUsize, UrlOrigin, Uuid, char);
unsafe_no_jsmanaged_fields!(bool, f32, f64, String, AtomicBool, AtomicUsize, Uuid, char);
unsafe_no_jsmanaged_fields!(usize, u8, u16, u32, u64);
unsafe_no_jsmanaged_fields!(isize, i8, i16, i32, i64);
unsafe_no_jsmanaged_fields!(ServoUrl, ImmutableOrigin, MutableOrigin);
unsafe_no_jsmanaged_fields!(Image, ImageMetadata, ImageCacheChan, ImageCacheThread);
unsafe_no_jsmanaged_fields!(Metadata);
unsafe_no_jsmanaged_fields!(NetworkError);
Expand Down
33 changes: 17 additions & 16 deletions servo/components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl};
use net_traits::request::RequestInit;
use net_traits::response::HttpsState;
use num_traits::ToPrimitive;
use origin::Origin;
use script_layout_interface::message::{Msg, ReflowQueryType};
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Runnable};
Expand All @@ -116,7 +115,7 @@ use script_traits::{TouchEventType, TouchId};
use script_traits::UntrustedNodeAddress;
use servo_atoms::Atom;
use servo_config::prefs::PREFS;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::{Cell, Ref, RefMut};
Expand All @@ -136,6 +135,7 @@ use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join};
use style::stylesheets::Stylesheet;
use task_source::TaskSource;
use time;
use url::Host;
use url::percent_encoding::percent_decode;

pub enum TouchEventResult {
Expand Down Expand Up @@ -277,7 +277,7 @@ pub struct Document {
https_state: Cell<HttpsState>,
touchpad_pressure_phase: Cell<TouchpadPressurePhase>,
/// The document's origin.
origin: Origin,
origin: MutableOrigin,
/// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states
referrer_policy: Cell<Option<ReferrerPolicy>>,
/// https://html.spec.whatwg.org/multipage/#dom-document-referrer
Expand Down Expand Up @@ -424,7 +424,7 @@ impl Document {
}
}

pub fn origin(&self) -> &Origin {
pub fn origin(&self) -> &MutableOrigin {
&self.origin
}

Expand Down Expand Up @@ -1949,7 +1949,7 @@ impl Document {
pub fn new_inherited(window: &Window,
has_browsing_context: HasBrowsingContext,
url: Option<ServoUrl>,
origin: Origin,
origin: MutableOrigin,
is_html_document: IsHTMLDocument,
content_type: Option<DOMString>,
last_modified: Option<String>,
Expand Down Expand Up @@ -2053,7 +2053,7 @@ impl Document {
Ok(Document::new(window,
HasBrowsingContext::No,
None,
doc.origin().alias(),
doc.origin().clone(),
IsHTMLDocument::NonHTMLDocument,
None,
None,
Expand All @@ -2067,7 +2067,7 @@ impl Document {
pub fn new(window: &Window,
has_browsing_context: HasBrowsingContext,
url: Option<ServoUrl>,
origin: Origin,
origin: MutableOrigin,
doctype: IsHTMLDocument,
content_type: Option<DOMString>,
last_modified: Option<String>,
Expand Down Expand Up @@ -2154,7 +2154,7 @@ impl Document {
HasBrowsingContext::No,
None,
// https://github.com/whatwg/html/issues/2109
Origin::opaque_identifier(),
MutableOrigin::new(ImmutableOrigin::new_opaque()),
doctype,
None,
None,
Expand Down Expand Up @@ -2411,16 +2411,17 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#relaxing-the-same-origin-restriction
fn Domain(&self) -> DOMString {
// Step 1.
if self.browsing_context().is_none() {
if !self.has_browsing_context {
return DOMString::new();
}

if let Some(host) = self.origin.host() {
// Step 4.
DOMString::from(host.to_string())
} else {
// Step 2.
match self.origin.effective_domain() {
// Step 3.
DOMString::new()
None => DOMString::new(),
// Step 4.
Some(Host::Domain(domain)) => DOMString::from(domain),
Some(host) => DOMString::from(host.to_string()),
}
}

Expand Down Expand Up @@ -3077,7 +3078,7 @@ impl DocumentMethods for Document {
return Ok(DOMString::new());
}

if !self.origin.is_scheme_host_port_tuple() {
if !self.origin.is_tuple() {
return Err(Error::Security);
}

Expand All @@ -3097,7 +3098,7 @@ impl DocumentMethods for Document {
return Ok(());
}

if !self.origin.is_scheme_host_port_tuple() {
if !self.origin.is_tuple() {
return Err(Error::Security);
}

Expand Down
4 changes: 2 additions & 2 deletions servo/components/script/dom/domimplementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl DOMImplementationMethods for DOMImplementation {
let doc = XMLDocument::new(win,
HasBrowsingContext::No,
None,
self.document.origin().alias(),
self.document.origin().clone(),
IsHTMLDocument::NonHTMLDocument,
Some(DOMString::from(content_type)),
None,
Expand Down Expand Up @@ -127,7 +127,7 @@ impl DOMImplementationMethods for DOMImplementation {
let doc = Document::new(win,
HasBrowsingContext::No,
None,
self.document.origin().alias(),
self.document.origin().clone(),
IsHTMLDocument::HTMLDocument,
None,
None,
Expand Down
4 changes: 2 additions & 2 deletions servo/components/script/dom/domparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl DOMParserMethods for DOMParser {
let document = Document::new(&self.window,
HasBrowsingContext::No,
Some(url.clone()),
doc.origin().alias(),
doc.origin().clone(),
IsHTMLDocument::HTMLDocument,
Some(content_type),
None,
Expand All @@ -79,7 +79,7 @@ impl DOMParserMethods for DOMParser {
let document = Document::new(&self.window,
HasBrowsingContext::No,
Some(url.clone()),
doc.origin().alias(),
doc.origin().clone(),
IsHTMLDocument::NonHTMLDocument,
Some(content_type),
None,
Expand Down
2 changes: 1 addition & 1 deletion servo/components/script/dom/htmliframeelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl HTMLIFrameElement {
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
};

ScriptThread::process_attach_layout(new_layout_info, document.origin().alias());
ScriptThread::process_attach_layout(new_layout_info, document.origin().clone());
} else {
let load_info = IFrameLoadInfoWithData {
info: load_info,
Expand Down
2 changes: 1 addition & 1 deletion servo/components/script/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ impl Node {
let document = Document::new(window, HasBrowsingContext::No,
Some(document.url()),
// https://github.com/whatwg/dom/issues/378
document.origin().alias(),
document.origin().clone(),
is_html_doc, None,
None, DocumentActivity::Inactive,
DocumentSource::NotFromParser, loader,
Expand Down
2 changes: 1 addition & 1 deletion servo/components/script/dom/servoparser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl ServoParser {
let document = Document::new(window,
HasBrowsingContext::No,
Some(url.clone()),
context_document.origin().alias(),
context_document.origin().clone(),
IsHTMLDocument::HTMLDocument,
None,
None,
Expand Down
11 changes: 5 additions & 6 deletions servo/components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::storage_thread::StorageType;
use num_traits::ToPrimitive;
use open;
use origin::Origin;
use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64};
Expand All @@ -83,7 +82,7 @@ use servo_atoms::Atom;
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_geometry::{f32_rect_to_au_rect, max_rect};
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Cell;
Expand Down Expand Up @@ -660,10 +659,10 @@ impl WindowMethods for Window {
"/" => {
// TODO(#12715): Should be the origin of the incumbent settings
// object, not self's.
Some(self.Document().origin().copy())
Some(self.Document().origin().immutable().clone())
},
url => match ServoUrl::parse(&url) {
Ok(url) => Some(Origin::new(&url)),
Ok(url) => Some(url.origin().clone()),
Err(_) => return Err(Error::Syntax),
}
};
Expand Down Expand Up @@ -1793,13 +1792,13 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue

struct PostMessageHandler {
destination: Trusted<Window>,
origin: Option<Origin>,
origin: Option<ImmutableOrigin>,
message: StructuredCloneData,
}

impl PostMessageHandler {
fn new(window: &Window,
origin: Option<Origin>,
origin: Option<ImmutableOrigin>,
message: StructuredCloneData) -> PostMessageHandler {
PostMessageHandler {
destination: Trusted::new(window),
Expand Down
7 changes: 3 additions & 4 deletions servo/components/script/dom/xmldocument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use dom::location::Location;
use dom::node::Node;
use dom::window::Window;
use js::jsapi::{JSContext, JSObject};
use origin::Origin;
use script_traits::DocumentActivity;
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};

// https://dom.spec.whatwg.org/#xmldocument
#[dom_struct]
Expand All @@ -29,7 +28,7 @@ impl XMLDocument {
fn new_inherited(window: &Window,
has_browsing_context: HasBrowsingContext,
url: Option<ServoUrl>,
origin: Origin,
origin: MutableOrigin,
is_html_document: IsHTMLDocument,
content_type: Option<DOMString>,
last_modified: Option<String>,
Expand All @@ -55,7 +54,7 @@ impl XMLDocument {
pub fn new(window: &Window,
has_browsing_context: HasBrowsingContext,
url: Option<ServoUrl>,
origin: Origin,
origin: MutableOrigin,
doctype: IsHTMLDocument,
content_type: Option<DOMString>,
last_modified: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion servo/components/script/dom/xmlhttprequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl XMLHttpRequest {
Document::new(win,
HasBrowsingContext::No,
parsed_url,
doc.origin().alias(),
doc.origin().clone(),
is_html_document,
content_type,
None,
Expand Down
1 change: 0 additions & 1 deletion servo/components/script/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub mod layout_wrapper;
mod mem;
mod microtask;
mod network_listener;
pub mod origin;
pub mod script_runtime;
#[allow(unsafe_code)]
pub mod script_thread;
Expand Down
Loading

0 comments on commit 110b95b

Please sign in to comment.