Use task! to send a storage notification

This commit is contained in:
Anthony Ramine 2017-09-17 23:32:16 +02:00
parent 915a4f8385
commit 56a546afcd

View file

@ -19,7 +19,6 @@ use net_traits::IpcSend;
use net_traits::storage_thread::{StorageThreadMsg, StorageType}; use net_traits::storage_thread::{StorageThreadMsg, StorageType};
use script_traits::ScriptMsg; use script_traits::ScriptMsg;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use task::Task;
use task_source::TaskSource; use task_source::TaskSource;
#[dom_struct] #[dom_struct]
@ -166,41 +165,25 @@ impl Storage {
new_value: Option<String>, new_value: Option<String>,
) { ) {
let global = self.global(); let global = self.global();
let this = Trusted::new(self);
global.as_window().dom_manipulation_task_source().queue( global.as_window().dom_manipulation_task_source().queue(
box StorageEventTask { box task!(send_storage_notification: move || {
element: Trusted::new(self), let this = this.root();
url, let global = this.global();
key, let event = StorageEvent::new(
old_value,
new_value,
},
global.upcast(),
).unwrap();
struct StorageEventTask {
element: Trusted<Storage>,
url: ServoUrl,
key: Option<String>,
old_value: Option<String>,
new_value: Option<String>
}
impl Task for StorageEventTask {
fn run(self: Box<Self>) {
let this = *self;
let storage = this.element.root();
let global = storage.global();
let storage_event = StorageEvent::new(
global.as_window(), global.as_window(),
atom!("storage"), atom!("storage"),
EventBubbles::DoesNotBubble, EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable, EventCancelable::NotCancelable,
this.key.map(DOMString::from), key.map(DOMString::from),
this.old_value.map(DOMString::from), old_value.map(DOMString::from),
this.new_value.map(DOMString::from), new_value.map(DOMString::from),
DOMString::from(this.url.into_string()), DOMString::from(url.into_string()),
Some(&storage) Some(&this),
); );
storage_event.upcast::<Event>().fire(global.upcast()); event.upcast::<Event>().fire(global.upcast());
} }),
} global.upcast(),
).unwrap();
} }
} }