Skip to content

Commit b968142

Browse files
committed
webmessaging: add more source info to message
1 parent 39e3beb commit b968142

File tree

4 files changed

+60
-42
lines changed

4 files changed

+60
-42
lines changed

components/constellation/constellation.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,8 +1845,7 @@ where
18451845
let result = self
18461846
.pipelines
18471847
.get(&pipeline_id)
1848-
.and_then(|pipeline| self.browsing_contexts.get(&pipeline.browsing_context_id))
1849-
.map(|ctx| (ctx.id, ctx.parent_pipeline_id));
1848+
.map(|pipeline| pipeline.browsing_context_id);
18501849
if let Err(e) = sender.send(result) {
18511850
warn!(
18521851
"Sending reply to get browsing context info failed ({:?}).",
@@ -4149,14 +4148,29 @@ where
41494148
},
41504149
Some(browsing_context) => browsing_context.pipeline_id,
41514150
};
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-
};
4151+
4152+
let (source_top_level_browsing_context_id, source_browsing_context_id) =
4153+
match self.pipelines.get(&source_pipeline) {
4154+
Some(pipeline) => (
4155+
pipeline.top_level_browsing_context_id,
4156+
pipeline.browsing_context_id,
4157+
),
4158+
None => return warn!("PostMessage from closed pipeline {:?}", source_pipeline),
4159+
};
4160+
4161+
let source_parent = self
4162+
.browsing_contexts
4163+
.get(&source_browsing_context_id)
4164+
.and_then(|bc| bc.parent_pipeline_id)
4165+
.and_then(|parent_id| self.pipelines.get(&parent_id))
4166+
.map(|pipeline| pipeline.browsing_context_id);
4167+
41564168
let msg = ConstellationControlMsg::PostMessage {
41574169
target: pipeline_id,
4170+
source_parent,
41584171
source: source_pipeline,
4159-
source_browsing_context: source_browsing_context,
4172+
source_browsing_context: source_browsing_context_id,
4173+
source_top_level_browsing_context: source_top_level_browsing_context_id,
41604174
target_origin: origin,
41614175
source_origin,
41624176
data,

components/script/script_thread.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,15 +1951,19 @@ impl ScriptThread {
19511951
),
19521952
ConstellationControlMsg::PostMessage {
19531953
target: target_pipeline_id,
1954+
source_parent,
19541955
source: source_pipeline_id,
19551956
source_browsing_context,
1957+
source_top_level_browsing_context,
19561958
target_origin: origin,
19571959
source_origin,
19581960
data,
19591961
} => self.handle_post_message_msg(
19601962
target_pipeline_id,
1963+
source_parent,
19611964
source_pipeline_id,
19621965
source_browsing_context,
1966+
source_top_level_browsing_context,
19631967
origin,
19641968
source_origin,
19651969
data,
@@ -2605,8 +2609,10 @@ impl ScriptThread {
26052609
fn handle_post_message_msg(
26062610
&self,
26072611
pipeline_id: PipelineId,
2612+
source_parent: Option<BrowsingContextId>,
26082613
source_pipeline_id: PipelineId,
2609-
source_browsing_context: TopLevelBrowsingContextId,
2614+
source_browsing_context: BrowsingContextId,
2615+
source_top_level_browsing_context: TopLevelBrowsingContextId,
26102616
origin: Option<ImmutableOrigin>,
26112617
source_origin: ImmutableOrigin,
26122618
data: StructuredSerializedData,
@@ -2615,12 +2621,11 @@ impl ScriptThread {
26152621
match window {
26162622
None => return warn!("postMessage after target pipeline {} closed.", pipeline_id),
26172623
Some(window) => {
2618-
// FIXME: synchronously talks to constellation.
2619-
// send the required info as part of postmessage instead.
26202624
let source = match self.remote_window_proxy(
26212625
&*window.global(),
2626+
source_top_level_browsing_context,
26222627
source_browsing_context,
2623-
source_pipeline_id,
2628+
source_parent,
26242629
None,
26252630
) {
26262631
None => {
@@ -3043,20 +3048,6 @@ impl ScriptThread {
30433048
}
30443049
}
30453050

3046-
fn ask_constellation_for_browsing_context_info(
3047-
&self,
3048-
pipeline_id: PipelineId,
3049-
) -> Option<(BrowsingContextId, Option<PipelineId>)> {
3050-
let (result_sender, result_receiver) = ipc::channel().unwrap();
3051-
let msg = ScriptMsg::GetBrowsingContextInfo(pipeline_id, result_sender);
3052-
self.script_sender
3053-
.send((pipeline_id, msg))
3054-
.expect("Failed to send to constellation.");
3055-
result_receiver
3056-
.recv()
3057-
.expect("Failed to get browsing context info from constellation.")
3058-
}
3059-
30603051
fn ask_constellation_for_top_level_info(
30613052
&self,
30623053
sender_pipeline: PipelineId,
@@ -3082,20 +3073,20 @@ impl ScriptThread {
30823073
&self,
30833074
global_to_clone: &GlobalScope,
30843075
top_level_browsing_context_id: TopLevelBrowsingContextId,
3085-
pipeline_id: PipelineId,
3076+
browsing_context_id: BrowsingContextId,
3077+
parent: Option<BrowsingContextId>,
30863078
opener: Option<BrowsingContextId>,
30873079
) -> Option<DomRoot<WindowProxy>> {
3088-
let (browsing_context_id, parent_pipeline_id) =
3089-
self.ask_constellation_for_browsing_context_info(pipeline_id)?;
30903080
if let Some(window_proxy) = self.window_proxies.borrow().get(&browsing_context_id) {
30913081
return Some(DomRoot::from_ref(window_proxy));
30923082
}
30933083

3094-
let parent_browsing_context = parent_pipeline_id.and_then(|parent_id| {
3084+
let parent_browsing_context = parent.and_then(|parent_bc| {
30953085
self.remote_window_proxy(
30963086
global_to_clone,
30973087
top_level_browsing_context_id,
3098-
parent_id,
3088+
parent_bc,
3089+
None,
30993090
opener,
31003091
)
31013092
});
@@ -3147,12 +3138,24 @@ impl ScriptThread {
31473138
});
31483139
let parent_browsing_context = match (parent_info, iframe.as_ref()) {
31493140
(_, Some(iframe)) => Some(window_from_node(&**iframe).window_proxy()),
3150-
(Some(parent_id), _) => self.remote_window_proxy(
3151-
window.upcast(),
3152-
top_level_browsing_context_id,
3153-
parent_id,
3154-
opener,
3155-
),
3141+
(Some(parent_id), _) => {
3142+
let (result_sender, result_receiver) = ipc::channel().unwrap();
3143+
let msg = ScriptMsg::GetBrowsingContextInfo(parent_id, result_sender);
3144+
self.script_sender
3145+
.send((parent_id, msg))
3146+
.expect("Failed to send to constellation.");
3147+
let browsing_context_id = result_receiver
3148+
.recv()
3149+
.expect("Failed to get reply from the constellation.")
3150+
.expect("Failed to get browsing context info from constellation.");
3151+
self.remote_window_proxy(
3152+
window.upcast(),
3153+
top_level_browsing_context_id,
3154+
browsing_context_id,
3155+
None,
3156+
opener,
3157+
)
3158+
},
31563159
_ => None,
31573160
};
31583161

components/script_traits/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,14 @@ pub enum ConstellationControlMsg {
340340
PostMessage {
341341
/// The target of the message.
342342
target: PipelineId,
343+
/// The parent browsing-context of the source, if any.
344+
source_parent: Option<BrowsingContextId>,
343345
/// The source of the message.
344346
source: PipelineId,
347+
/// The browsing context associated with the source pipeline.
348+
source_browsing_context: BrowsingContextId,
345349
/// The top level browsing context associated with the source pipeline.
346-
source_browsing_context: TopLevelBrowsingContextId,
350+
source_top_level_browsing_context: TopLevelBrowsingContextId,
347351
/// The expected origin of the target.
348352
target_origin: Option<ImmutableOrigin>,
349353
/// The source origin of the message.

components/script_traits/script_msg.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,8 @@ pub enum ScriptMsg {
187187
IpcSender<Option<TopLevelBrowsingContextId>>,
188188
),
189189
/// Get the browsing context id of the browsing context in which pipeline is
190-
/// embedded and the parent pipeline id of that browsing context.
191-
GetBrowsingContextInfo(
192-
PipelineId,
193-
IpcSender<Option<(BrowsingContextId, Option<PipelineId>)>>,
194-
),
190+
/// embedded.
191+
GetBrowsingContextInfo(PipelineId, IpcSender<Option<BrowsingContextId>>),
195192
/// Get the nth child browsing context ID for a given browsing context, sorted in tree order.
196193
GetChildBrowsingContextId(
197194
BrowsingContextId,

0 commit comments

Comments
 (0)