Introduce GlobalScope::pipeline_id

This commit is contained in:
Anthony Ramine 2016-10-01 17:24:54 +02:00
parent c6ff767625
commit 27f100b1d4
21 changed files with 103 additions and 85 deletions

View file

@ -23,7 +23,6 @@ use js::jsapi::{HandleValue, JS_GetClass, JSAutoCompartment, JSContext};
use js::jsapi::{JSObject, MutableHandleValue}; use js::jsapi::{JSObject, MutableHandleValue};
use js::rust::CompileOptionsWrapper; use js::rust::CompileOptionsWrapper;
use libc; use libc;
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads}; use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
use profile_traits::time; use profile_traits::time;
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan}; use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
@ -80,14 +79,6 @@ impl<'a> GlobalRef<'a> {
} }
} }
/// Get the `PipelineId` for this global scope.
pub fn pipeline_id(&self) -> PipelineId {
match *self {
GlobalRef::Window(window) => window.pipeline_id(),
GlobalRef::Worker(worker) => worker.pipeline_id(),
}
}
/// Get the `ResourceThreads` for this global scope. /// Get the `ResourceThreads` for this global scope.
pub fn resource_threads(&self) -> ResourceThreads { pub fn resource_threads(&self) -> ResourceThreads {
match *self { match *self {

View file

@ -4,6 +4,7 @@
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject}; use dom::bindings::conversions::{ToJSValConvertible, root_from_handleobject};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor};
use dom::bindings::reflector::{Reflectable, MutReflectable, Reflector}; use dom::bindings::reflector::{Reflectable, MutReflectable, Reflector};
@ -12,6 +13,7 @@ use dom::bindings::utils::WindowProxyHandler;
use dom::bindings::utils::get_array_index_from_id; use dom::bindings::utils::get_array_index_from_id;
use dom::document::Document; use dom::document::Document;
use dom::element::Element; use dom::element::Element;
use dom::globalscope::GlobalScope;
use dom::window::Window; use dom::window::Window;
use js::JSCLASS_IS_GLOBAL; use js::JSCLASS_IS_GLOBAL;
use js::glue::{CreateWrapperProxyHandler, ProxyTraps, NewWindowProxy}; use js::glue::{CreateWrapperProxyHandler, ProxyTraps, NewWindowProxy};
@ -150,7 +152,7 @@ impl BrowsingContext {
pub fn find_child_by_id(&self, pipeline_id: PipelineId) -> Option<Root<Window>> { pub fn find_child_by_id(&self, pipeline_id: PipelineId) -> Option<Root<Window>> {
self.children.borrow().iter().find(|context| { self.children.borrow().iter().find(|context| {
let window = context.active_window(); let window = context.active_window();
window.pipeline_id() == pipeline_id window.upcast::<GlobalScope>().pipeline_id() == pipeline_id
}).map(|context| context.active_window()) }).map(|context| context.active_window())
} }

View file

@ -11,7 +11,8 @@ pub struct Console(());
impl Console { impl Console {
fn send_to_devtools(global: GlobalRef, level: LogLevel, message: DOMString) { fn send_to_devtools(global: GlobalRef, level: LogLevel, message: DOMString) {
if let Some(chan) = global.as_global_scope().devtools_chan() { let global_scope = global.as_global_scope();
if let Some(chan) = global_scope.devtools_chan() {
let console_message = prepare_message(level, message); let console_message = prepare_message(level, message);
let worker_id = if let GlobalRef::Worker(worker) = global { let worker_id = if let GlobalRef::Worker(worker) = global {
Some(worker.get_worker_id()) Some(worker.get_worker_id())
@ -19,7 +20,7 @@ impl Console {
None None
}; };
let devtools_message = ScriptToDevtoolsControlMsg::ConsoleAPI( let devtools_message = ScriptToDevtoolsControlMsg::ConsoleAPI(
global.pipeline_id(), global_scope.pipeline_id(),
console_message, console_message,
worker_id); worker_id);
chan.send(devtools_message).unwrap(); chan.send(devtools_message).unwrap();

View file

@ -651,8 +651,9 @@ impl Document {
// Update the focus state for all elements in the focus chain. // Update the focus state for all elements in the focus chain.
// https://html.spec.whatwg.org/multipage/#focus-chain // https://html.spec.whatwg.org/multipage/#focus-chain
if focus_type == FocusType::Element { if focus_type == FocusType::Element {
let event = ConstellationMsg::Focus(self.window.pipeline_id()); let global_scope = self.window.upcast::<GlobalScope>();
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); let event = ConstellationMsg::Focus(global_scope.pipeline_id());
global_scope.constellation_chan().send(event).unwrap();
} }
} }
} }
@ -670,9 +671,10 @@ impl Document {
/// Sends this document's title to the compositor. /// Sends this document's title to the compositor.
pub fn send_title_to_compositor(&self) { pub fn send_title_to_compositor(&self) {
let window = self.window(); let window = self.window();
window.upcast::<GlobalScope>() let global_scope = window.upcast::<GlobalScope>();
global_scope
.constellation_chan() .constellation_chan()
.send(ConstellationMsg::SetTitle(window.pipeline_id(), .send(ConstellationMsg::SetTitle(global_scope.pipeline_id(),
Some(String::from(self.Title())))) Some(String::from(self.Title()))))
.unwrap(); .unwrap();
} }
@ -1358,10 +1360,11 @@ impl Document {
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) { pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
if PREFS.is_mozbrowser_enabled() { if PREFS.is_mozbrowser_enabled() {
if let Some((parent_pipeline_id, _)) = self.window.parent_info() { if let Some((parent_pipeline_id, _)) = self.window.parent_info() {
let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id, let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id,
Some(self.window.pipeline_id()), Some(global_scope.pipeline_id()),
event); event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); global_scope.constellation_chan().send(event).unwrap();
} }
} }
} }
@ -1381,10 +1384,11 @@ impl Document {
// //
// TODO: Should tick animation only when document is visible // TODO: Should tick animation only when document is visible
if !self.running_animation_callbacks.get() { if !self.running_animation_callbacks.get() {
let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::ChangeRunningAnimationsState( let event = ConstellationMsg::ChangeRunningAnimationsState(
self.window.pipeline_id(), global_scope.pipeline_id(),
AnimationState::AnimationCallbacksPresent); AnimationState::AnimationCallbacksPresent);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); global_scope.constellation_chan().send(event).unwrap();
} }
ident ident
@ -1420,9 +1424,10 @@ impl Document {
if self.animation_frame_list.borrow().is_empty() { if self.animation_frame_list.borrow().is_empty() {
mem::swap(&mut *self.animation_frame_list.borrow_mut(), mem::swap(&mut *self.animation_frame_list.borrow_mut(),
&mut animation_frame_list); &mut animation_frame_list);
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline_id(), let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::ChangeRunningAnimationsState(global_scope.pipeline_id(),
AnimationState::NoAnimationCallbacksPresent); AnimationState::NoAnimationCallbacksPresent);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); global_scope.constellation_chan().send(event).unwrap();
} }
self.running_animation_callbacks.set(false); self.running_animation_callbacks.set(false);
@ -1480,7 +1485,8 @@ impl Document {
let loader = self.loader.borrow(); let loader = self.loader.borrow();
if !loader.is_blocked() && !loader.events_inhibited() { if !loader.is_blocked() && !loader.events_inhibited() {
let win = self.window(); let win = self.window();
let msg = MainThreadScriptMsg::DocumentLoadsComplete(win.pipeline_id()); let msg = MainThreadScriptMsg::DocumentLoadsComplete(
win.upcast::<GlobalScope>().pipeline_id());
win.main_thread_script_chan().send(msg).unwrap(); win.main_thread_script_chan().send(msg).unwrap();
} }
} }
@ -1578,9 +1584,10 @@ impl Document {
} }
pub fn notify_constellation_load(&self) { pub fn notify_constellation_load(&self) {
let pipeline_id = self.window.pipeline_id(); let global_scope = self.window.upcast::<GlobalScope>();
let pipeline_id = global_scope.pipeline_id();
let load_event = ConstellationMsg::LoadComplete(pipeline_id); let load_event = ConstellationMsg::LoadComplete(pipeline_id);
self.window.upcast::<GlobalScope>().constellation_chan().send(load_event).unwrap(); global_scope.constellation_chan().send(load_event).unwrap();
} }
pub fn set_current_parser(&self, script: Option<ParserRef>) { pub fn set_current_parser(&self, script: Option<ParserRef>) {

View file

@ -11,6 +11,7 @@ use dom::crypto::Crypto;
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext}; use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
use msg::constellation_msg::PipelineId;
use profile_traits::{mem, time}; use profile_traits::{mem, time};
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest}; use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
use std::cell::Cell; use std::cell::Cell;
@ -24,6 +25,9 @@ pub struct GlobalScope {
crypto: MutNullableHeap<JS<Crypto>>, crypto: MutNullableHeap<JS<Crypto>>,
next_worker_id: Cell<WorkerId>, next_worker_id: Cell<WorkerId>,
/// Pipeline id associated with this global.
pipeline_id: PipelineId,
/// A flag to indicate whether the developer tools has requested /// A flag to indicate whether the developer tools has requested
/// live updates from the worker. /// live updates from the worker.
devtools_wants_updates: Cell<bool>, devtools_wants_updates: Cell<bool>,
@ -53,6 +57,7 @@ pub struct GlobalScope {
impl GlobalScope { impl GlobalScope {
pub fn new_inherited( pub fn new_inherited(
pipeline_id: PipelineId,
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>, devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
mem_profiler_chan: mem::ProfilerChan, mem_profiler_chan: mem::ProfilerChan,
time_profiler_chan: time::ProfilerChan, time_profiler_chan: time::ProfilerChan,
@ -63,6 +68,7 @@ impl GlobalScope {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
crypto: Default::default(), crypto: Default::default(),
next_worker_id: Cell::new(WorkerId(0)), next_worker_id: Cell::new(WorkerId(0)),
pipeline_id: pipeline_id,
devtools_wants_updates: Default::default(), devtools_wants_updates: Default::default(),
console_timers: DOMRefCell::new(Default::default()), console_timers: DOMRefCell::new(Default::default()),
devtools_chan: devtools_chan, devtools_chan: devtools_chan,
@ -149,6 +155,11 @@ impl GlobalScope {
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> { pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
&self.scheduler_chan &self.scheduler_chan
} }
/// Get the `PipelineId` for this global scope.
pub fn pipeline_id(&self) -> PipelineId {
self.pipeline_id
}
} }
fn timestamp_in_ms(time: Timespec) -> u64 { fn timestamp_in_ms(time: Timespec) -> u64 {

View file

@ -39,19 +39,21 @@ impl History {
impl History { impl History {
fn traverse_history(&self, direction: TraversalDirection) { fn traverse_history(&self, direction: TraversalDirection) {
let pipeline = self.window.pipeline_id(); let global_scope = self.window.upcast::<GlobalScope>();
let pipeline = global_scope.pipeline_id();
let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction); let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction);
let _ = self.window.upcast::<GlobalScope>().constellation_chan().send(msg); let _ = global_scope.constellation_chan().send(msg);
} }
} }
impl HistoryMethods for History { impl HistoryMethods for History {
// https://html.spec.whatwg.org/multipage/#dom-history-length // https://html.spec.whatwg.org/multipage/#dom-history-length
fn Length(&self) -> u32 { fn Length(&self) -> u32 {
let pipeline = self.window.pipeline_id(); let global_scope = self.window.upcast::<GlobalScope>();
let pipeline = global_scope.pipeline_id();
let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length.");
let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender); let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender);
let _ = self.window.upcast::<GlobalScope>().constellation_chan().send(msg); let _ = global_scope.constellation_chan().send(msg);
recv.recv().unwrap() recv.recv().unwrap()
} }

View file

@ -24,6 +24,7 @@ use dom::element::Element;
use dom::event::{EventBubbles, EventCancelable}; use dom::event::{EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use dom::file::File; use dom::file::File;
use dom::globalscope::GlobalScope;
use dom::htmlbuttonelement::HTMLButtonElement; use dom::htmlbuttonelement::HTMLButtonElement;
use dom::htmlcollection::CollectionFilter; use dom::htmlcollection::CollectionFilter;
use dom::htmldatalistelement::HTMLDataListElement; use dom::htmldatalistelement::HTMLDataListElement;
@ -436,7 +437,7 @@ impl HTMLFormElement {
// Step 2 // Step 2
let nav = box PlannedNavigation { let nav = box PlannedNavigation {
load_data: load_data, load_data: load_data,
pipeline_id: window.pipeline_id(), pipeline_id: window.upcast::<GlobalScope>().pipeline_id(),
script_chan: window.main_thread_script_chan().clone(), script_chan: window.main_thread_script_chan().clone(),
generation_id: self.generation_id.get(), generation_id: self.generation_id.get(),
form: Trusted::new(self) form: Trusted::new(self)

View file

@ -126,9 +126,10 @@ impl HTMLIFrameElement {
let private_iframe = self.privatebrowsing(); let private_iframe = self.privatebrowsing();
let frame_type = if self.Mozbrowser() { FrameType::MozBrowserIFrame } else { FrameType::IFrame }; let frame_type = if self.Mozbrowser() { FrameType::MozBrowserIFrame } else { FrameType::IFrame };
let global_scope = window.upcast::<GlobalScope>();
let load_info = IFrameLoadInfo { let load_info = IFrameLoadInfo {
load_data: load_data, load_data: load_data,
parent_pipeline_id: window.pipeline_id(), parent_pipeline_id: global_scope.pipeline_id(),
old_pipeline_id: old_pipeline_id, old_pipeline_id: old_pipeline_id,
new_pipeline_id: new_pipeline_id, new_pipeline_id: new_pipeline_id,
sandbox: sandboxed, sandbox: sandboxed,
@ -136,7 +137,7 @@ impl HTMLIFrameElement {
frame_type: frame_type, frame_type: frame_type,
replace: replace, replace: replace,
}; };
window.upcast::<GlobalScope>() global_scope
.constellation_chan() .constellation_chan()
.send(ConstellationMsg::ScriptLoadedURLInIFrame(load_info)) .send(ConstellationMsg::ScriptLoadedURLInIFrame(load_info))
.unwrap(); .unwrap();

View file

@ -267,7 +267,7 @@ impl HTMLLinkElement {
credentials_mode: CredentialsMode::Include, credentials_mode: CredentialsMode::Include,
use_url_credentials: true, use_url_credentials: true,
origin: document.url().clone(), origin: document.url().clone(),
pipeline_id: Some(self.global().r().pipeline_id()), pipeline_id: Some(self.global().r().as_global_scope().pipeline_id()),
referrer_url: Some(document.url().clone()), referrer_url: Some(document.url().clone()),
referrer_policy: referrer_policy, referrer_policy: referrer_policy,
.. RequestInit::default() .. RequestInit::default()

View file

@ -242,7 +242,7 @@ fn fetch_a_classic_script(script: &HTMLScriptElement,
_ => CredentialsMode::Include, _ => CredentialsMode::Include,
}, },
origin: doc.url().clone(), origin: doc.url().clone(),
pipeline_id: Some(script.global().r().pipeline_id()), pipeline_id: Some(script.global().r().as_global_scope().pipeline_id()),
referrer_url: Some(doc.url().clone()), referrer_url: Some(doc.url().clone()),
referrer_policy: doc.get_referrer_policy(), referrer_policy: doc.get_referrer_policy(),
.. RequestInit::default() .. RequestInit::default()

View file

@ -451,7 +451,7 @@ fn net_request_from_global(global: GlobalRef,
url: Url, url: Url,
is_service_worker_global_scope: bool) -> NetTraitsRequest { is_service_worker_global_scope: bool) -> NetTraitsRequest {
let origin = Origin::Origin(global.get_url().origin()); let origin = Origin::Origin(global.get_url().origin());
let pipeline_id = global.pipeline_id(); let pipeline_id = global.as_global_scope().pipeline_id();
NetTraitsRequest::new(url, NetTraitsRequest::new(url,
Some(origin), Some(origin),
is_service_worker_global_scope, is_service_worker_global_scope,

View file

@ -95,11 +95,14 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
return Err(Error::Type("Scope URL contains forbidden characters".to_owned())); return Err(Error::Type("Scope URL contains forbidden characters".to_owned()));
} }
let worker_registration = ServiceWorkerRegistration::new(self.global().r().as_global_scope(), let global = self.global();
let global = global.r();
let global_scope = global.as_global_scope();
let worker_registration = ServiceWorkerRegistration::new(global_scope,
script_url, script_url,
scope.clone(), scope.clone(),
self); self);
ScriptThread::set_registration(scope, &*worker_registration, self.global().r().pipeline_id()); ScriptThread::set_registration(scope, &*worker_registration, global_scope.pipeline_id());
Ok(worker_registration) Ok(worker_registration)
} }
} }

View file

@ -51,13 +51,13 @@ impl ServiceWorkerRegistration {
} }
pub fn create_scope_things(global: GlobalRef, script_url: Url) -> ScopeThings { pub fn create_scope_things(global: GlobalRef, script_url: Url) -> ScopeThings {
let global_scope = global.as_global_scope();
let worker_load_origin = WorkerScriptLoadOrigin { let worker_load_origin = WorkerScriptLoadOrigin {
referrer_url: None, referrer_url: None,
referrer_policy: None, referrer_policy: None,
pipeline_id: Some(global.pipeline_id()) pipeline_id: Some(global_scope.pipeline_id())
}; };
let global_scope = global.as_global_scope();
let worker_id = global_scope.get_next_worker_id(); let worker_id = global_scope.get_next_worker_id();
let devtools_chan = global_scope.devtools_chan().cloned(); let devtools_chan = global_scope.devtools_chan().cloned();
let init = prepare_workerscope_init(global, None); let init = prepare_workerscope_init(global, None);

View file

@ -206,7 +206,7 @@ impl Runnable for StorageEventRunnable {
assert!(UrlHelper::SameOrigin(&ev_url, &it_window.get_url())); assert!(UrlHelper::SameOrigin(&ev_url, &it_window.get_url()));
// TODO: Such a Document object is not necessarily fully active, but events fired on such // TODO: Such a Document object is not necessarily fully active, but events fired on such
// objects are ignored by the event loop until the Document becomes fully active again. // objects are ignored by the event loop until the Document becomes fully active again.
if ev_window.pipeline_id() != it_window.pipeline_id() { if ev_window.upcast::<GlobalScope>().pipeline_id() != it_window.upcast::<GlobalScope>().pipeline_id() {
storage_event.upcast::<Event>().fire(it_window.upcast()); storage_event.upcast::<Event>().fire(it_window.upcast());
} }
} }

View file

@ -181,9 +181,6 @@ pub struct Window {
/// Pending resize event, if any. /// Pending resize event, if any.
resize_event: Cell<Option<(WindowSizeData, WindowSizeType)>>, resize_event: Cell<Option<(WindowSizeData, WindowSizeType)>>,
/// Pipeline id associated with this page.
id: PipelineId,
/// Parent id associated with this page, if any. /// Parent id associated with this page, if any.
parent_info: Option<(PipelineId, FrameType)>, parent_info: Option<(PipelineId, FrameType)>,
@ -293,10 +290,6 @@ impl Window {
self.image_cache_chan.clone() self.image_cache_chan.clone()
} }
pub fn pipeline_id(&self) -> PipelineId {
self.id
}
pub fn parent_info(&self) -> Option<(PipelineId, FrameType)> { pub fn parent_info(&self) -> Option<(PipelineId, FrameType)> {
self.parent_info self.parent_info
} }
@ -430,9 +423,10 @@ impl WindowMethods for Window {
} }
let (sender, receiver) = ipc::channel().unwrap(); let (sender, receiver) = ipc::channel().unwrap();
self.upcast::<GlobalScope>() let global_scope = self.upcast::<GlobalScope>();
global_scope
.constellation_chan() .constellation_chan()
.send(ConstellationMsg::Alert(self.pipeline_id(), s.to_string(), sender)) .send(ConstellationMsg::Alert(global_scope.pipeline_id(), s.to_string(), sender))
.unwrap(); .unwrap();
let should_display_alert_dialog = receiver.recv().unwrap(); let should_display_alert_dialog = receiver.recv().unwrap();
@ -443,7 +437,9 @@ impl WindowMethods for Window {
// https://html.spec.whatwg.org/multipage/#dom-window-close // https://html.spec.whatwg.org/multipage/#dom-window-close
fn Close(&self) { fn Close(&self) {
self.main_thread_script_chan().send(MainThreadScriptMsg::ExitWindow(self.id.clone())).unwrap(); self.main_thread_script_chan()
.send(MainThreadScriptMsg::ExitWindow(self.upcast::<GlobalScope>().pipeline_id()))
.unwrap();
} }
// https://html.spec.whatwg.org/multipage/#dom-document-2 // https://html.spec.whatwg.org/multipage/#dom-document-2
@ -493,7 +489,7 @@ impl WindowMethods for Window {
args, args,
timeout, timeout,
IsInterval::NonInterval, IsInterval::NonInterval,
TimerSource::FromWindow(self.id.clone())) TimerSource::FromWindow(self.upcast::<GlobalScope>().pipeline_id()))
} }
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout // https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
@ -503,7 +499,7 @@ impl WindowMethods for Window {
args, args,
timeout, timeout,
IsInterval::NonInterval, IsInterval::NonInterval,
TimerSource::FromWindow(self.id.clone())) TimerSource::FromWindow(self.upcast::<GlobalScope>().pipeline_id()))
} }
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-cleartimeout // https://html.spec.whatwg.org/multipage/#dom-windowtimers-cleartimeout
@ -518,7 +514,7 @@ impl WindowMethods for Window {
args, args,
timeout, timeout,
IsInterval::Interval, IsInterval::Interval,
TimerSource::FromWindow(self.id.clone())) TimerSource::FromWindow(self.upcast::<GlobalScope>().pipeline_id()))
} }
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval // https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
@ -528,7 +524,7 @@ impl WindowMethods for Window {
args, args,
timeout, timeout,
IsInterval::Interval, IsInterval::Interval,
TimerSource::FromWindow(self.id.clone())) TimerSource::FromWindow(self.upcast::<GlobalScope>().pipeline_id()))
} }
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-clearinterval // https://html.spec.whatwg.org/multipage/#dom-windowtimers-clearinterval
@ -976,8 +972,10 @@ impl Window {
// TODO (farodin91): Raise an event to stop the current_viewport // TODO (farodin91): Raise an event to stop the current_viewport
self.update_viewport_for_scroll(x, y); self.update_viewport_for_scroll(x, y);
let message = ConstellationMsg::ScrollFragmentPoint(self.pipeline_id(), layer_id, point, smooth); let global_scope = self.upcast::<GlobalScope>();
self.upcast::<GlobalScope>().constellation_chan().send(message).unwrap(); let message = ConstellationMsg::ScrollFragmentPoint(
global_scope.pipeline_id(), layer_id, point, smooth);
global_scope.constellation_chan().send(message).unwrap();
} }
pub fn update_viewport_for_scroll(&self, x: f32, y: f32) { pub fn update_viewport_for_scroll(&self, x: f32, y: f32) {
@ -1032,7 +1030,7 @@ impl Window {
let for_display = query_type == ReflowQueryType::NoQuery; let for_display = query_type == ReflowQueryType::NoQuery;
if for_display && self.suppress_reflow.get() { if for_display && self.suppress_reflow.get() {
debug!("Suppressing reflow pipeline {} for goal {:?} reason {:?} before FirstLoad or RefreshTick", debug!("Suppressing reflow pipeline {} for goal {:?} reason {:?} before FirstLoad or RefreshTick",
self.id, goal, reason); self.upcast::<GlobalScope>().pipeline_id(), goal, reason);
return false; return false;
} }
@ -1049,7 +1047,7 @@ impl Window {
// On debug mode, print the reflow event information. // On debug mode, print the reflow event information.
if opts::get().relayout_event { if opts::get().relayout_event {
debug_reflow_events(self.id, &goal, &query_type, &reason); debug_reflow_events(self.upcast::<GlobalScope>().pipeline_id(), &goal, &query_type, &reason);
} }
let document = self.Document(); let document = self.Document();
@ -1154,8 +1152,9 @@ impl Window {
let ready_state = document.ReadyState(); let ready_state = document.ReadyState();
if ready_state == DocumentReadyState::Complete && !reftest_wait { if ready_state == DocumentReadyState::Complete && !reftest_wait {
let event = ConstellationMsg::SetDocumentState(self.id, DocumentState::Idle); let global_scope = self.upcast::<GlobalScope>();
self.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); let event = ConstellationMsg::SetDocumentState(global_scope.pipeline_id(), DocumentState::Idle);
global_scope.constellation_chan().send(event).unwrap();
} }
} }
@ -1264,12 +1263,12 @@ impl Window {
} }
let layer_id = self.layout_rpc.node_layer_id().layer_id; let layer_id = self.layout_rpc.node_layer_id().layer_id;
let pipeline_id = self.id;
let (send, recv) = ipc::channel::<Point2D<f32>>().unwrap(); let (send, recv) = ipc::channel::<Point2D<f32>>().unwrap();
self.upcast::<GlobalScope>() let global_scope = self.upcast::<GlobalScope>();
global_scope
.constellation_chan() .constellation_chan()
.send(ConstellationMsg::GetScrollOffset(pipeline_id, layer_id, send)) .send(ConstellationMsg::GetScrollOffset(global_scope.pipeline_id(), layer_id, send))
.unwrap(); .unwrap();
recv.recv().unwrap_or(Point2D::zero()) recv.recv().unwrap_or(Point2D::zero())
} }
@ -1345,7 +1344,7 @@ impl Window {
let referrer_policy = referrer_policy.or(doc.get_referrer_policy()); let referrer_policy = referrer_policy.or(doc.get_referrer_policy());
self.main_thread_script_chan().send( self.main_thread_script_chan().send(
MainThreadScriptMsg::Navigate(self.id, MainThreadScriptMsg::Navigate(self.upcast::<GlobalScope>().pipeline_id(),
LoadData::new(url, referrer_policy, Some(doc.url().clone())), LoadData::new(url, referrer_policy, Some(doc.url().clone())),
replace)).unwrap(); replace)).unwrap();
} }
@ -1388,7 +1387,7 @@ impl Window {
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle { pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
self.timers.schedule_callback(callback, self.timers.schedule_callback(callback,
duration, duration,
TimerSource::FromWindow(self.id.clone())) TimerSource::FromWindow(self.upcast::<GlobalScope>().pipeline_id()))
} }
pub fn unschedule_callback(&self, handle: OneshotTimerHandle) { pub fn unschedule_callback(&self, handle: OneshotTimerHandle) {
@ -1588,6 +1587,7 @@ impl Window {
let win = box Window { let win = box Window {
globalscope: globalscope:
GlobalScope::new_inherited( GlobalScope::new_inherited(
id,
devtools_chan, devtools_chan,
mem_profiler_chan, mem_profiler_chan,
time_profiler_chan, time_profiler_chan,
@ -1612,7 +1612,6 @@ impl Window {
local_storage: Default::default(), local_storage: Default::default(),
status: DOMRefCell::new(DOMString::new()), status: DOMRefCell::new(DOMString::new()),
timers: OneshotTimers::new(timer_event_chan, scheduler_chan), timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
id: id,
parent_info: parent_info, parent_info: parent_info,
dom_static: GlobalStaticData::new(), dom_static: GlobalStaticData::new(),
js_runtime: DOMRefCell::new(Some(runtime.clone())), js_runtime: DOMRefCell::new(Some(runtime.clone())),

View file

@ -84,17 +84,17 @@ impl Worker {
let worker = Worker::new(global.as_global_scope(), sender.clone(), closing.clone()); let worker = Worker::new(global.as_global_scope(), sender.clone(), closing.clone());
let worker_ref = Trusted::new(worker.r()); let worker_ref = Trusted::new(worker.r());
let global_scope = global.as_global_scope();
let worker_load_origin = WorkerScriptLoadOrigin { let worker_load_origin = WorkerScriptLoadOrigin {
referrer_url: None, referrer_url: None,
referrer_policy: None, referrer_policy: None,
pipeline_id: Some(global.pipeline_id()), pipeline_id: Some(global_scope.pipeline_id()),
}; };
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); let (devtools_sender, devtools_receiver) = ipc::channel().unwrap();
let global_scope = global.as_global_scope();
let worker_id = global_scope.get_next_worker_id(); let worker_id = global_scope.get_next_worker_id();
if let Some(ref chan) = global_scope.devtools_chan() { if let Some(ref chan) = global_scope.devtools_chan() {
let pipeline_id = global.pipeline_id(); let pipeline_id = global_scope.pipeline_id();
let title = format!("Worker for {}", worker_url); let title = format!("Worker for {}", worker_url);
let page_info = DevtoolsPageInfo { let page_info = DevtoolsPageInfo {
title: title, title: title,

View file

@ -60,6 +60,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
let time_profiler_chan = global_scope.time_profiler_chan().clone(); let time_profiler_chan = global_scope.time_profiler_chan().clone();
let constellation_chan = global_scope.constellation_chan().clone(); let constellation_chan = global_scope.constellation_chan().clone();
let scheduler_chan = global_scope.scheduler_chan().clone(); let scheduler_chan = global_scope.scheduler_chan().clone();
let pipeline_id = global_scope.pipeline_id();
let init = WorkerGlobalScopeInit { let init = WorkerGlobalScopeInit {
resource_threads: global.resource_threads(), resource_threads: global.resource_threads(),
mem_profiler_chan: mem_profiler_chan, mem_profiler_chan: mem_profiler_chan,
@ -69,7 +70,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
constellation_chan: constellation_chan, constellation_chan: constellation_chan,
scheduler_chan: scheduler_chan, scheduler_chan: scheduler_chan,
worker_id: worker_id, worker_id: worker_id,
pipeline_id: global.pipeline_id(), pipeline_id: pipeline_id,
}; };
init init
@ -81,7 +82,6 @@ pub struct WorkerGlobalScope {
globalscope: GlobalScope, globalscope: GlobalScope,
worker_id: WorkerId, worker_id: WorkerId,
pipeline_id: PipelineId,
worker_url: Url, worker_url: Url,
#[ignore_heap_size_of = "Arc"] #[ignore_heap_size_of = "Arc"]
closing: Option<Arc<AtomicBool>>, closing: Option<Arc<AtomicBool>>,
@ -120,13 +120,13 @@ impl WorkerGlobalScope {
WorkerGlobalScope { WorkerGlobalScope {
globalscope: globalscope:
GlobalScope::new_inherited( GlobalScope::new_inherited(
init.pipeline_id,
init.to_devtools_sender, init.to_devtools_sender,
init.mem_profiler_chan, init.mem_profiler_chan,
init.time_profiler_chan, init.time_profiler_chan,
init.constellation_chan, init.constellation_chan,
init.scheduler_chan.clone()), init.scheduler_chan.clone()),
worker_id: init.worker_id, worker_id: init.worker_id,
pipeline_id: init.pipeline_id,
worker_url: worker_url, worker_url: worker_url,
closing: closing, closing: closing,
runtime: runtime, runtime: runtime,
@ -207,7 +207,7 @@ impl WorkerGlobalScope {
fn do_flush_promise_jobs(&self) { fn do_flush_promise_jobs(&self) {
self.promise_job_queue.flush_promise_jobs(|id| { self.promise_job_queue.flush_promise_jobs(|id| {
assert_eq!(self.pipeline_id(), id); assert_eq!(self.upcast::<GlobalScope>().pipeline_id(), id);
Some(GlobalRoot::Worker(Root::from_ref(self))) Some(GlobalRoot::Worker(Root::from_ref(self)))
}); });
} }
@ -221,7 +221,7 @@ impl LoadOrigin for WorkerGlobalScope {
None None
} }
fn pipeline_id(&self) -> Option<PipelineId> { fn pipeline_id(&self) -> Option<PipelineId> {
Some(self.pipeline_id()) Some(self.upcast::<GlobalScope>().pipeline_id())
} }
} }
@ -401,10 +401,6 @@ impl WorkerGlobalScope {
FileReadingTaskSource(self.script_chan()) FileReadingTaskSource(self.script_chan())
} }
pub fn pipeline_id(&self) -> PipelineId {
self.pipeline_id
}
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) { pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>(); let dedicated = self.downcast::<DedicatedWorkerGlobalScope>();
if let Some(dedicated) = dedicated { if let Some(dedicated) = dedicated {

View file

@ -284,7 +284,7 @@ impl LoadOrigin for XMLHttpRequest {
fn pipeline_id(&self) -> Option<PipelineId> { fn pipeline_id(&self) -> Option<PipelineId> {
let global = self.global(); let global = self.global();
Some(global.r().pipeline_id()) Some(global.r().as_global_scope().pipeline_id())
} }
} }
@ -1208,7 +1208,10 @@ impl XMLHttpRequest {
let decoded = charset.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap(); let decoded = charset.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap();
let document = self.new_doc(IsHTMLDocument::HTMLDocument); let document = self.new_doc(IsHTMLDocument::HTMLDocument);
// TODO: Disable scripting while parsing // TODO: Disable scripting while parsing
parse_html(document.r(), DOMString::from(decoded), wr.get_url(), ParseContext::Owner(Some(wr.pipeline_id()))); parse_html(document.r(),
DOMString::from(decoded),
wr.get_url(),
ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
document document
} }
@ -1222,7 +1225,7 @@ impl XMLHttpRequest {
parse_xml(document.r(), parse_xml(document.r(),
DOMString::from(decoded), DOMString::from(decoded),
wr.get_url(), wr.get_url(),
xml::ParseContext::Owner(Some(wr.pipeline_id()))); xml::ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
document document
} }

View file

@ -178,7 +178,7 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext,
_data: *mut c_void) -> bool { _data: *mut c_void) -> bool {
let result = panic::catch_unwind(AssertUnwindSafe(|| { let result = panic::catch_unwind(AssertUnwindSafe(|| {
let global = global_root_from_object(job.get()); let global = global_root_from_object(job.get());
let pipeline = global.r().pipeline_id(); let pipeline = global.r().as_global_scope().pipeline_id();
global.r().enqueue_promise_job(EnqueuedPromiseCallback { global.r().enqueue_promise_job(EnqueuedPromiseCallback {
callback: PromiseJobCallback::new(job.get()), callback: PromiseJobCallback::new(job.get()),
pipeline: pipeline, pipeline: pipeline,

View file

@ -650,7 +650,7 @@ impl ScriptThread {
let window = context.active_window(); let window = context.active_window();
let resize_event = window.steal_resize_event(); let resize_event = window.steal_resize_event();
match resize_event { match resize_event {
Some(size) => resizes.push((window.pipeline_id(), size)), Some(size) => resizes.push((window.upcast::<GlobalScope>().pipeline_id(), size)),
None => () None => ()
} }
} }
@ -1501,7 +1501,7 @@ impl ScriptThread {
// If root is being exited, shut down all contexts // If root is being exited, shut down all contexts
let context = self.root_browsing_context(); let context = self.root_browsing_context();
let window = context.active_window(); let window = context.active_window();
if window.pipeline_id() == id { if window.upcast::<GlobalScope>().pipeline_id() == id {
debug!("shutting down layout for root context {:?}", id); debug!("shutting down layout for root context {:?}", id);
shut_down_layout(&context); shut_down_layout(&context);
let _ = self.constellation_chan.send(ConstellationMsg::PipelineExited(id)); let _ = self.constellation_chan.send(ConstellationMsg::PipelineExited(id));

View file

@ -19,6 +19,7 @@ use dom::bindings::js::Root;
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::browsingcontext::BrowsingContext; use dom::browsingcontext::BrowsingContext;
use dom::element::Element; use dom::element::Element;
use dom::globalscope::GlobalScope;
use dom::htmlelement::HTMLElement; use dom::htmlelement::HTMLElement;
use dom::htmliframeelement::HTMLIFrameElement; use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlinputelement::HTMLInputElement; use dom::htmlinputelement::HTMLInputElement;
@ -142,7 +143,7 @@ pub fn handle_get_frame_id(context: &BrowsingContext,
} }
}; };
let frame_id = window.map(|x| x.map(|x| x.pipeline_id())); let frame_id = window.map(|x| x.map(|x| x.upcast::<GlobalScope>().pipeline_id()));
reply.send(frame_id).unwrap() reply.send(frame_id).unwrap()
} }