Add WebBluetooth Blacklist support

This commit is contained in:
fokinv 2016-05-20 13:19:58 +02:00 committed by Attila Dusnoki
parent b11648903b
commit a920e6d54e
8 changed files with 237 additions and 10 deletions

View file

@ -2,11 +2,12 @@
* 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 bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use core::clone::Clone;
use dom::bindings::codegen::Bindings::BluetoothBinding;
use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions;
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothScanFilter, BluetoothMethods};
use dom::bindings::error::Error::Type;
use dom::bindings::error::Error::{Security, Type};
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
@ -71,7 +72,11 @@ fn canonicalize_filter(filter: &BluetoothScanFilter, global: GlobalRef) -> Falli
return Err(Type(SERVICE_ERROR.to_owned()));
}
for service in services {
services_vec.push(try!(BluetoothUUID::GetService(global, service.clone())).to_string());
let uuid = try!(BluetoothUUID::GetService(global, service.clone())).to_string();
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
return Err(Security)
}
services_vec.push(uuid);
}
}
@ -119,7 +124,11 @@ fn convert_request_device_options(options: &RequestDeviceOptions,
let mut optional_services = vec!();
if let Some(ref opt_services) = options.optionalServices {
for opt_service in opt_services {
optional_services.push(try!(BluetoothUUID::GetService(global, opt_service.clone())).to_string());
let uuid = try!(BluetoothUUID::GetService(global, opt_service.clone())).to_string();
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
return Err(Security)
}
optional_services.push(uuid);
}
}