aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOJ Kwon <kwon.ohjoong@gmail.com>2018-04-17 19:46:02 -0700
committerOJ Kwon <kwon.ohjoong@gmail.com>2018-04-18 11:39:33 -0700
commit61b4a891bb188835842683800d6e97cecfd81609 (patch)
tree4d722f5f0403022842eb11eda7b4280919b65ce2
parent5574b4212632dfbf661a7813ccd9cc670c23a0d0 (diff)
downloadservo-61b4a891bb188835842683800d6e97cecfd81609.tar.gz
servo-61b4a891bb188835842683800d6e97cecfd81609.zip
refactor(bluetooth): uses embedderproxy directly
-rw-r--r--Cargo.lock3
-rw-r--r--components/bluetooth/Cargo.toml3
-rw-r--r--components/bluetooth/lib.rs55
-rw-r--r--components/constellation/constellation.rs34
-rw-r--r--components/script_traits/lib.rs2
-rw-r--r--components/script_traits/script_msg.rs7
-rw-r--r--components/servo/lib.rs11
7 files changed, 47 insertions, 68 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 55232d83a3c..63da933466e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -179,9 +179,10 @@ version = "0.0.1"
dependencies = [
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bluetooth_traits 0.0.1",
+ "compositing 0.0.1",
"device 0.0.1 (git+https://github.com/servo/devices)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "script_traits 0.0.1",
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_config 0.0.1",
"servo_rand 0.0.1",
"uuid 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/components/bluetooth/Cargo.toml b/components/bluetooth/Cargo.toml
index cf73315a639..bc172342977 100644
--- a/components/bluetooth/Cargo.toml
+++ b/components/bluetooth/Cargo.toml
@@ -12,9 +12,10 @@ path = "lib.rs"
[dependencies]
bitflags = "1.0"
bluetooth_traits = {path = "../bluetooth_traits"}
+compositing = {path = "../compositing"}
device = {git = "https://github.com/servo/devices", features = ["bluetooth-test"]}
ipc-channel = "0.10"
-script_traits = {path = "../script_traits"}
+log = "0.4"
servo_config = {path = "../config"}
servo_rand = {path = "../rand"}
uuid = {version = "0.6", features = ["v4"]}
diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs
index 3309b6133a3..3df295b56e9 100644
--- a/components/bluetooth/lib.rs
+++ b/components/bluetooth/lib.rs
@@ -5,9 +5,11 @@
#[macro_use]
extern crate bitflags;
extern crate bluetooth_traits;
+extern crate compositing;
extern crate device;
extern crate ipc_channel;
-extern crate script_traits;
+#[macro_use]
+extern crate log;
extern crate servo_config;
extern crate servo_rand;
extern crate uuid;
@@ -19,10 +21,10 @@ use bluetooth_traits::{BluetoothDeviceMsg, BluetoothRequest, BluetoothResponse,
use bluetooth_traits::{BluetoothError, BluetoothResponseResult, BluetoothResult};
use bluetooth_traits::blocklist::{uuid_is_blocklisted, Blocklist};
use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence, RequestDeviceoptions};
+use compositing::compositor_thread::{EmbedderMsg, EmbedderProxy};
use device::bluetooth::{BluetoothAdapter, BluetoothDevice, BluetoothGATTCharacteristic};
use device::bluetooth::{BluetoothGATTDescriptor, BluetoothGATTService};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
-use script_traits::BluetoothManagerMsg;
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_rand::Rng;
@@ -61,19 +63,23 @@ macro_rules! return_if_cached(
);
);
-pub fn new_bluetooth_thread() -> (IpcSender<BluetoothRequest>, IpcSender<IpcSender<BluetoothManagerMsg>>) {
- let (sender, receiver) = ipc::channel().unwrap();
- let (constellation_sender, constellation_receiver) = ipc::channel().unwrap();
- let adapter = if Some(true) == PREFS.get("dom.bluetooth.enabled").as_boolean() {
- BluetoothAdapter::init()
- } else {
- BluetoothAdapter::init_mock()
- }.ok();
- thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || {
- let constellation_chan = constellation_receiver.recv().unwrap();
- BluetoothManager::new(receiver, adapter, constellation_chan).start();
- }).expect("Thread spawning failed");
- (sender, constellation_sender)
+pub trait BluetoothThreadFactory {
+ fn new(embedder_proxy: EmbedderProxy) -> Self;
+}
+
+impl BluetoothThreadFactory for IpcSender<BluetoothRequest> {
+ fn new(embedder_proxy: EmbedderProxy) -> IpcSender<BluetoothRequest> {
+ let (sender, receiver) = ipc::channel().unwrap();
+ let adapter = if Some(true) == PREFS.get("dom.bluetooth.enabled").as_boolean() {
+ BluetoothAdapter::init()
+ } else {
+ BluetoothAdapter::init_mock()
+ }.ok();
+ thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || {
+ BluetoothManager::new(receiver, adapter, embedder_proxy).start();
+ }).expect("Thread spawning failed");
+ sender
+ }
}
// https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter
@@ -195,13 +201,13 @@ pub struct BluetoothManager {
cached_characteristics: HashMap<String, BluetoothGATTCharacteristic>,
cached_descriptors: HashMap<String, BluetoothGATTDescriptor>,
allowed_services: HashMap<String, HashSet<String>>,
- constellation_chan: IpcSender<BluetoothManagerMsg>,
+ embedder_proxy: EmbedderProxy,
}
impl BluetoothManager {
pub fn new(receiver: IpcReceiver<BluetoothRequest>,
adapter: Option<BluetoothAdapter>,
- constellation_chan: IpcSender<BluetoothManagerMsg>) -> BluetoothManager {
+ embedder_proxy: EmbedderProxy) -> BluetoothManager {
BluetoothManager {
receiver: receiver,
adapter: adapter,
@@ -214,7 +220,7 @@ impl BluetoothManager {
cached_characteristics: HashMap::new(),
cached_descriptors: HashMap::new(),
allowed_services: HashMap::new(),
- constellation_chan: constellation_chan,
+ embedder_proxy: embedder_proxy,
}
}
@@ -376,9 +382,16 @@ impl BluetoothManager {
}
let (ipc_sender, ipc_receiver) = ipc::channel().expect("Failed to create IPC channel!");
- let msg = BluetoothManagerMsg::OpenDeviceSelectDialog(dialog_rows, ipc_sender);
-
- self.constellation_chan.send(msg).map(|_| ipc_receiver.recv().unwrap()).unwrap_or_default()
+ let msg = EmbedderMsg::GetSelectedBluetoothDevice(dialog_rows, ipc_sender);
+ self.embedder_proxy.send(msg);
+
+ match ipc_receiver.recv() {
+ Ok(result) => result,
+ Err(e) => {
+ warn!("Failed to receive files from embedder ({}).", e);
+ None
+ }
+ }
}
fn generate_device_id(&mut self) -> String {
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs
index b863421e825..620e4b61460 100644
--- a/components/constellation/constellation.rs
+++ b/components/constellation/constellation.rs
@@ -123,12 +123,12 @@ use pipeline::{InitialPipelineState, Pipeline};
use profile_traits::mem;
use profile_traits::time;
use script_traits::{AnimationState, AnimationTickType, CompositorEvent};
-use script_traits::{BluetoothManagerMsg, SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use script_traits::{ConstellationControlMsg, ConstellationMsg as FromCompositorMsg, DiscardBrowsingContext};
use script_traits::{DocumentActivity, DocumentState, LayoutControlMsg, LoadData};
use script_traits::{IFrameLoadInfo, IFrameLoadInfoWithData, IFrameSandboxState, TimerSchedulerMsg};
use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory};
use script_traits::{LogEntry, ScriptToConstellationChan, ServiceWorkerMsg, webdriver_msg};
+use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use script_traits::{WindowSizeData, WindowSizeType};
use serde::{Deserialize, Serialize};
use servo_config::opts;
@@ -174,9 +174,6 @@ pub struct Constellation<Message, LTF, STF> {
/// This is the constellation's view of `script_sender`.
script_receiver: Receiver<Result<(PipelineId, FromScriptMsg), IpcError>>,
- /// A channel for the constellation to receive messages from bluetooth threads.
- bluetoothmanager_receiver: Receiver<Result<BluetoothManagerMsg, IpcError>>,
-
/// An IPC channel for layout threads to send messages to the constellation.
/// This is the layout threads' view of `layout_receiver`.
layout_sender: IpcSender<FromLayoutMsg>,
@@ -549,23 +546,17 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
STF: ScriptThreadFactory<Message=Message>
{
/// Create a new constellation thread.
- pub fn start(state: InitialConstellationState)
- -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>, IpcSender<BluetoothManagerMsg>) {
+ pub fn start(state: InitialConstellationState) -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) {
let (compositor_sender, compositor_receiver) = channel();
// service worker manager to communicate with constellation
let (swmanager_sender, swmanager_receiver) = ipc::channel().expect("ipc channel failure");
let sw_mgr_clone = swmanager_sender.clone();
- let (bluetoothmanager_sender, bluetoothmanager_receiver) = ipc::channel().expect("ipc channel failure");
-
thread::Builder::new().name("Constellation".to_owned()).spawn(move || {
let (ipc_script_sender, ipc_script_receiver) = ipc::channel().expect("ipc channel failure");
let script_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_script_receiver);
- let bluetoothmanager_receiver =
- route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(bluetoothmanager_receiver);
-
let (ipc_layout_sender, ipc_layout_receiver) = ipc::channel().expect("ipc channel failure");
let layout_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_layout_receiver);
@@ -579,7 +570,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
script_sender: ipc_script_sender,
layout_sender: ipc_layout_sender,
script_receiver: script_receiver,
- bluetoothmanager_receiver: bluetoothmanager_receiver,
compositor_receiver: compositor_receiver,
layout_receiver: layout_receiver,
network_listener_sender: network_listener_sender,
@@ -646,7 +636,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
constellation.run();
}).expect("Thread spawning failed");
- (compositor_sender, swmanager_sender, bluetoothmanager_sender)
+ (compositor_sender, swmanager_sender)
}
/// The main event loop for the constellation.
@@ -840,7 +830,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Layout(FromLayoutMsg),
NetworkListener((PipelineId, FetchResponseMsg)),
FromSWManager(SWManagerMsg),
- FromBluetoothManager(BluetoothManagerMsg),
}
// Get one incoming request.
@@ -860,7 +849,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let receiver_from_layout = &self.layout_receiver;
let receiver_from_network_listener = &self.network_listener_receiver;
let receiver_from_swmanager = &self.swmanager_receiver;
- let receiver_from_bluetoothmanager = &self.bluetoothmanager_receiver;
select! {
msg = receiver_from_script.recv() =>
msg.expect("Unexpected script channel panic in constellation").map(Request::Script),
@@ -873,9 +861,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
msg.expect("Unexpected network listener channel panic in constellation")
)),
msg = receiver_from_swmanager.recv() =>
- msg.expect("Unexpected panic channel panic in constellation").map(Request::FromSWManager),
- msg = receiver_from_bluetoothmanager.recv() =>
- msg.expect("Unexpected bluetooth channel panic in constellation").map(Request::FromBluetoothManager)
+ msg.expect("Unexpected panic channel panic in constellation").map(Request::FromSWManager)
}
};
@@ -899,9 +885,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
},
Request::FromSWManager(message) => {
self.handle_request_from_swmanager(message);
- },
- Request::FromBluetoothManager(message) => {
- self.handle_request_from_bluetoothmanager(message);
}
}
}
@@ -931,15 +914,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
- fn handle_request_from_bluetoothmanager(&mut self, message: BluetoothManagerMsg) {
- match message {
- BluetoothManagerMsg::OpenDeviceSelectDialog(devices, sender) => {
- let msg = EmbedderMsg::GetSelectedBluetoothDevice(devices, sender);
- self.embedder_proxy.send(msg);
- }
- }
- }
-
fn handle_request_from_compositor(&mut self, message: FromCompositorMsg) {
match message {
FromCompositorMsg::Exit => {
diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs
index 316f4bc128e..d270d87a50c 100644
--- a/components/script_traits/lib.rs
+++ b/components/script_traits/lib.rs
@@ -73,7 +73,7 @@ use webrender_api::{ExternalScrollId, DevicePixel, DeviceUintSize, DocumentId, I
use webvr_traits::{WebVREvent, WebVRMsg};
pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
-pub use script_msg::{BluetoothManagerMsg, ServiceWorkerMsg, ScopeThings, SWManagerMsg, SWManagerSenders, DOMMessage};
+pub use script_msg::{ServiceWorkerMsg, ScopeThings, SWManagerMsg, SWManagerSenders, DOMMessage};
/// The address of a node. Layout sends these back. They must be validated via
/// `from_untrusted_node_address` before they can be used, because we do not trust layout.
diff --git a/components/script_traits/script_msg.rs b/components/script_traits/script_msg.rs
index 65829b02406..43812ad097a 100644
--- a/components/script_traits/script_msg.rs
+++ b/components/script_traits/script_msg.rs
@@ -213,10 +213,3 @@ pub enum SWManagerMsg {
/// Provide the constellation with a means of communicating with the Service Worker Manager
OwnSender(IpcSender<ServiceWorkerMsg>),
}
-
-/// Messages outgoing from the Bluetooth Manager thread to constellation
-#[derive(Deserialize, Serialize)]
-pub enum BluetoothManagerMsg {
- /// Requesting to open device select dialog
- OpenDeviceSelectDialog(Vec<String>, IpcSender<Option<String>>)
-}
diff --git a/components/servo/lib.rs b/components/servo/lib.rs
index b6f95e28a52..3b7973ba203 100644
--- a/components/servo/lib.rs
+++ b/components/servo/lib.rs
@@ -67,7 +67,8 @@ fn webdriver(port: u16, constellation: Sender<ConstellationMsg>) {
#[cfg(not(feature = "webdriver"))]
fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) { }
-use bluetooth::new_bluetooth_thread;
+use bluetooth::BluetoothThreadFactory;
+use bluetooth_traits::BluetoothRequest;
use canvas::gl_context::GLContextFactory;
use canvas::webgl_thread::WebGLThreads;
use compositing::{IOCompositor, ShutdownState, RenderNotifier};
@@ -457,7 +458,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
webrender_api_sender: webrender_api::RenderApiSender,
window_gl: Rc<gl::Gl>)
-> (Sender<ConstellationMsg>, SWManagerSenders) {
- let (bluetooth_thread, bluetooth_constellation_sender) = new_bluetooth_thread();
+ let bluetooth_thread: IpcSender<BluetoothRequest> = BluetoothThreadFactory::new(embedder_proxy.clone());
let (public_resource_threads, private_resource_threads) =
new_resource_threads(user_agent,
@@ -525,9 +526,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
webgl_threads,
webvr_chan,
};
- let (constellation_chan,
- from_swmanager_sender,
- from_bluetoothmanager_sender) =
+ let (constellation_chan, from_swmanager_sender) =
Constellation::<script_layout_interface::message::Msg,
layout_thread::LayoutThread,
script::script_thread::ScriptThread>::start(initial_state);
@@ -537,8 +536,6 @@ fn create_constellation(user_agent: Cow<'static, str>,
webvr_constellation_sender.send(constellation_chan.clone()).unwrap();
}
- bluetooth_constellation_sender.send(from_bluetoothmanager_sender.clone()).unwrap();
-
// channels to communicate with Service Worker Manager
let sw_senders = SWManagerSenders {
swmanager_sender: from_swmanager_sender,