Skip to content

Commit

Permalink
Auto merge of #16592 - avadacatavra:globalscope, r=jdm
Browse files Browse the repository at this point in the history
added origin to globalscope

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

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/16592)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 24, 2017
2 parents 46bb635 + 2c6bd51 commit 4263b79
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
5 changes: 5 additions & 0 deletions components/script/dom/dissimilaroriginlocation.rs
Expand Up @@ -12,6 +12,7 @@ use dom::bindings::str::DOMString;
use dom::bindings::str::USVString;
use dom::dissimilaroriginwindow::DissimilarOriginWindow;
use dom_struct::dom_struct;
use servo_url::MutableOrigin;

/// Represents a dissimilar-origin `Location` that exists in another script thread.
///
Expand Down Expand Up @@ -43,6 +44,10 @@ impl DissimilarOriginLocation {
window,
DissimilarOriginLocationBinding::Wrap)
}

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

impl DissimilarOriginLocationMethods for DissimilarOriginLocation {
Expand Down
8 changes: 7 additions & 1 deletion components/script/dom/dissimilaroriginwindow.rs
Expand Up @@ -19,6 +19,7 @@ use js::jsval::{JSVal, UndefinedValue};
use msg::constellation_msg::PipelineId;
use script_traits::ScriptMsg as ConstellationMsg;
use servo_url::ImmutableOrigin;
use servo_url::MutableOrigin;
use servo_url::ServoUrl;

/// Represents a dissimilar-origin `Window` that exists in another script thread.
Expand Down Expand Up @@ -56,12 +57,17 @@ impl DissimilarOriginWindow {
global_to_clone_from.constellation_chan().clone(),
global_to_clone_from.scheduler_chan().clone(),
global_to_clone_from.resource_threads().clone(),
timer_event_chan),
timer_event_chan,
global_to_clone_from.origin().clone()),
browsing_context: JS::from_ref(browsing_context),
location: MutNullableJS::new(None),
};
unsafe { DissimilarOriginWindowBinding::Wrap(cx, win) }
}

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

impl DissimilarOriginWindowMethods for DissimilarOriginWindow {
Expand Down
14 changes: 12 additions & 2 deletions components/script/dom/globalscope.rs
Expand Up @@ -38,7 +38,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent};
use script_traits::{TimerEventId, TimerSchedulerMsg, TimerSource};
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -92,6 +92,9 @@ pub struct GlobalScope {
resource_threads: ResourceThreads,

timers: OneshotTimers,

/// The origin of the globalscope
origin: MutableOrigin,
}

impl GlobalScope {
Expand All @@ -103,7 +106,8 @@ impl GlobalScope {
constellation_chan: IpcSender<ConstellationMsg>,
scheduler_chan: IpcSender<TimerSchedulerMsg>,
resource_threads: ResourceThreads,
timer_event_chan: IpcSender<TimerEvent>)
timer_event_chan: IpcSender<TimerEvent>,
origin: MutableOrigin)
-> Self {
GlobalScope {
eventtarget: EventTarget::new_inherited(),
Expand All @@ -120,6 +124,7 @@ impl GlobalScope {
in_error_reporting_mode: Default::default(),
resource_threads: resource_threads,
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
origin: origin,
}
}

Expand Down Expand Up @@ -238,6 +243,11 @@ impl GlobalScope {
self.pipeline_id
}

/// Get the origin for this global scope
pub fn origin(&self) -> &MutableOrigin {
&self.origin
}

/// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url)
/// for this global scope.
pub fn api_base_url(&self) -> ServoUrl {
Expand Down
6 changes: 5 additions & 1 deletion components/script/dom/location.rs
Expand Up @@ -13,7 +13,7 @@ use dom::globalscope::GlobalScope;
use dom::urlhelper::UrlHelper;
use dom::window::Window;
use dom_struct::dom_struct;
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};

#[dom_struct]
pub struct Location {
Expand Down Expand Up @@ -60,6 +60,10 @@ impl Location {
pub fn reload_without_origin_check(&self) {
self.window.load_url(self.get_url(), true, true, None);
}

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

impl LocationMethods for Location {
Expand Down
10 changes: 8 additions & 2 deletions components/script/dom/window.rs
Expand Up @@ -85,7 +85,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::{Host, ImmutableOrigin, ServoUrl};
use servo_url::{Host, MutableOrigin, ImmutableOrigin, ServoUrl};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Cell;
Expand Down Expand Up @@ -286,6 +286,10 @@ impl Window {
}
}

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

pub fn get_cx(&self) -> *mut JSContext {
self.js_runtime.borrow().as_ref().unwrap().cx()
}
Expand Down Expand Up @@ -1749,6 +1753,7 @@ impl Window {
id: PipelineId,
parent_info: Option<(PipelineId, FrameType)>,
window_size: Option<WindowSizeData>,
origin: MutableOrigin,
webvr_thread: Option<IpcSender<WebVRMsg>>)
-> Root<Window> {
let layout_rpc: Box<LayoutRPC + Send> = {
Expand All @@ -1771,7 +1776,8 @@ impl Window {
constellation_chan,
scheduler_chan,
resource_threads,
timer_event_chan),
timer_event_chan,
origin),
script_chan: script_chan,
dom_manipulation_task_source: dom_task_source,
user_interaction_task_source: user_task_source,
Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/workerglobalscope.rs
Expand Up @@ -37,7 +37,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
use script_thread::RunnableWrapper;
use script_traits::{TimerEvent, TimerEventId};
use script_traits::WorkerGlobalScopeInit;
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};
use std::default::Default;
use std::rc::Rc;
use std::sync::Arc;
Expand All @@ -59,6 +59,7 @@ pub fn prepare_workerscope_init(global: &GlobalScope,
scheduler_chan: global.scheduler_chan().clone(),
worker_id: global.get_next_worker_id(),
pipeline_id: global.pipeline_id(),
origin: global.origin().immutable().clone(),
};

init
Expand Down Expand Up @@ -109,7 +110,8 @@ impl WorkerGlobalScope {
init.constellation_chan,
init.scheduler_chan,
init.resource_threads,
timer_event_chan),
timer_event_chan,
MutableOrigin::new(init.origin)),
worker_id: init.worker_id,
worker_url: worker_url,
closing: closing,
Expand Down
1 change: 1 addition & 0 deletions components/script/script_thread.rs
Expand Up @@ -1784,6 +1784,7 @@ impl ScriptThread {
incomplete.pipeline_id,
incomplete.parent_info,
incomplete.window_size,
incomplete.origin.clone(),
self.webvr_thread.clone());

// Initialize the browsing context for the window.
Expand Down
2 changes: 2 additions & 0 deletions components/script_traits/lib.rs
Expand Up @@ -777,6 +777,8 @@ pub struct WorkerGlobalScopeInit {
pub worker_id: WorkerId,
/// The pipeline id
pub pipeline_id: PipelineId,
/// The origin
pub origin: ImmutableOrigin,
}

/// Common entities representing a network load origin
Expand Down

0 comments on commit 4263b79

Please sign in to comment.