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:
Anthony Ramine 2017-09-16 01:15:44 +02:00
parent 4b596f2912
commit 69275162b0

View file

@ -17,7 +17,7 @@ use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::IpcSend;
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
use script_thread::{Runnable, ScriptThread};
use script_thread::Runnable;
use script_traits::ScriptMsg;
use servo_url::ServoUrl;
use task_source::TaskSource;
@ -158,50 +158,49 @@ impl Storage {
}
/// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
pub fn queue_storage_event(&self, url: ServoUrl,
key: Option<String>, old_value: Option<String>, new_value: Option<String>) {
pub fn queue_storage_event(
&self,
url: ServoUrl,
key: Option<String>,
old_value: Option<String>,
new_value: Option<String>,
) {
let global = self.global();
let window = global.as_window();
let task_source = window.dom_manipulation_task_source();
let trusted_storage = Trusted::new(self);
task_source
.queue(
box StorageEventRunnable::new(trusted_storage, url, key, old_value, new_value), &global)
.unwrap();
}
}
pub struct StorageEventRunnable {
global.as_window().dom_manipulation_task_source().queue(
box StorageEventRunnable {
element: Trusted::new(self),
url,
key,
old_value,
new_value,
},
global.upcast(),
).unwrap();
struct StorageEventRunnable {
element: Trusted<Storage>,
url: ServoUrl,
key: Option<String>,
old_value: Option<String>,
new_value: Option<String>
}
impl StorageEventRunnable {
fn new(storage: Trusted<Storage>, url: ServoUrl,
key: Option<String>, old_value: Option<String>, new_value: Option<String>) -> StorageEventRunnable {
StorageEventRunnable { element: storage, url: url, key: key, old_value: old_value, new_value: new_value }
}
}
impl Runnable for StorageEventRunnable {
fn main_thread_handler(self: Box<StorageEventRunnable>, _: &ScriptThread) {
fn handler(self: Box<Self>) {
let this = *self;
let storage = this.element.root();
let global = storage.global();
let window = global.as_window();
let storage_event = StorageEvent::new(
&window,
global.as_window(),
atom!("storage"),
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
this.key.map(DOMString::from), this.old_value.map(DOMString::from), this.new_value.map(DOMString::from),
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());
storage_event.upcast::<Event>().fire(global.upcast());
}
}
}
}