Skip to content

Commit 234583e

Browse files
authored
Auto merge of #27171 - gterzian:fix_postmessage, r=<try>
Webmessaging: add more source info to message <!-- Please describe your changes on the following line: --> FIX #27146 FIX #24066 FIX #22647 FIX #22154 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./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. -->
2 parents c73734c + 68e5426 commit 234583e

File tree

9 files changed

+150
-62
lines changed

9 files changed

+150
-62
lines changed

components/constellation/constellation.rs

Lines changed: 56 additions & 7 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,
@@ -1845,8 +1871,7 @@ where
18451871
let result = self
18461872
.pipelines
18471873
.get(&pipeline_id)
1848-
.and_then(|pipeline| self.browsing_contexts.get(&pipeline.browsing_context_id))
1849-
.map(|ctx| (ctx.id, ctx.parent_pipeline_id));
1874+
.map(|pipeline| pipeline.browsing_context_id);
18501875
if let Err(e) = sender.send(result) {
18511876
warn!(
18521877
"Sending reply to get browsing context info failed ({:?}).",
@@ -3947,8 +3972,10 @@ where
39473972
self.update_activity(new_pipeline_id);
39483973

39493974
if let Some(parent_pipeline_id) = parent_pipeline_id {
3975+
let ancestors = self.get_ancestors_for_parent(Some(parent_pipeline_id.clone()));
39503976
let msg = ConstellationControlMsg::UpdatePipelineId(
39513977
parent_pipeline_id,
3978+
ancestors,
39523979
browsing_context_id,
39533980
top_level_id,
39543981
new_pipeline_id,
@@ -4149,14 +4176,34 @@ where
41494176
},
41504177
Some(browsing_context) => browsing_context.pipeline_id,
41514178
};
4152-
let source_browsing_context = match self.pipelines.get(&source_pipeline) {
4153-
Some(pipeline) => pipeline.top_level_browsing_context_id,
4154-
None => return warn!("PostMessage from closed pipeline {:?}", source_pipeline),
4155-
};
4179+
4180+
let (source_top_level_browsing_context_id, source_browsing_context_id) =
4181+
match self.pipelines.get(&source_pipeline) {
4182+
Some(pipeline) => (
4183+
pipeline.top_level_browsing_context_id,
4184+
pipeline.browsing_context_id,
4185+
),
4186+
None => return warn!("PostMessage from closed pipeline {:?}", source_pipeline),
4187+
};
4188+
4189+
let source_parent_id = self
4190+
.browsing_contexts
4191+
.get(&source_browsing_context_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
4197+
.and_then(|parent_id| self.pipelines.get(&parent_id))
4198+
.map(|pipeline| pipeline.browsing_context_id);
4199+
41564200
let msg = ConstellationControlMsg::PostMessage {
41574201
target: pipeline_id,
4202+
source_parent,
4203+
ancestors,
41584204
source: source_pipeline,
4159-
source_browsing_context: source_browsing_context,
4205+
source_browsing_context: source_browsing_context_id,
4206+
source_top_level_browsing_context: source_top_level_browsing_context_id,
41604207
target_origin: origin,
41614208
source_origin,
41624209
data,
@@ -4901,9 +4948,11 @@ where
49014948
},
49024949
};
49034950
if let Some(parent_pipeline_id) = parent_pipeline_id {
4951+
let ancestors = self.get_ancestors_for_parent(Some(parent_pipeline_id));
49044952
if let Some(parent_pipeline) = self.pipelines.get(&parent_pipeline_id) {
49054953
let msg = ConstellationControlMsg::UpdatePipelineId(
49064954
parent_pipeline_id,
4955+
ancestors,
49074956
change.browsing_context_id,
49084957
change.top_level_browsing_context_id,
49094958
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
@@ -3966,7 +3966,7 @@ impl DocumentMethods for Document {
39663966
// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
39673967
fn HasFocus(&self) -> bool {
39683968
// Step 1-2.
3969-
if self.window().parent_info().is_none() && self.is_fully_active() {
3969+
if !self.window().has_parent() && self.is_fully_active() {
39703970
return true;
39713971
}
39723972
// 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)