Factored out permission_state_invocation_results API to GlobalScope

Instead of Window
This commit is contained in:
gatowololo 2019-06-27 10:23:52 -07:00 committed by Iulian Gabriel Radu
parent ad9bfc2a62
commit 24c14ac94e
3 changed files with 11 additions and 17 deletions

View file

@ -5,6 +5,7 @@
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BroadcastChannelBinding::BroadcastChannelMethods; use crate::dom::bindings::codegen::Bindings::BroadcastChannelBinding::BroadcastChannelMethods;
use crate::dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods; use crate::dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods;
use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionState;
use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction; use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods; use crate::dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
@ -189,6 +190,9 @@ pub struct GlobalScope {
/// The origin of the globalscope /// The origin of the globalscope
origin: MutableOrigin, origin: MutableOrigin,
/// A map for storing the previous permission state read results.
permission_state_invocation_results: DomRefCell<HashMap<String, PermissionState>>,
/// The microtask queue associated with this global. /// The microtask queue associated with this global.
/// ///
/// It is refcounted because windows in the same script thread share the /// It is refcounted because windows in the same script thread share the
@ -575,6 +579,7 @@ impl GlobalScope {
timers: OneshotTimers::new(scheduler_chan), timers: OneshotTimers::new(scheduler_chan),
init_timers: Default::default(), init_timers: Default::default(),
origin, origin,
permission_state_invocation_results: Default::default(),
microtask_queue, microtask_queue,
list_auto_close_worker: Default::default(), list_auto_close_worker: Default::default(),
event_source_tracker: DOMTracker::new(), event_source_tracker: DOMTracker::new(),
@ -1701,6 +1706,12 @@ impl GlobalScope {
} }
} }
pub fn permission_state_invocation_results(
&self,
) -> &DomRefCell<HashMap<String, PermissionState>> {
&self.permission_state_invocation_results
}
pub fn track_worker(&self, closing_worker: Arc<AtomicBool>) { pub fn track_worker(&self, closing_worker: Arc<AtomicBool>) {
self.list_auto_close_worker self.list_auto_close_worker
.borrow_mut() .borrow_mut()

View file

@ -143,7 +143,6 @@ impl Permissions {
// (Revoke) Step 3. // (Revoke) Step 3.
let globalscope = self.global(); let globalscope = self.global();
globalscope globalscope
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
.remove(&root_desc.name.to_string()); .remove(&root_desc.name.to_string());
@ -176,7 +175,6 @@ impl Permissions {
// (Revoke) Step 3. // (Revoke) Step 3.
let globalscope = self.global(); let globalscope = self.global();
globalscope globalscope
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
.remove(&root_desc.name.to_string()); .remove(&root_desc.name.to_string());
@ -269,7 +267,6 @@ impl PermissionAlgorithm for Permissions {
); );
globalscope globalscope
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
.insert(perm_name.to_string(), state); .insert(perm_name.to_string(), state);
@ -309,7 +306,6 @@ pub fn get_descriptor_permission_state(
PermissionState::Granted PermissionState::Granted
} else { } else {
settings settings
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
.remove(&permission_name.to_string()); .remove(&permission_name.to_string());
@ -323,7 +319,6 @@ pub fn get_descriptor_permission_state(
// Step 3. // Step 3.
if let Some(prev_result) = settings if let Some(prev_result) = settings
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow() .borrow()
.get(&permission_name.to_string()) .get(&permission_name.to_string())
@ -333,7 +328,6 @@ pub fn get_descriptor_permission_state(
// Store the invocation result // Store the invocation result
settings settings
.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
.insert(permission_name.to_string(), state); .insert(permission_name.to_string(), state);

View file

@ -8,7 +8,6 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
}; };
use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::HistoryMethods; use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::HistoryMethods;
use crate::dom::bindings::codegen::Bindings::MediaQueryListBinding::MediaQueryListBinding::MediaQueryListMethods; use crate::dom::bindings::codegen::Bindings::MediaQueryListBinding::MediaQueryListBinding::MediaQueryListMethods;
use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionState;
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit; use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction; use crate::dom::bindings::codegen::Bindings::VoidFunctionBinding::VoidFunction;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{ use crate::dom::bindings::codegen::Bindings::WindowBinding::{
@ -275,9 +274,6 @@ pub struct Window {
#[ignore_malloc_size_of = "defined in webxr"] #[ignore_malloc_size_of = "defined in webxr"]
webxr_registry: webxr_api::Registry, webxr_registry: webxr_api::Registry,
/// A map for storing the previous permission state read results.
permission_state_invocation_results: DomRefCell<HashMap<String, PermissionState>>,
/// All of the elements that have an outstanding image request that was /// All of the elements that have an outstanding image request that was
/// initiated by layout during a reflow. They are stored in the script thread /// initiated by layout during a reflow. They are stored in the script thread
/// to ensure that the element can be marked dirty when the image data becomes /// to ensure that the element can be marked dirty when the image data becomes
@ -476,12 +472,6 @@ impl Window {
Worklet::new(self, WorkletGlobalScopeType::Paint) Worklet::new(self, WorkletGlobalScopeType::Paint)
} }
pub fn permission_state_invocation_results(
&self,
) -> &DomRefCell<HashMap<String, PermissionState>> {
&self.permission_state_invocation_results
}
pub fn pending_image_notification(&self, response: PendingImageResponse) { pub fn pending_image_notification(&self, response: PendingImageResponse) {
//XXXjdm could be more efficient to send the responses to the layout thread, //XXXjdm could be more efficient to send the responses to the layout thread,
// rather than making the layout thread talk to the image cache to // rather than making the layout thread talk to the image cache to
@ -2333,7 +2323,6 @@ impl Window {
webgl_chan, webgl_chan,
webvr_chan, webvr_chan,
webxr_registry, webxr_registry,
permission_state_invocation_results: Default::default(),
pending_layout_images: Default::default(), pending_layout_images: Default::default(),
unminified_js_dir: Default::default(), unminified_js_dir: Default::default(),
test_worklet: Default::default(), test_worklet: Default::default(),