mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Clean up Storage::queue_storage_event
This moves the Runnable type directly in the method and makes it not use main_thread_handler, which is unneeded here anyway.
This commit is contained in:
parent
4b596f2912
commit
69275162b0
1 changed files with 44 additions and 45 deletions
|
@ -17,7 +17,7 @@ use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use net_traits::IpcSend;
|
use net_traits::IpcSend;
|
||||||
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
|
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
|
||||||
use script_thread::{Runnable, ScriptThread};
|
use script_thread::Runnable;
|
||||||
use script_traits::ScriptMsg;
|
use script_traits::ScriptMsg;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use task_source::TaskSource;
|
use task_source::TaskSource;
|
||||||
|
@ -158,50 +158,49 @@ impl Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
|
/// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
|
||||||
pub fn queue_storage_event(&self, url: ServoUrl,
|
pub fn queue_storage_event(
|
||||||
key: Option<String>, old_value: Option<String>, new_value: Option<String>) {
|
&self,
|
||||||
|
url: ServoUrl,
|
||||||
|
key: Option<String>,
|
||||||
|
old_value: Option<String>,
|
||||||
|
new_value: Option<String>,
|
||||||
|
) {
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let window = global.as_window();
|
global.as_window().dom_manipulation_task_source().queue(
|
||||||
let task_source = window.dom_manipulation_task_source();
|
box StorageEventRunnable {
|
||||||
let trusted_storage = Trusted::new(self);
|
element: Trusted::new(self),
|
||||||
task_source
|
url,
|
||||||
.queue(
|
key,
|
||||||
box StorageEventRunnable::new(trusted_storage, url, key, old_value, new_value), &global)
|
old_value,
|
||||||
.unwrap();
|
new_value,
|
||||||
}
|
},
|
||||||
}
|
global.upcast(),
|
||||||
|
).unwrap();
|
||||||
pub struct StorageEventRunnable {
|
struct StorageEventRunnable {
|
||||||
element: Trusted<Storage>,
|
element: Trusted<Storage>,
|
||||||
url: ServoUrl,
|
url: ServoUrl,
|
||||||
key: Option<String>,
|
key: Option<String>,
|
||||||
old_value: Option<String>,
|
old_value: Option<String>,
|
||||||
new_value: Option<String>
|
new_value: Option<String>
|
||||||
}
|
}
|
||||||
|
impl Runnable for StorageEventRunnable {
|
||||||
impl StorageEventRunnable {
|
fn handler(self: Box<Self>) {
|
||||||
fn new(storage: Trusted<Storage>, url: ServoUrl,
|
let this = *self;
|
||||||
key: Option<String>, old_value: Option<String>, new_value: Option<String>) -> StorageEventRunnable {
|
let storage = this.element.root();
|
||||||
StorageEventRunnable { element: storage, url: url, key: key, old_value: old_value, new_value: new_value }
|
let global = storage.global();
|
||||||
}
|
let storage_event = StorageEvent::new(
|
||||||
}
|
global.as_window(),
|
||||||
|
atom!("storage"),
|
||||||
impl Runnable for StorageEventRunnable {
|
EventBubbles::DoesNotBubble,
|
||||||
fn main_thread_handler(self: Box<StorageEventRunnable>, _: &ScriptThread) {
|
EventCancelable::NotCancelable,
|
||||||
let this = *self;
|
this.key.map(DOMString::from),
|
||||||
let storage = this.element.root();
|
this.old_value.map(DOMString::from),
|
||||||
let global = storage.global();
|
this.new_value.map(DOMString::from),
|
||||||
let window = global.as_window();
|
DOMString::from(this.url.into_string()),
|
||||||
|
Some(&storage)
|
||||||
let storage_event = StorageEvent::new(
|
);
|
||||||
&window,
|
storage_event.upcast::<Event>().fire(global.upcast());
|
||||||
atom!("storage"),
|
}
|
||||||
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
}
|
||||||
this.key.map(DOMString::from), this.old_value.map(DOMString::from), this.new_value.map(DOMString::from),
|
|
||||||
DOMString::from(this.url.into_string()),
|
|
||||||
Some(&storage)
|
|
||||||
);
|
|
||||||
|
|
||||||
storage_event.upcast::<Event>().fire(window.upcast());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue