mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Implement initial version of ReportingObserver (#37905)
The specification moved around lately with how it defines its reports and report bodies. They became dictionaries, but are currently missing some fields [1]. Most tests won't be passing yet, since the `Reporting-Endpoints` header isn't used yet. In fact, the specification leaves it up to the browser to figure out when to run this task [2]. I am not sure if there some background scheduling we can do here. Confirmed with content-security-policy/reporting-api/ report-to-directive-allowed-in-meta.https.sub.html that the callback is invoked. The test doesn't pass, since the `describe_scripted_caller` is empty for HTML elements. Thus the `source_file` is empty, whereas it should be equivalent to the current document URL. Part of #37328 Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com> [1]: https://github.com/w3c/reporting/issues/286 [2]: https://w3c.github.io/reporting/#report-delivery
This commit is contained in:
parent
3d4868592a
commit
fcb2a4cd95
20 changed files with 551 additions and 101 deletions
|
@ -102,6 +102,7 @@ use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
|
|||
ImageBitmapOptions, ImageBitmapSource,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::MediaQueryListBinding::MediaQueryList_Binding::MediaQueryListMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ReportingObserverBinding::Report;
|
||||
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
||||
use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::{
|
||||
|
@ -146,6 +147,7 @@ use crate::dom::navigator::Navigator;
|
|||
use crate::dom::node::{Node, NodeDamage, NodeTraits, from_untrusted_node_address};
|
||||
use crate::dom::performance::Performance;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::reportingobserver::ReportingObserver;
|
||||
use crate::dom::screen::Screen;
|
||||
use crate::dom::selection::Selection;
|
||||
use crate::dom::shadowroot::ShadowRoot;
|
||||
|
@ -398,6 +400,12 @@ pub(crate) struct Window {
|
|||
|
||||
/// <https://dom.spec.whatwg.org/#window-current-event>
|
||||
current_event: DomRefCell<Option<Dom<Event>>>,
|
||||
|
||||
/// <https://w3c.github.io/reporting/#windoworworkerglobalscope-registered-reporting-observer-list>
|
||||
reporting_observer_list: DomRefCell<Vec<DomRoot<ReportingObserver>>>,
|
||||
|
||||
/// <https://w3c.github.io/reporting/#windoworworkerglobalscope-reports>
|
||||
report_list: DomRefCell<Vec<Report>>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -502,6 +510,35 @@ impl Window {
|
|||
self.window_proxy.get().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn append_reporting_observer(&self, reporting_observer: DomRoot<ReportingObserver>) {
|
||||
self.reporting_observer_list
|
||||
.borrow_mut()
|
||||
.push(reporting_observer);
|
||||
}
|
||||
|
||||
pub(crate) fn remove_reporting_observer(&self, reporting_observer: &ReportingObserver) {
|
||||
if let Some(index) = self
|
||||
.reporting_observer_list
|
||||
.borrow()
|
||||
.iter()
|
||||
.position(|observer| &**observer == reporting_observer)
|
||||
{
|
||||
self.reporting_observer_list.borrow_mut().remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn registered_reporting_observers(&self) -> Vec<DomRoot<ReportingObserver>> {
|
||||
self.reporting_observer_list.borrow().clone()
|
||||
}
|
||||
|
||||
pub(crate) fn append_report(&self, report: Report) {
|
||||
self.report_list.borrow_mut().push(report);
|
||||
}
|
||||
|
||||
pub(crate) fn buffered_reports(&self) -> Vec<Report> {
|
||||
self.report_list.borrow().clone()
|
||||
}
|
||||
|
||||
/// Returns the window proxy if it has not been discarded.
|
||||
/// <https://html.spec.whatwg.org/multipage/#a-browsing-context-is-discarded>
|
||||
pub(crate) fn undiscarded_window_proxy(&self) -> Option<DomRoot<WindowProxy>> {
|
||||
|
@ -3106,6 +3143,8 @@ impl Window {
|
|||
current_event: DomRefCell::new(None),
|
||||
theme: Cell::new(theme),
|
||||
trusted_types: Default::default(),
|
||||
reporting_observer_list: Default::default(),
|
||||
report_list: Default::default(),
|
||||
});
|
||||
|
||||
unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue