diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-15 10:50:20 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-15 10:50:20 -0600 |
commit | 07b9dbe05a3d27b2623195f0c77ea7d7c45a4783 (patch) | |
tree | fdfab8c411c77d05604ff166a9b623f4a957978e /components/script/dom/storage.rs | |
parent | ef74d8da3bdb1cc3b1edf767a593e0e59228f23b (diff) | |
parent | c91ef86a20813d433fb7fb595c37d611d27967d0 (diff) | |
download | servo-07b9dbe05a3d27b2623195f0c77ea7d7c45a4783.tar.gz servo-07b9dbe05a3d27b2623195f0c77ea7d7c45a4783.zip |
Auto merge of #14023 - asajeffrey:storage-notify-via-constellation, r=nox
Storage notifications routed via the constellation.
<!-- Please describe your changes on the following line: -->
At the moment, storage notifications are only sent within a script thread, not to same-origin pipelines in different script threads. This PR fixes that.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #5196
- [X] These changes do not require tests because existing tests now pass
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14023)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/storage.rs')
-rw-r--r-- | components/script/dom/storage.rs | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 099c6c04fea..3eb2b1ca844 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -17,6 +17,7 @@ use ipc_channel::ipc::{self, IpcSender}; use net_traits::IpcSend; use net_traits::storage_thread::{StorageThreadMsg, StorageType}; use script_thread::{Runnable, ScriptThread}; +use script_traits::ScriptMsg; use task_source::TaskSource; use url::Url; @@ -149,60 +150,60 @@ impl Storage { /// https://html.spec.whatwg.org/multipage/#send-a-storage-notification fn broadcast_change_notification(&self, key: Option<String>, old_value: Option<String>, new_value: Option<String>) { + let pipeline_id = self.global().pipeline_id(); + let storage = self.storage_type; + let url = self.get_url(); + let msg = ScriptMsg::BroadcastStorageEvent(pipeline_id, storage, url, key, old_value, new_value); + self.global().constellation_chan().send(msg).unwrap(); + } + + /// https://html.spec.whatwg.org/multipage/#send-a-storage-notification + pub fn queue_storage_event(&self, url: Url, + 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, key, old_value, new_value), &global) + box StorageEventRunnable::new(trusted_storage, url, key, old_value, new_value), &global) .unwrap(); } } pub struct StorageEventRunnable { element: Trusted<Storage>, + url: Url, key: Option<String>, old_value: Option<String>, new_value: Option<String> } impl StorageEventRunnable { - fn new(storage: Trusted<Storage>, key: Option<String>, old_value: Option<String>, - new_value: Option<String>) -> StorageEventRunnable { - StorageEventRunnable { element: storage, key: key, old_value: old_value, new_value: new_value } + fn new(storage: Trusted<Storage>, url: Url, + 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 name(&self) -> &'static str { "StorageEventRunnable" } - fn main_thread_handler(self: Box<StorageEventRunnable>, script_thread: &ScriptThread) { + fn main_thread_handler(self: Box<StorageEventRunnable>, _: &ScriptThread) { let this = *self; let storage = this.element.root(); let global = storage.global(); - let ev_url = storage.get_url(); + let window = global.as_window(); let storage_event = StorageEvent::new( &global, 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(ev_url.to_string()), + DOMString::from(this.url.into_string()), Some(&storage) ); - // TODO: This is only iterating over documents in the current script - // thread, so we are not firing events to other script threads. - // NOTE: once that is fixed, we can remove borrow_documents from ScriptThread. - for (id, document) in script_thread.borrow_documents().iter() { - if ev_url.origin() == document.window().get_url().origin() { - // TODO: Such a Document object is not necessarily fully active, but events fired on such - // objects are ignored by the event loop until the Document becomes fully active again. - if global.pipeline_id() != id { - storage_event.upcast::<Event>().fire(document.window().upcast()); - } - } - } + storage_event.upcast::<Event>().fire(window.upcast()); } } |