From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- toolkit/content/widgets/docs/index.rst | 10 ++++++ toolkit/content/widgets/docs/ua_widget.rst | 58 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 toolkit/content/widgets/docs/index.rst create mode 100644 toolkit/content/widgets/docs/ua_widget.rst (limited to 'toolkit/content/widgets/docs') diff --git a/toolkit/content/widgets/docs/index.rst b/toolkit/content/widgets/docs/index.rst new file mode 100644 index 0000000000..2e576357f3 --- /dev/null +++ b/toolkit/content/widgets/docs/index.rst @@ -0,0 +1,10 @@ +=============== +Toolkit Widgets +=============== + +The ``/toolkit/content/widgets`` directory contains XBL bindings, Mozilla Custom Elements, and UA Widgets usable for all applications. + +.. toctree:: + :maxdepth: 1 + + ua_widget diff --git a/toolkit/content/widgets/docs/ua_widget.rst b/toolkit/content/widgets/docs/ua_widget.rst new file mode 100644 index 0000000000..5d01c95a3c --- /dev/null +++ b/toolkit/content/widgets/docs/ua_widget.rst @@ -0,0 +1,58 @@ +UA Widgets +========== + +Introduction +------------ + +User Agent Widgets (UA Widgets) are intended to be a replacement of our usage of XBL bindings in web content. These widgets run JavaScript inside extended principal per-origin sandboxes. They insert their own DOM inside of a special, closed Shadow Root inaccessible to the page, called a UA Widget Shadow Root. + +UA Widget lifecycle +------------------- + +UA Widgets are generally constructed when the element is appended to the document and destroyed when the element is removed from the tree. Yet, in order to be fast, specialization was made to each of the widgets. + +When the element is appended to the tree, a chrome-only ``UAWidgetSetupOrChange`` event is dispatched and is caught by a frame script, namely UAWidgetsChild. + +UAWidgetsChild then grabs the sandbox for that origin (lazily creating it as needed), loads the script as needed, and initializes an instance by calling the JS constructor with a reference to the UA Widget Shadow Root created by the DOM. We will discuss the sandbox in the latter section. + +The ``onsetup`` method is called right after the instance is constructed. The call to constructor must not throw, or UAWidgetsChild will be confused since an instance of the widget will not be returned, but the widget is already half-initalized. If the ``onsetup`` method call throws, UAWidgetsChild will still be able to hold the reference of the widget and call the teardown method later on. + +When the element is removed from the tree, ``UAWidgetTeardown`` is dispatched so UAWidgetsChild can destroy the widget, if it exists. If so, the UAWidgetsChild calls the ``teardown()`` method on the widget, causing the widget to destruct itself. + +Counter-intuitively, elements are not considered "removed from the tree" when the document is unloaded. This is considered safe as anything the widget touches should be reset or cleaned up when the document unloads. Please do not violate the assumption by having any browser state toggled by the teardown. + +When a UA Widget initializes, it should create its own DOM inside the passed UA Widget Shadow Root, including the ```` element necessary to load the stylesheet, add event listeners, etc. When destroyed (i.e. the teardown method is called), it should do the opposite. + +**Specialization**: for video controls, we do not want to do the work if the control is not needed (i.e. when the ``