Auto merge of #16508 - brainlessdeveloper:fetch-set-origin, r=asajeffrey

Properly set origin of fetch requests

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

These changes aim to fix #15247

---
<!-- 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 #15247 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes
- [x] These changes do not require tests because cors is already tested with different origins

These changes require changes in tests, but I need help with that (see comments below).

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16508)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-17 08:29:23 -07:00 committed by GitHub
commit 2bb4f65100
32 changed files with 173 additions and 529 deletions

View file

@ -160,6 +160,7 @@ impl DedicatedWorkerGlobalScope {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone();
thread::Builder::new().name(name).spawn(move || {
thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER);
@ -179,10 +180,10 @@ impl DedicatedWorkerGlobalScope {
destination: Destination::Worker,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: worker_url,
pipeline_id: pipeline_id,
referrer_url: referrer_url,
referrer_policy: referrer_policy,
origin,
.. RequestInit::default()
};

View file

@ -387,7 +387,7 @@ impl EventSource {
// TODO: Step 9 set request's client settings
let mut request = RequestInit {
url: url_record,
origin: global.get_url(),
origin: global.origin().immutable().clone(),
pipeline_id: Some(global.pipeline_id()),
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
use_url_credentials: true,

View file

@ -259,7 +259,7 @@ impl HTMLImageElement {
let request = RequestInit {
url: img_url.clone(),
origin: document.url().clone(),
origin: document.origin().immutable().clone(),
type_: RequestType::Image,
pipeline_id: Some(document.global().pipeline_id()),
.. RequestInit::default()

View file

@ -550,7 +550,7 @@ impl HTMLMediaElement {
destination: Destination::Media,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: document.url(),
origin: document.origin().immutable().clone(),
pipeline_id: Some(self.global().pipeline_id()),
referrer_url: Some(document.url()),
referrer_policy: document.get_referrer_policy(),

View file

@ -253,7 +253,7 @@ fn fetch_a_classic_script(script: &HTMLScriptElement,
Some(CorsSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
_ => CredentialsMode::Include,
},
origin: doc.url(),
origin: doc.origin().immutable().clone(),
pipeline_id: Some(script.global().pipeline_id()),
referrer_url: Some(doc.url()),
referrer_policy: doc.get_referrer_policy(),

View file

@ -151,6 +151,7 @@ impl ServiceWorkerGlobalScope {
.. } = scope_things;
let serialized_worker_url = script_url.to_string();
let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone();
thread::Builder::new().name(format!("ServiceWorker for {}", serialized_worker_url)).spawn(move || {
thread_state::initialize(SCRIPT | IN_WORKER);
let roots = RootCollection::new();
@ -164,10 +165,10 @@ impl ServiceWorkerGlobalScope {
destination: Destination::ServiceWorker,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: script_url,
pipeline_id: pipeline_id,
referrer_url: referrer_url,
referrer_policy: referrer_policy,
origin,
.. RequestInit::default()
};

View file

@ -211,7 +211,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
destination: Destination::Script,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: self.worker_url.clone(),
origin: global_scope.origin().immutable().clone(),
pipeline_id: Some(self.upcast::<GlobalScope>().pipeline_id()),
referrer_url: None,
referrer_policy: None,

View file

@ -574,17 +574,14 @@ impl WorkletThread {
// TODO: Fetch a module graph, not just a single script.
// TODO: Fetch the script asynchronously?
// TODO: Caching.
// TODO: Avoid re-parsing the origin as a URL.
let resource_fetcher = self.global_init.resource_threads.sender();
let origin_url = ServoUrl::parse(&*origin.unicode_serialization())
.unwrap_or_else(|_| ServoUrl::parse("about:blank").unwrap());
let request = RequestInit {
url: script_url,
type_: RequestType::Script,
destination: Destination::Script,
mode: RequestMode::CorsMode,
origin: origin_url,
credentials_mode: credentials.into(),
origin,
.. RequestInit::default()
};
let script = load_whole_resource(request, &resource_fetcher).ok()

View file

@ -594,7 +594,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
use_cors_preflight: has_handlers,
credentials_mode: credentials_mode,
use_url_credentials: use_url_credentials,
origin: self.global().get_url(),
origin: self.global().origin().immutable().clone(),
referrer_url: self.referrer_url.clone(),
referrer_policy: self.referrer_policy.clone(),
pipeline_id: Some(self.global().pipeline_id()),

View file

@ -56,10 +56,7 @@ fn request_init_from_request(request: NetTraitsRequest) -> NetTraitsRequestInit
use_cors_preflight: request.use_cors_preflight,
credentials_mode: request.credentials_mode,
use_url_credentials: request.use_url_credentials,
// TODO: NetTraitsRequestInit and NetTraitsRequest have different "origin"
// ... NetTraitsRequestInit.origin: Url
// ... NetTraitsRequest.origin: RefCell<Origin>
origin: request.url(),
origin: GlobalScope::current().expect("No current global object").origin().immutable().clone(),
referrer_url: from_referrer_to_referrer_url(&request),
referrer_policy: request.referrer_policy,
pipeline_id: request.pipeline_id,

View file

@ -70,7 +70,7 @@ pub fn fetch_image_for_layout(url: ServoUrl,
let request = FetchRequestInit {
url: url,
origin: document.url().clone(),
origin: document.origin().immutable().clone(),
type_: RequestType::Image,
pipeline_id: Some(document.global().pipeline_id()),
.. FetchRequestInit::default()

View file

@ -1928,6 +1928,12 @@ impl ScriptThread {
ROUTER.route_ipc_receiver_to_mpsc_sender(ipc_timer_event_port,
self.timer_event_chan.clone());
let origin = if final_url.as_str() == "about:blank" {
incomplete.origin.clone()
} else {
MutableOrigin::new(final_url.origin())
};
// Create the window and document objects.
let window = Window::new(self.js_runtime.clone(),
MainThreadScriptChan(sender.clone()),
@ -1951,7 +1957,7 @@ impl ScriptThread {
incomplete.pipeline_id,
incomplete.parent_info,
incomplete.window_size,
incomplete.origin.clone(),
origin,
self.webvr_thread.clone());
// Initialize the browsing context for the window.
@ -2283,13 +2289,13 @@ impl ScriptThread {
destination: Destination::Document,
credentials_mode: CredentialsMode::Include,
use_url_credentials: true,
origin: load_data.url.clone(),
pipeline_id: Some(id),
referrer_url: load_data.referrer_url,
referrer_policy: load_data.referrer_policy,
headers: load_data.headers,
body: load_data.data,
redirect_mode: RedirectMode::Manual,
origin: incomplete.origin.immutable().clone(),
.. RequestInit::default()
};

View file

@ -261,7 +261,7 @@ impl<'a> StylesheetLoader<'a> {
Some(CorsSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
_ => CredentialsMode::Include,
},
origin: document.url(),
origin: document.origin().immutable().clone(),
pipeline_id: Some(self.elem.global().pipeline_id()),
referrer_url: Some(document.url()),
referrer_policy: referrer_policy,