aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared
diff options
context:
space:
mode:
Diffstat (limited to 'components/shared')
-rw-r--r--components/shared/constellation/from_script_message.rs36
-rw-r--r--components/shared/constellation/lib.rs19
-rw-r--r--components/shared/constellation/structured_data/transferable.rs7
-rw-r--r--components/shared/embedder/lib.rs75
-rw-r--r--components/shared/script/lib.rs14
5 files changed, 134 insertions, 17 deletions
diff --git a/components/shared/constellation/from_script_message.rs b/components/shared/constellation/from_script_message.rs
index 8346551fd15..ddc9f788617 100644
--- a/components/shared/constellation/from_script_message.rs
+++ b/components/shared/constellation/from_script_message.rs
@@ -4,7 +4,7 @@
//! Messages send from the ScriptThread to the Constellation.
-use std::collections::{HashMap, VecDeque};
+use std::collections::HashMap;
use std::fmt;
use base::Epoch;
@@ -15,7 +15,8 @@ use base::id::{
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
use embedder_traits::{
- AnimationState, EmbedderMsg, MediaSessionEvent, TouchEventResult, ViewportDetails,
+ AnimationState, EmbedderMsg, FocusSequenceNumber, MediaSessionEvent, TouchEventResult,
+ ViewportDetails,
};
use euclid::default::Size2D as UntypedSize2D;
use http::{HeaderMap, Method};
@@ -34,7 +35,9 @@ use webgpu_traits::{WebGPU, WebGPUAdapterResponse};
use webrender_api::ImageKey;
use crate::structured_data::{BroadcastMsg, StructuredSerializedData};
-use crate::{LogEntry, MessagePortMsg, PortMessageTask, TraversalDirection, WindowSizeType};
+use crate::{
+ LogEntry, MessagePortMsg, PortMessageTask, PortTransferInfo, TraversalDirection, WindowSizeType,
+};
/// A Script to Constellation channel.
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -469,7 +472,7 @@ pub enum ScriptToConstellationMessage {
/* The ids of ports transferred successfully */
Vec<MessagePortId>,
/* The ids, and buffers, of ports whose transfer failed */
- HashMap<MessagePortId, VecDeque<PortMessageTask>>,
+ HashMap<MessagePortId, PortTransferInfo>,
),
/// A new message-port was created or transferred, with corresponding control-sender.
NewMessagePort(MessagePortRouterId, MessagePortId),
@@ -481,10 +484,14 @@ pub enum ScriptToConstellationMessage {
RerouteMessagePort(MessagePortId, PortMessageTask),
/// A message-port was shipped, let the entangled port know.
MessagePortShipped(MessagePortId),
- /// A message-port has been discarded by script.
- RemoveMessagePort(MessagePortId),
/// Entangle two message-ports.
EntanglePorts(MessagePortId, MessagePortId),
+ /// Disentangle two message-ports.
+ /// The first is the initiator, the second the other port,
+ /// unless the message is sent to complete a disentanglement,
+ /// in which case the first one is the other port,
+ /// and the second is none.
+ DisentanglePorts(MessagePortId, Option<MessagePortId>),
/// A global has started managing broadcast-channels.
NewBroadcastChannelRouter(
BroadcastChannelRouterId,
@@ -519,8 +526,21 @@ pub enum ScriptToConstellationMessage {
UntypedSize2D<u64>,
IpcSender<(IpcSender<CanvasMsg>, CanvasId, ImageKey)>,
),
- /// Notifies the constellation that this frame has received focus.
- Focus,
+ /// Notifies the constellation that this pipeline is requesting focus.
+ ///
+ /// When this message is sent, the sender pipeline has already its local
+ /// focus state updated. The constellation, after receiving this message,
+ /// will broadcast messages to other pipelines that are affected by this
+ /// focus operation.
+ ///
+ /// The first field contains the browsing context ID of the container
+ /// element if one was focused.
+ ///
+ /// The second field is a sequence number that the constellation should use
+ /// when sending a focus-related message to the sender pipeline next time.
+ Focus(Option<BrowsingContextId>, FocusSequenceNumber),
+ /// Requests the constellation to focus the specified browsing context.
+ FocusRemoteDocument(BrowsingContextId),
/// Get the top-level browsing context info for a given browsing context.
GetTopForBrowsingContext(BrowsingContextId, IpcSender<Option<WebViewId>>),
/// Get the browsing context id of the browsing context in which pipeline is
diff --git a/components/shared/constellation/lib.rs b/components/shared/constellation/lib.rs
index b3d4fe525a1..559bc2dd2d1 100644
--- a/components/shared/constellation/lib.rs
+++ b/components/shared/constellation/lib.rs
@@ -157,18 +157,29 @@ pub struct PortMessageTask {
pub data: StructuredSerializedData,
}
+/// The information needed by a global to process the transfer of a port.
+#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
+pub struct PortTransferInfo {
+ /// <https://html.spec.whatwg.org/multipage/#port-message-queue>
+ pub port_message_queue: VecDeque<PortMessageTask>,
+ /// A boolean indicating whether the port has been disentangled while in transfer,
+ /// if so, the disentanglement should be completed along with the transfer.
+ /// <https://html.spec.whatwg.org/multipage/#disentangle>
+ pub disentangled: bool,
+}
+
/// Messages for communication between the constellation and a global managing ports.
#[derive(Debug, Deserialize, Serialize)]
#[allow(clippy::large_enum_variant)]
pub enum MessagePortMsg {
/// Complete the transfer for a batch of ports.
- CompleteTransfer(HashMap<MessagePortId, VecDeque<PortMessageTask>>),
+ CompleteTransfer(HashMap<MessagePortId, PortTransferInfo>),
/// Complete the transfer of a single port,
/// whose transfer was pending because it had been requested
/// while a previous failed transfer was being rolled-back.
- CompletePendingTransfer(MessagePortId, VecDeque<PortMessageTask>),
- /// Remove a port, the entangled one doesn't exists anymore.
- RemoveMessagePort(MessagePortId),
+ CompletePendingTransfer(MessagePortId, PortTransferInfo),
+ /// <https://html.spec.whatwg.org/multipage/#disentangle>
+ CompleteDisentanglement(MessagePortId),
/// Handle a new port-message-task.
NewTask(MessagePortId, PortMessageTask),
}
diff --git a/components/shared/constellation/structured_data/transferable.rs b/components/shared/constellation/structured_data/transferable.rs
index cd6388f5f34..7e4fe0e6d2d 100644
--- a/components/shared/constellation/structured_data/transferable.rs
+++ b/components/shared/constellation/structured_data/transferable.rs
@@ -77,7 +77,12 @@ impl MessagePortImpl {
self.entangled_port
}
- /// Entanged this port with another.
+ /// <https://html.spec.whatwg.org/multipage/#disentangle>
+ pub fn disentangle(&mut self) -> Option<MessagePortId> {
+ self.entangled_port.take()
+ }
+
+ /// <https://html.spec.whatwg.org/multipage/#entangle>
pub fn entangle(&mut self, other_id: MessagePortId) {
self.entangled_port = Some(other_id);
}
diff --git a/components/shared/embedder/lib.rs b/components/shared/embedder/lib.rs
index 5f1171859dc..c87fa9019ef 100644
--- a/components/shared/embedder/lib.rs
+++ b/components/shared/embedder/lib.rs
@@ -14,7 +14,7 @@ pub mod user_content_manager;
mod webdriver;
use std::ffi::c_void;
-use std::fmt::{Debug, Error, Formatter};
+use std::fmt::{Debug, Display, Error, Formatter};
use std::path::PathBuf;
use std::sync::Arc;
@@ -784,3 +784,76 @@ pub enum AnimationState {
/// No animations are active but callbacks are queued
NoAnimationCallbacksPresent,
}
+
+/// A sequence number generated by a script thread for its pipelines. The
+/// constellation attaches the target pipeline's last seen `FocusSequenceNumber`
+/// to every focus-related message it sends.
+///
+/// This is used to resolve the inconsistency that occurs due to bidirectional
+/// focus state synchronization and provide eventual consistency. Example:
+///
+/// ```text
+/// script constellation
+/// -----------------------------------------------------------------------
+/// send ActivateDocument ----------> receive ActivateDocument
+/// ,---- send FocusDocument
+/// |
+/// focus an iframe |
+/// send Focus -----------------|---> receive Focus
+/// | focus the iframe's content document
+/// receive FocusDocument <-----' send FocusDocument to the content pipeline --> ...
+/// unfocus the iframe
+/// focus the document
+///
+/// Final state: Final state:
+/// the iframe is not focused the iframe is focused
+/// ```
+///
+/// When the above sequence completes, from the script thread's point of view,
+/// the iframe is unfocused, but from the constellation's point of view, the
+/// iframe is still focused.
+///
+/// This inconsistency can be resolved by associating a sequence number to each
+/// message. Whenever a script thread initiates a focus operation, it generates
+/// and sends a brand new sequence number. The constellation attaches the
+/// last-received sequence number to each message it sends. This way, the script
+/// thread can discard out-dated incoming focus messages, and eventually, all
+/// actors converge to the consistent state which is determined based on the
+/// last focus message received by the constellation.
+///
+/// ```text
+/// script constellation
+/// -----------------------------------------------------------------------
+/// send ActivateDocument ----------> receive ActivateDocument
+/// ,---- send FocusDocument (0)
+/// |
+/// seq_number += 1 |
+/// focus an iframe |
+/// send Focus (1) -------------|---> receive Focus (1)
+/// | focus the iframe's content document
+/// receive FocusDocument (0) <-' send FocusDocument to the content pipeline --> ...
+/// ignore it because 0 < 1
+///
+/// Final state: Final state:
+/// the iframe is focused the iframe is focused
+/// ```
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Default,
+ Deserialize,
+ Eq,
+ Hash,
+ MallocSizeOf,
+ PartialEq,
+ Serialize,
+ PartialOrd,
+)]
+pub struct FocusSequenceNumber(pub u64);
+
+impl Display for FocusSequenceNumber {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
+ Display::fmt(&self.0, f)
+ }
+}
diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs
index 7323907cba3..748c42400a8 100644
--- a/components/shared/script/lib.rs
+++ b/components/shared/script/lib.rs
@@ -27,8 +27,8 @@ use crossbeam_channel::{RecvTimeoutError, Sender};
use devtools_traits::ScriptToDevtoolsControlMsg;
use embedder_traits::user_content_manager::UserContentManager;
use embedder_traits::{
- CompositorHitTestResult, InputEvent, MediaSessionActionType, Theme, ViewportDetails,
- WebDriverScriptCommand,
+ CompositorHitTestResult, FocusSequenceNumber, InputEvent, MediaSessionActionType, Theme,
+ ViewportDetails, WebDriverScriptCommand,
};
use euclid::{Rect, Scale, Size2D, UnknownUnit};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
@@ -191,7 +191,15 @@ pub enum ScriptThreadMessage {
RemoveHistoryStates(PipelineId, Vec<HistoryStateId>),
/// Set an iframe to be focused. Used when an element in an iframe gains focus.
/// PipelineId is for the parent, BrowsingContextId is for the nested browsing context
- FocusIFrame(PipelineId, BrowsingContextId),
+ FocusIFrame(PipelineId, BrowsingContextId, FocusSequenceNumber),
+ /// Focus the document. Used when the container gains focus.
+ FocusDocument(PipelineId, FocusSequenceNumber),
+ /// Notifies that the document's container (e.g., an iframe) is not included
+ /// in the top-level browsing context's focus chain (not considering system
+ /// focus) anymore.
+ ///
+ /// Obviously, this message is invalid for a top-level document.
+ Unfocus(PipelineId, FocusSequenceNumber),
/// Passes a webdriver command to the script thread for execution
WebDriverScriptCommand(PipelineId, WebDriverScriptCommand),
/// Notifies script thread that all animations are done