Auto merge of #15368 - szeged:get_availability, r=nox

Implement GetAvailability for Bluetooth

<!-- Please describe your changes on the following line: -->
This implements the [getAvailability](https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability) function from the spec.

---
<!-- 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
- [ ] These changes fix #__ (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. -->

<!-- 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/15368)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-13 04:32:46 -08:00 committed by GitHub
commit e394334739
9 changed files with 98 additions and 9 deletions

View file

@ -443,6 +443,18 @@ impl BluetoothMethods for Bluetooth {
return p;
}
#[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability
fn GetAvailability(&self) -> Rc<Promise> {
let p = Promise::new(&self.global());
// Step 1. We did not override the method
// Step 2 - 3. in handle_response
let sender = response_async(&p, self);
self.get_bluetooth_thread().send(
BluetoothRequest::GetAvailability(sender)).unwrap();
p
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-onavailabilitychanged
event_handler!(availabilitychanged, GetOnavailabilitychanged, SetOnavailabilitychanged);
}
@ -466,6 +478,11 @@ impl AsyncBluetoothListener for Bluetooth {
// Step 5.
promise.resolve_native(promise_cx, &bt_device);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability
// Step 2 - 3.
BluetoothResponse::GetAvailability(is_available) => {
promise.resolve_native(promise_cx, &is_available);
}
_ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())),
}
}

View file

@ -29,8 +29,8 @@ dictionary RequestDeviceOptions {
[Pref="dom.bluetooth.enabled"]
interface Bluetooth : EventTarget {
// [SecureContext]
// Promise<boolean> getAvailability();
[SecureContext]
Promise<boolean> getAvailability();
[SecureContext]
attribute EventHandler onavailabilitychanged;
// [SecureContext, SameObject]