Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an inCompartments config option for bindings #23459

Merged
merged 4 commits into from Jun 2, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use the newly added inCompartments option everywhere it can be

  • Loading branch information
Eijebong committed May 25, 2019
commit 292d468cd1552dd5644e8e0e2bf617b8bcac7655
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::baseaudiocontext::{BaseAudioContext, BaseAudioContextOptions};
use crate::dom::bindings::codegen::Bindings::AudioContextBinding;
use crate::dom::bindings::codegen::Bindings::AudioContextBinding::{
@@ -108,13 +108,9 @@ impl AudioContextMethods for AudioContext {
}

// https://webaudio.github.io/web-audio-api/#dom-audiocontext-suspend
fn Suspend(&self) -> Rc<Promise> {
fn Suspend(&self, comp: InCompartment) -> Rc<Promise> {
// Step 1.
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let promise = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&self.global(), comp);

// Step 2.
if self.context.control_thread_state() == ProcessingState::Closed {
@@ -173,13 +169,9 @@ impl AudioContextMethods for AudioContext {
}

// https://webaudio.github.io/web-audio-api/#dom-audiocontext-close
fn Close(&self) -> Rc<Promise> {
fn Close(&self, comp: InCompartment) -> Rc<Promise> {
// Step 1.
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let promise = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&self.global(), comp);

// Step 2.
if self.context.control_thread_state() == ProcessingState::Closed {
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::analysernode::AnalyserNode;
use crate::dom::audiobuffer::AudioBuffer;
use crate::dom::audiobuffersourcenode::AudioBufferSourceNode;
@@ -274,13 +274,9 @@ impl BaseAudioContextMethods for BaseAudioContext {
}

/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-resume
fn Resume(&self) -> Rc<Promise> {
fn Resume(&self, comp: InCompartment) -> Rc<Promise> {
// Step 1.
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let promise = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&self.global(), comp);

// Step 2.
if self.audio_context_impl.state() == ProcessingState::Closed {
@@ -424,13 +420,10 @@ impl BaseAudioContextMethods for BaseAudioContext {
audio_data: CustomAutoRooterGuard<ArrayBuffer>,
decode_success_callback: Option<Rc<DecodeSuccessCallback>>,
decode_error_callback: Option<Rc<DecodeErrorCallback>>,
comp: InCompartment,
) -> Rc<Promise> {
// Step 1.
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let promise = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
let promise = Promise::new_in_current_compartment(&self.global(), comp);
let global = self.global();
let window = global.as_window();

@@ -31,7 +31,9 @@ DOMInterfaces = {
},

#FIXME(jdm): This should be 'register': False, but then we don't generate enum types
'TestBinding': {},
'TestBinding': {
'inCompartments': ['PromiseAttribute', 'PromiseNativeHandler'],
},

'URL': {
'weakReferenceable': True,
@@ -50,8 +52,85 @@ DOMInterfaces = {
'inCompartments': ['Fetch'],
},

'TestBinding': {
'inCompartments': ['PromiseAttribute'],
'CustomElementRegistry': {
'inCompartments': ['WhenDefined'],
},

'AudioContext': {
'inCompartments': ['Suspend', 'Close'],
},

'NavigationPreloadManager': {
'inCompartments': ['Enable', 'Disable', 'SetHeaderValue', 'GetState'],
},

'HTMLMediaElement': {
'inCompartments': ['Play'],
},

'BluetoothRemoteGATTDescriptor': {
'inCompartments': ['ReadValue', 'WriteValue'],
},

'OfflineAudioContext': {
'inCompartments': ['StartRendering'],
},

'BluetoothRemoteGATTServer': {
'inCompartments': ['Connect'],
},

'ServiceWorkerContainer': {
'inCompartments': ['Register'],
},

'Navigator': {
'inCompartments': ['GetVRDisplays'],
},

'MediaDevices': {
'inCompartments': ['GetUserMedia'],
},

'XRSession': {
'inCompartments': ['UpdateRenderState', 'RequestReferenceSpace'],
},

'Bluetooth': {
'inCompartments': ['RequestDevice', 'GetAvailability'],
},

'BaseAudioContext': {
'inCompartments': ['Resume', 'DecodeAudioData'],
},

'RTCPeerConnection': {
'inCompartments': ['AddIceCandidate', 'CreateOffer', 'CreateAnswer', 'SetLocalDescription', 'SetRemoteDescription'],
},

'BluetoothRemoteGATTCharacteristic': {
'inCompartments': ['ReadValue', 'WriteValue', 'StartNotifications', 'StopNotifications'],
},

'VRDisplay': {
'inCompartments': ['RequestPresent', 'ExitPresent'],
},

'Worklet': {
'inCompartments': ['AddModule'],
},

'TestWorklet': {
'inCompartments': ['AddModule'],
},

'BluetoothDevice': {
'inCompartments': ['WatchAdvertisements'],
},

'XR': {
'inCompartments': ['SupportsSessionMode', 'RequestSession'],
}


}
@@ -535,12 +535,8 @@ impl From<BluetoothError> for Error {

impl BluetoothMethods for Bluetooth {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
fn RequestDevice(&self, option: &RequestDeviceOptions) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn RequestDevice(&self, option: &RequestDeviceOptions, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
// Step 1.
if (option.filters.is_some() && option.acceptAllDevices) ||
(option.filters.is_none() && !option.acceptAllDevices)
@@ -557,12 +553,8 @@ impl BluetoothMethods for Bluetooth {
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability
fn GetAvailability(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn GetAvailability(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
// Step 1. We did not override the method
// Step 2 - 3. in handle_response
let sender = response_async(&p, self);
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding;
use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
@@ -278,12 +278,8 @@ impl BluetoothDeviceMethods for BluetoothDevice {
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-watchadvertisements
fn WatchAdvertisements(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn WatchAdvertisements(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
let sender = response_async(&p, self);
// TODO: Step 1.
// Note: Steps 2 - 3 are implemented in components/bluetooth/lib.rs in watch_advertisements function
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::BluetoothCharacteristicPropertiesMethods;
use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding;
@@ -135,12 +135,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
fn ReadValue(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn ReadValue(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);

// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
@@ -172,12 +168,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);

// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
@@ -227,12 +219,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
fn StartNotifications(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn StartNotifications(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);

// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
@@ -268,12 +256,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications
fn StopNotifications(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn StopNotifications(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);
let sender = response_async(&p, self);

// TODO: Step 3 - 4: Implement `active notification context set` for BluetoothRemoteGATTCharacteristic,
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::BluetoothRemoteGATTCharacteristicMethods;
use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding;
@@ -94,12 +94,8 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
fn ReadValue(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn ReadValue(&self, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);

// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
@@ -130,12 +126,8 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer, comp: InCompartment) -> Rc<Promise> {
let p = Promise::new_in_current_compartment(&self.global(), comp);

// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::compartments::{AlreadyInCompartment, InCompartment};
use crate::compartments::InCompartment;
use crate::dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
use crate::dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
@@ -71,13 +71,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
#[allow(unsafe_code)]
fn Connect(&self) -> Rc<Promise> {
fn Connect(&self, comp: InCompartment) -> Rc<Promise> {
// Step 1.
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
let p = Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
);
let p = Promise::new_in_current_compartment(&self.global(), comp);
let sender = response_async(&p, self);

// TODO: Step 3: Check if the UA is currently using the Bluetooth system.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.