Skip to content

Commit 11f3ca3

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 d93e67a + ada2f9c commit 11f3ca3

File tree

8 files changed

+96
-77
lines changed

8 files changed

+96
-77
lines changed

components/constellation/constellation.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,14 @@ where
10871087
pipeline_id, browsing_context_id
10881088
);
10891089

1090-
let (event_loop, host) = match sandbox {
1091-
IFrameSandboxState::IFrameSandboxed => (None, None),
1090+
let (parent_info, event_loop, host) = match sandbox {
1091+
IFrameSandboxState::IFrameSandboxed => (None, None, None),
10921092
IFrameSandboxState::IFrameUnsandboxed => {
10931093
// If this is an about:blank load, it must share the creator's event loop.
10941094
// This must match the logic in the script thread when determining the proper origin.
10951095
if load_data.url.as_str() != "about:blank" {
10961096
match reg_host(&load_data.url) {
1097-
None => (None, None),
1097+
None => (None, None, None),
10981098
Some(host) => {
10991099
match self.get_event_loop(
11001100
&host,
@@ -1103,13 +1103,13 @@ where
11031103
) {
11041104
Err(err) => {
11051105
warn!("{}", err);
1106-
(None, Some(host))
1106+
(None, None, Some(host))
11071107
},
11081108
Ok(event_loop) => {
11091109
if let Some(event_loop) = event_loop.upgrade() {
1110-
(Some(event_loop), None)
1110+
(None, Some(event_loop), None)
11111111
} else {
1112-
(None, Some(host))
1112+
(None, None, Some(host))
11131113
}
11141114
},
11151115
}
@@ -1118,14 +1118,18 @@ where
11181118
} else if let Some(parent) =
11191119
parent_pipeline_id.and_then(|pipeline_id| self.pipelines.get(&pipeline_id))
11201120
{
1121-
(Some(parent.event_loop.clone()), None)
1121+
(
1122+
Some(parent.browsing_context_id),
1123+
Some(parent.event_loop.clone()),
1124+
None,
1125+
)
11221126
} else if let Some(creator) = load_data
11231127
.creator_pipeline_id
11241128
.and_then(|pipeline_id| self.pipelines.get(&pipeline_id))
11251129
{
1126-
(Some(creator.event_loop.clone()), None)
1130+
(None, Some(creator.event_loop.clone()), None)
11271131
} else {
1128-
(None, None)
1132+
(None, None, None)
11291133
}
11301134
},
11311135
};
@@ -1140,7 +1144,7 @@ where
11401144
id: pipeline_id,
11411145
browsing_context_id,
11421146
top_level_browsing_context_id,
1143-
parent_pipeline_id,
1147+
parent_info,
11441148
opener,
11451149
script_to_constellation_chan: ScriptToConstellationChan {
11461150
sender: self.script_sender.clone(),
@@ -1845,8 +1849,7 @@ where
18451849
let result = self
18461850
.pipelines
18471851
.get(&pipeline_id)
1848-
.and_then(|pipeline| self.browsing_contexts.get(&pipeline.browsing_context_id))
1849-
.map(|ctx| (ctx.id, ctx.parent_pipeline_id));
1852+
.map(|pipeline| pipeline.browsing_context_id);
18501853
if let Err(e) = sender.send(result) {
18511854
warn!(
18521855
"Sending reply to get browsing context info failed ({:?}).",
@@ -4149,14 +4152,29 @@ where
41494152
},
41504153
Some(browsing_context) => browsing_context.pipeline_id,
41514154
};
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-
};
4155+
4156+
let (source_top_level_browsing_context_id, source_browsing_context_id) =
4157+
match self.pipelines.get(&source_pipeline) {
4158+
Some(pipeline) => (
4159+
pipeline.top_level_browsing_context_id,
4160+
pipeline.browsing_context_id,
4161+
),
4162+
None => return warn!("PostMessage from closed pipeline {:?}", source_pipeline),
4163+
};
4164+
4165+
let source_parent = self
4166+
.browsing_contexts
4167+
.get(&source_browsing_context_id)
4168+
.and_then(|bc| bc.parent_pipeline_id)
4169+
.and_then(|parent_id| self.pipelines.get(&parent_id))
4170+
.map(|pipeline| pipeline.browsing_context_id);
4171+
41564172
let msg = ConstellationControlMsg::PostMessage {
41574173
target: pipeline_id,
4174+
source_parent,
41584175
source: source_pipeline,
4159-
source_browsing_context: source_browsing_context,
4176+
source_browsing_context: source_browsing_context_id,
4177+
source_top_level_browsing_context: source_top_level_browsing_context_id,
41604178
target_origin: origin,
41614179
source_origin,
41624180
data,

components/constellation/pipeline.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ pub struct InitialPipelineState {
113113
/// The ID of the top-level browsing context that contains this Pipeline.
114114
pub top_level_browsing_context_id: TopLevelBrowsingContextId,
115115

116-
/// The ID of the parent pipeline and frame type, if any.
116+
/// The browsing context of the parent of this pipeline.
117117
/// If `None`, this is the root.
118-
pub parent_pipeline_id: Option<PipelineId>,
118+
pub parent_info: Option<BrowsingContextId>,
119119

120120
pub opener: Option<BrowsingContextId>,
121121

@@ -225,7 +225,7 @@ impl Pipeline {
225225
let (script_chan, bhm_control_chan) = match state.event_loop {
226226
Some(script_chan) => {
227227
let new_layout_info = NewLayoutInfo {
228-
parent_info: state.parent_pipeline_id,
228+
parent_info: state.parent_info,
229229
new_pipeline_id: state.id,
230230
browsing_context_id: state.browsing_context_id,
231231
top_level_browsing_context_id: state.top_level_browsing_context_id,
@@ -274,7 +274,7 @@ impl Pipeline {
274274
id: state.id,
275275
browsing_context_id: state.browsing_context_id,
276276
top_level_browsing_context_id: state.top_level_browsing_context_id,
277-
parent_pipeline_id: state.parent_pipeline_id,
277+
parent_info: state.parent_info,
278278
opener: state.opener,
279279
script_to_constellation_chan: state.script_to_constellation_chan.clone(),
280280
namespace_request_sender: state.namespace_request_sender,
@@ -484,7 +484,7 @@ pub struct UnprivilegedPipelineContent {
484484
id: PipelineId,
485485
top_level_browsing_context_id: TopLevelBrowsingContextId,
486486
browsing_context_id: BrowsingContextId,
487-
parent_pipeline_id: Option<PipelineId>,
487+
parent_info: Option<BrowsingContextId>,
488488
opener: Option<BrowsingContextId>,
489489
namespace_request_sender: IpcSender<PipelineNamespaceRequest>,
490490
script_to_constellation_chan: ScriptToConstellationChan,
@@ -545,7 +545,7 @@ impl UnprivilegedPipelineContent {
545545
id: self.id,
546546
browsing_context_id: self.browsing_context_id,
547547
top_level_browsing_context_id: self.top_level_browsing_context_id,
548-
parent_info: self.parent_pipeline_id,
548+
parent_info: self.parent_info,
549549
opener: self.opener,
550550
control_chan: self.script_chan.clone(),
551551
control_port: self.script_port,
@@ -589,7 +589,7 @@ impl UnprivilegedPipelineContent {
589589
self.id,
590590
self.top_level_browsing_context_id,
591591
self.load_data.url,
592-
self.parent_pipeline_id.is_some(),
592+
self.parent_info.is_some(),
593593
layout_pair,
594594
self.pipeline_port,
595595
background_hang_monitor_register,

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().is_top_level() && self.is_fully_active() {
39583958
return true;
39593959
}
39603960
// TODO Step 3.

components/script/dom/htmliframeelement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl HTMLIFrameElement {
198198
.unwrap();
199199

200200
let new_layout_info = NewLayoutInfo {
201-
parent_info: Some(global_scope.pipeline_id()),
201+
parent_info: Some(window.window_proxy().browsing_context_id()),
202202
new_pipeline_id: new_pipeline_id,
203203
browsing_context_id: browsing_context_id,
204204
top_level_browsing_context_id: top_level_browsing_context_id,

components/script/dom/window.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub struct Window {
214214
resize_event: Cell<Option<(WindowSizeData, WindowSizeType)>>,
215215

216216
/// Parent id associated with this page, if any.
217-
parent_info: Option<PipelineId>,
217+
parent_info: Option<BrowsingContextId>,
218218

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

428-
pub fn parent_info(&self) -> Option<PipelineId> {
429-
self.parent_info
430-
}
431-
432428
pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
433429
let (tx, rx) = unbounded();
434430
(Box::new(SendableMainThreadScriptChan(tx)), Box::new(rx))
@@ -2238,6 +2234,10 @@ impl Window {
22382234
self.current_state.get() == WindowState::Alive
22392235
}
22402236

2237+
pub fn parent_info(&self) -> Option<BrowsingContextId> {
2238+
self.parent_info.clone()
2239+
}
2240+
22412241
// https://html.spec.whatwg.org/multipage/#top-level-browsing-context
22422242
pub fn is_top_level(&self) -> bool {
22432243
self.parent_info.is_none()
@@ -2339,7 +2339,7 @@ impl Window {
23392339
scheduler_chan: IpcSender<TimerSchedulerMsg>,
23402340
layout_chan: Sender<Msg>,
23412341
pipelineid: PipelineId,
2342-
parent_info: Option<PipelineId>,
2342+
parent_info: Option<BrowsingContextId>,
23432343
window_size: WindowSizeData,
23442344
origin: MutableOrigin,
23452345
navigation_start: u64,

0 commit comments

Comments
 (0)