forked from mirrors/gecko-dev
<!-- Please describe your changes on the following line: --> This patch removes Worker scope from Storage and StorageEvent WebIDL definition. This way it is possible to construct the objects passing Window instead of GlobalScope. It also removes some tests as they would run out of the scope. It removes Worker from the WebIDL files defining the Storage and StorageEvent interfaces, as they should not be exposed in that scope. In Rust source code, this patch replaces "GlobalScope" with "Window" on the contructors. It also modifies constructor calling code in order to pass Window instead of the previously used GlobalScope. There has been removed these interfaces from the Worker tests. (This time I did a real build and real tests. Sorry about previous pull requests, I am used to the Mozilla flow, which doesn't uses GitHub) --- <!-- 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 #15436 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 3d0fe9a0dd12650efc754f85287d2426c7463535 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : c7bb052d4be36590cd3584cb34a815207f8f86a4
120 lines
4.3 KiB
Rust
120 lines
4.3 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
|
use dom::bindings::codegen::Bindings::StorageEventBinding;
|
|
use dom::bindings::codegen::Bindings::StorageEventBinding::StorageEventMethods;
|
|
use dom::bindings::error::Fallible;
|
|
use dom::bindings::inheritance::Castable;
|
|
use dom::bindings::js::{MutNullableJS, Root, RootedReference};
|
|
use dom::bindings::reflector::reflect_dom_object;
|
|
use dom::bindings::str::DOMString;
|
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
|
use dom::storage::Storage;
|
|
use dom::window::Window;
|
|
use servo_atoms::Atom;
|
|
|
|
#[dom_struct]
|
|
pub struct StorageEvent {
|
|
event: Event,
|
|
key: Option<DOMString>,
|
|
old_value: Option<DOMString>,
|
|
new_value: Option<DOMString>,
|
|
url: DOMString,
|
|
storage_area: MutNullableJS<Storage>
|
|
}
|
|
|
|
|
|
impl StorageEvent {
|
|
pub fn new_inherited(key: Option<DOMString>,
|
|
old_value: Option<DOMString>,
|
|
new_value: Option<DOMString>,
|
|
url: DOMString,
|
|
storage_area: Option<&Storage>) -> StorageEvent {
|
|
StorageEvent {
|
|
event: Event::new_inherited(),
|
|
key: key,
|
|
old_value: old_value,
|
|
new_value: new_value,
|
|
url: url,
|
|
storage_area: MutNullableJS::new(storage_area)
|
|
}
|
|
}
|
|
|
|
pub fn new_uninitialized(window: &Window,
|
|
url: DOMString) -> Root<StorageEvent> {
|
|
reflect_dom_object(box StorageEvent::new_inherited(None, None, None, url, None),
|
|
window,
|
|
StorageEventBinding::Wrap)
|
|
}
|
|
|
|
pub fn new(global: &Window,
|
|
type_: Atom,
|
|
bubbles: EventBubbles,
|
|
cancelable: EventCancelable,
|
|
key: Option<DOMString>,
|
|
oldValue: Option<DOMString>,
|
|
newValue: Option<DOMString>,
|
|
url: DOMString,
|
|
storageArea: Option<&Storage>) -> Root<StorageEvent> {
|
|
let ev = reflect_dom_object(box StorageEvent::new_inherited(key, oldValue, newValue,
|
|
url, storageArea),
|
|
global,
|
|
StorageEventBinding::Wrap);
|
|
{
|
|
let event = ev.upcast::<Event>();
|
|
event.init_event(type_, bool::from(bubbles), bool::from(cancelable));
|
|
}
|
|
ev
|
|
}
|
|
|
|
pub fn Constructor(global: &Window,
|
|
type_: DOMString,
|
|
init: &StorageEventBinding::StorageEventInit) -> Fallible<Root<StorageEvent>> {
|
|
let key = init.key.clone();
|
|
let oldValue = init.oldValue.clone();
|
|
let newValue = init.newValue.clone();
|
|
let url = init.url.clone();
|
|
let storageArea = init.storageArea.r();
|
|
let bubbles = EventBubbles::from(init.parent.bubbles);
|
|
let cancelable = EventCancelable::from(init.parent.cancelable);
|
|
let event = StorageEvent::new(global, Atom::from(type_),
|
|
bubbles, cancelable,
|
|
key, oldValue, newValue,
|
|
url, storageArea);
|
|
Ok(event)
|
|
}
|
|
}
|
|
|
|
impl StorageEventMethods for StorageEvent {
|
|
// https://html.spec.whatwg.org/multipage/#dom-storageevent-key
|
|
fn GetKey(&self) -> Option<DOMString> {
|
|
self.key.clone()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-storageevent-oldvalue
|
|
fn GetOldValue(&self) -> Option<DOMString> {
|
|
self.old_value.clone()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-storageevent-newvalue
|
|
fn GetNewValue(&self) -> Option<DOMString> {
|
|
self.new_value.clone()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-storageevent-url
|
|
fn Url(&self) -> DOMString {
|
|
self.url.clone()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-storageevent-storagearea
|
|
fn GetStorageArea(&self) -> Option<Root<Storage>> {
|
|
self.storage_area.get()
|
|
}
|
|
|
|
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
|
fn IsTrusted(&self) -> bool {
|
|
self.event.IsTrusted()
|
|
}
|
|
}
|