aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-01-07 22:19:45 -0500
committerGitHub <noreply@github.com>2019-01-07 22:19:45 -0500
commit11d1184663b897e7cf0153771a8b90944ad43375 (patch)
treea87fc401656f582d639a2dc2c0d77a7f6b706a58 /components/script/script_thread.rs
parente09e68371815987e2ba729864f511a4427e708f3 (diff)
parent8ff0c417a2b0d2f37a84b76735e011a4d500d3ab (diff)
downloadservo-11d1184663b897e7cf0153771a8b90944ad43375.tar.gz
servo-11d1184663b897e7cf0153771a8b90944ad43375.zip
Auto merge of #22514 - jdm:source, r=Manishearth
Implement source for postMessage events Also make similar-origin iframes access their newly loaded document as soon as the new document is created. This should allow tests that check the event.source property to run correctly. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22499 and fix #12715 and fix #22514. - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22514) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs58
1 files changed, 52 insertions, 6 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 6114e353d97..9247ca6afba 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -1419,7 +1419,7 @@ impl ScriptThread {
ChangeFrameVisibilityStatus(id, ..) => Some(id),
NotifyVisibilityChange(id, ..) => Some(id),
Navigate(id, ..) => Some(id),
- PostMessage(id, ..) => Some(id),
+ PostMessage { target: id, .. } => Some(id),
UpdatePipelineId(_, _, id, _) => Some(id),
UpdateHistoryState(id, ..) => Some(id),
RemoveHistoryStates(id, ..) => Some(id),
@@ -1592,9 +1592,19 @@ impl ScriptThread {
browsing_context_id,
visible,
),
- ConstellationControlMsg::PostMessage(pipeline_id, origin, data) => {
- self.handle_post_message_msg(pipeline_id, origin, data)
- },
+ ConstellationControlMsg::PostMessage {
+ target: target_pipeline_id,
+ source: source_pipeline_id,
+ source_browsing_context,
+ target_origin: origin,
+ data,
+ } => self.handle_post_message_msg(
+ target_pipeline_id,
+ source_pipeline_id,
+ source_browsing_context,
+ origin,
+ data,
+ ),
ConstellationControlMsg::UpdatePipelineId(
parent_pipeline_id,
browsing_context_id,
@@ -2080,12 +2090,33 @@ impl ScriptThread {
fn handle_post_message_msg(
&self,
pipeline_id: PipelineId,
+ source_pipeline_id: PipelineId,
+ source_browsing_context: TopLevelBrowsingContextId,
origin: Option<ImmutableOrigin>,
data: Vec<u8>,
) {
match { self.documents.borrow().find_window(pipeline_id) } {
- None => return warn!("postMessage after pipeline {} closed.", pipeline_id),
- Some(window) => window.post_message(origin, StructuredCloneData::Vector(data)),
+ None => return warn!("postMessage after target pipeline {} closed.", pipeline_id),
+ Some(window) => {
+ // FIXME: synchronously talks to constellation.
+ // send the required info as part of postmessage instead.
+ let source = match self.remote_window_proxy(
+ &*window.global(),
+ source_browsing_context,
+ source_pipeline_id,
+ None,
+ ) {
+ None => {
+ return warn!(
+ "postMessage after source pipeline {} closed.",
+ source_pipeline_id,
+ );
+ },
+ Some(source) => source,
+ };
+ // FIXME(#22512): enqueues a task; unnecessary delay.
+ window.post_message(origin, &*source, StructuredCloneData::Vector(data))
+ },
}
}
@@ -2820,6 +2851,21 @@ impl ScriptThread {
window.init_document(&document);
+ // For any similar-origin iframe, ensure that the contentWindow/contentDocument
+ // APIs resolve to the new window/document as soon as parsing starts.
+ if let Some(frame) = window_proxy
+ .frame_element()
+ .and_then(|e| e.downcast::<HTMLIFrameElement>())
+ {
+ let parent_pipeline = frame.global().pipeline_id();
+ self.handle_update_pipeline_id(
+ parent_pipeline,
+ window_proxy.browsing_context_id(),
+ incomplete.pipeline_id,
+ UpdatePipelineIdReason::Navigation,
+ );
+ }
+
self.script_sender
.send((incomplete.pipeline_id, ScriptMsg::ActivateDocument))
.unwrap();