Skip to content

Commit 68e5426

Browse files
committed
add browsing context ancestor info to various constellation -> script integrations
1 parent b968142 commit 68e5426

File tree

8 files changed

+120
-50
lines changed

8 files changed

+120
-50
lines changed

components/constellation/constellation.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,11 +1136,14 @@ where
11361136
self.public_resource_threads.clone()
11371137
};
11381138

1139+
let ancestors = self.get_ancestors_for_parent(parent_pipeline_id.clone());
1140+
11391141
let result = Pipeline::spawn::<Message, LTF, STF>(InitialPipelineState {
11401142
id: pipeline_id,
11411143
browsing_context_id,
11421144
top_level_browsing_context_id,
11431145
parent_pipeline_id,
1146+
ancestors,
11441147
opener,
11451148
script_to_constellation_chan: ScriptToConstellationChan {
11461149
sender: self.script_sender.clone(),
@@ -1208,6 +1211,29 @@ where
12081211
self.pipelines.insert(pipeline_id, pipeline.pipeline);
12091212
}
12101213

1214+
fn get_ancestors_for_parent(
1215+
&self,
1216+
mut parent_pipeline_id: Option<PipelineId>,
1217+
) -> VecDeque<BrowsingContextId> {
1218+
let mut ancestors = VecDeque::new();
1219+
1220+
while let Some(parent_id) = parent_pipeline_id {
1221+
match self.pipelines.get(&parent_id) {
1222+
Some(pipeline) => {
1223+
ancestors.push_back(pipeline.browsing_context_id);
1224+
if let Some(bc) = self.browsing_contexts.get(&pipeline.browsing_context_id) {
1225+
parent_pipeline_id = bc.parent_pipeline_id;
1226+
} else {
1227+
warn!("Unknow browsing context {:?}", pipeline.browsing_context_id)
1228+
}
1229+
},
1230+
None => warn!("Pipeline with closed parent {:?}", parent_id),
1231+
};
1232+
}
1233+
1234+
ancestors
1235+
}
1236+
12111237
/// Get an iterator for the fully active browsing contexts in a subtree.
12121238
fn fully_active_descendant_browsing_contexts_iter(
12131239
&self,
@@ -3946,8 +3972,10 @@ where
39463972
self.update_activity(new_pipeline_id);
39473973

39483974
if let Some(parent_pipeline_id) = parent_pipeline_id {
3975+
let ancestors = self.get_ancestors_for_parent(Some(parent_pipeline_id.clone()));
39493976
let msg = ConstellationControlMsg::UpdatePipelineId(
39503977
parent_pipeline_id,
3978+
ancestors,
39513979
browsing_context_id,
39523980
top_level_id,
39533981
new_pipeline_id,
@@ -4158,16 +4186,21 @@ where
41584186
None => return warn!("PostMessage from closed pipeline {:?}", source_pipeline),
41594187
};
41604188

4161-
let source_parent = self
4189+
let source_parent_id = self
41624190
.browsing_contexts
41634191
.get(&source_browsing_context_id)
4164-
.and_then(|bc| bc.parent_pipeline_id)
4192+
.and_then(|bc| bc.parent_pipeline_id);
4193+
4194+
let ancestors = self.get_ancestors_for_parent(source_parent_id.clone());
4195+
4196+
let source_parent = source_parent_id
41654197
.and_then(|parent_id| self.pipelines.get(&parent_id))
41664198
.map(|pipeline| pipeline.browsing_context_id);
41674199

41684200
let msg = ConstellationControlMsg::PostMessage {
41694201
target: pipeline_id,
41704202
source_parent,
4203+
ancestors,
41714204
source: source_pipeline,
41724205
source_browsing_context: source_browsing_context_id,
41734206
source_top_level_browsing_context: source_top_level_browsing_context_id,
@@ -4915,9 +4948,11 @@ where
49154948
},
49164949
};
49174950
if let Some(parent_pipeline_id) = parent_pipeline_id {
4951+
let ancestors = self.get_ancestors_for_parent(Some(parent_pipeline_id));
49184952
if let Some(parent_pipeline) = self.pipelines.get(&parent_pipeline_id) {
49194953
let msg = ConstellationControlMsg::UpdatePipelineId(
49204954
parent_pipeline_id,
4955+
ancestors,
49214956
change.browsing_context_id,
49224957
change.top_level_browsing_context_id,
49234958
pipeline_id,

components/constellation/pipeline.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use servo_config::opts::{self, Opts};
4444
use servo_config::{prefs, prefs::PrefValue};
4545
use servo_url::ServoUrl;
4646
use std::borrow::Cow;
47-
use std::collections::{HashMap, HashSet};
47+
use std::collections::{HashMap, HashSet, VecDeque};
4848
use std::rc::Rc;
4949
use std::sync::atomic::AtomicBool;
5050
use std::sync::Arc;
@@ -117,6 +117,10 @@ pub struct InitialPipelineState {
117117
/// If `None`, this is the root.
118118
pub parent_pipeline_id: Option<PipelineId>,
119119

120+
/// The ID of all ancestors, if any.
121+
/// If empty, this is the root.
122+
pub ancestors: VecDeque<BrowsingContextId>,
123+
120124
pub opener: Option<BrowsingContextId>,
121125

122126
/// A channel to the associated constellation.
@@ -226,6 +230,7 @@ impl Pipeline {
226230
Some(script_chan) => {
227231
let new_layout_info = NewLayoutInfo {
228232
parent_info: state.parent_pipeline_id,
233+
ancestors: state.ancestors,
229234
new_pipeline_id: state.id,
230235
browsing_context_id: state.browsing_context_id,
231236
top_level_browsing_context_id: state.top_level_browsing_context_id,
@@ -275,6 +280,7 @@ impl Pipeline {
275280
browsing_context_id: state.browsing_context_id,
276281
top_level_browsing_context_id: state.top_level_browsing_context_id,
277282
parent_pipeline_id: state.parent_pipeline_id,
283+
ancestors: state.ancestors,
278284
opener: state.opener,
279285
script_to_constellation_chan: state.script_to_constellation_chan.clone(),
280286
namespace_request_sender: state.namespace_request_sender,
@@ -485,6 +491,7 @@ pub struct UnprivilegedPipelineContent {
485491
top_level_browsing_context_id: TopLevelBrowsingContextId,
486492
browsing_context_id: BrowsingContextId,
487493
parent_pipeline_id: Option<PipelineId>,
494+
ancestors: VecDeque<BrowsingContextId>,
488495
opener: Option<BrowsingContextId>,
489496
namespace_request_sender: IpcSender<PipelineNamespaceRequest>,
490497
script_to_constellation_chan: ScriptToConstellationChan,
@@ -546,6 +553,7 @@ impl UnprivilegedPipelineContent {
546553
browsing_context_id: self.browsing_context_id,
547554
top_level_browsing_context_id: self.top_level_browsing_context_id,
548555
parent_info: self.parent_pipeline_id,
556+
ancestors: self.ancestors,
549557
opener: self.opener,
550558
control_chan: self.script_chan.clone(),
551559
control_port: self.script_port,

components/script/dom/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ impl DocumentMethods for Document {
39543954
// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
39553955
fn HasFocus(&self) -> bool {
39563956
// Step 1-2.
3957-
if self.window().parent_info().is_none() && self.is_fully_active() {
3957+
if !self.window().has_parent() && self.is_fully_active() {
39583958
return true;
39593959
}
39603960
// TODO Step 3.

components/script/dom/htmliframeelement.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl HTMLIFrameElement {
199199

200200
let new_layout_info = NewLayoutInfo {
201201
parent_info: Some(global_scope.pipeline_id()),
202+
ancestors: window.ancestors(),
202203
new_pipeline_id: new_pipeline_id,
203204
browsing_context_id: browsing_context_id,
204205
top_level_browsing_context_id: top_level_browsing_context_id,

components/script/dom/window.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ use std::borrow::Cow;
125125
use std::borrow::ToOwned;
126126
use std::cell::Cell;
127127
use std::collections::hash_map::Entry;
128-
use std::collections::{HashMap, HashSet};
128+
use std::collections::{HashMap, HashSet, VecDeque};
129129
use std::default::Default;
130130
use std::env;
131131
use std::io::{stderr, stdout, Write};
@@ -213,8 +213,8 @@ pub struct Window {
213213
/// Pending resize event, if any.
214214
resize_event: Cell<Option<(WindowSizeData, WindowSizeType)>>,
215215

216-
/// Parent id associated with this page, if any.
217-
parent_info: Option<PipelineId>,
216+
/// The ancestors browsing contexts, if any.
217+
ancestors: VecDeque<BrowsingContextId>,
218218

219219
/// Global static data related to the DOM.
220220
dom_static: GlobalStaticData,
@@ -425,8 +425,8 @@ impl Window {
425425
&self.script_chan.0
426426
}
427427

428-
pub fn parent_info(&self) -> Option<PipelineId> {
429-
self.parent_info
428+
pub fn has_parent(&self) -> bool {
429+
!self.ancestors.is_empty()
430430
}
431431

432432
pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
@@ -2240,7 +2240,11 @@ impl Window {
22402240

22412241
// https://html.spec.whatwg.org/multipage/#top-level-browsing-context
22422242
pub fn is_top_level(&self) -> bool {
2243-
self.parent_info.is_none()
2243+
!self.has_parent()
2244+
}
2245+
2246+
pub fn ancestors(&self) -> VecDeque<BrowsingContextId> {
2247+
self.ancestors.clone()
22442248
}
22452249

22462250
/// Evaluate media query lists and report changes
@@ -2339,7 +2343,7 @@ impl Window {
23392343
scheduler_chan: IpcSender<TimerSchedulerMsg>,
23402344
layout_chan: Sender<Msg>,
23412345
pipelineid: PipelineId,
2342-
parent_info: Option<PipelineId>,
2346+
ancestors: VecDeque<BrowsingContextId>,
23432347
window_size: WindowSizeData,
23442348
origin: MutableOrigin,
23452349
navigation_start: u64,
@@ -2403,7 +2407,7 @@ impl Window {
24032407
session_storage: Default::default(),
24042408
local_storage: Default::default(),
24052409
status: DomRefCell::new(DOMString::new()),
2406-
parent_info,
2410+
ancestors,
24072411
dom_static: GlobalStaticData::new(),
24082412
js_runtime: DomRefCell::new(Some(runtime.clone())),
24092413
bluetooth_thread,

components/script/dom/windowproxy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl WindowProxy {
319319
let (pipeline_sender, pipeline_receiver) = ipc::channel().unwrap();
320320
let new_layout_info = NewLayoutInfo {
321321
parent_info: None,
322+
ancestors: window.ancestors(),
322323
new_pipeline_id: new_pipeline_id,
323324
browsing_context_id: new_browsing_context_id,
324325
top_level_browsing_context_id: new_top_level_browsing_context_id,

0 commit comments

Comments
 (0)