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

[WIP] Chrome DevTools Protocol implementation #18133

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Move shared types from servo_cdp to cdp_traits

Reduces recompilation time when making changes to servo_cdp.
  • Loading branch information
spinda committed Aug 22, 2017
commit 6b345bfd6e57613f2ab0d80a3a0c269654477c89

Some generated files are not rendered by default. Learn more.

@@ -11,6 +11,7 @@ path = "lib.rs"

[dependencies]
bincode = "0.8"
cdp_traits = {path = "../cdp_traits"}
futures = "0.1"
ipc-channel = "0.8"
log = "0.3"
@@ -11,6 +11,7 @@

extern crate bincode;
extern crate cdp;
extern crate cdp_traits;
extern crate futures;
extern crate ipc_channel;
#[macro_use]
@@ -31,9 +32,9 @@ use cdp::http::{DevToolsUrls, Page, PageType, VersionInfo};
use cdp::http::{OwnedCommand as OwnedHttpCommand, Response as HttpResponse};
use cdp::ws::{Command as WsCommand, Response as WsResponse, ServerError};
use cdp::ws::page;
use cdp_traits::{CdpControlMsg, CdpControlReceiver, CdpControlSender};
use futures::{Future, Stream};
use futures::future::{self, Either, Loop};
use futures::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId};
use script_traits::{ConstellationMsg, LoadData};
use serde_json::Value;
@@ -48,35 +49,20 @@ use tokio_core::net::TcpListener;
use tokio_core::reactor::Core;
use tokio_service::Service;

pub enum Msg {
StartAccepting(Sender<ConstellationMsg>),
}

type MsgReceiver = UnboundedReceiver<Msg>;

#[derive(Clone)]
pub struct MsgSender(UnboundedSender<Msg>);

impl MsgSender {
pub fn send(&self, msg: Msg) {
let _ = self.0.send(msg);
}
}

/// Spin up a Chrome DevTools Protocol server that listens for connections on
/// the specified port.
pub fn start_server(port: u16) -> MsgSender {
let (sender, receiver) = mpsc::unbounded();
pub fn start_server(port: u16) -> CdpControlSender {
let (sender, receiver) = cdp_traits::control_channel();
{

This comment has been minimized.

Copy link
@jdm

jdm Sep 7, 2017

Member

Why is the {} necessary?

thread::Builder::new()
.name("ChromeDevtools".to_owned())
.spawn(move || run_server(receiver, port))
.expect("Thread spawning failed");
}
MsgSender(sender)
sender
}

fn run_server(receiver: MsgReceiver, port: u16) {
fn run_server(receiver: CdpControlReceiver, port: u16) {
let mut core = Core::new().expect("Core creation failed");
let handle = core.handle();

@@ -105,7 +91,7 @@ fn run_server(receiver: MsgReceiver, port: u16) {

let receive = future::loop_fn((receiver, Some(start_accepting)), |(receiver, maybe_start)| {
receiver.into_future().and_then(move |(message, receiver)| match message {
Some(Msg::StartAccepting(constellation_chan)) => match maybe_start {
Some(CdpControlMsg::StartAccepting(constellation_chan)) => match maybe_start {
Some(start_accepting) => {
start_accepting(constellation_chan);
debug!("CDP server now accpeting clients.");

This comment has been minimized.

Copy link
@jdm

jdm Sep 7, 2017

Member

accepting

@@ -0,0 +1,14 @@
[package]
name = "cdp_traits"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false

[lib]
name = "cdp_traits"
path = "lib.rs"

[dependencies]
futures = "0.1"
script_traits = {path = "../script_traits"}
@@ -0,0 +1,24 @@
extern crate futures;

This comment has been minimized.

Copy link
@jdm

jdm Sep 7, 2017

Member

Nit: missing license header.

extern crate script_traits;

use futures::sync::mpsc as futures_mpsc;
use script_traits::ConstellationMsg;
use std::sync::mpsc as std_mpsc;

/// Establish a CDP server control channel.
#[inline]

This comment has been minimized.

Copy link
@jdm

jdm Sep 7, 2017

Member

Why the inline marking? I can't imagine that this is a performance hit if it's not there.

pub fn control_channel() -> (CdpControlSender, CdpControlReceiver) {
futures_mpsc::unbounded()
}

/// The sender half of a CDP server control channel.
pub type CdpControlSender = futures_mpsc::UnboundedSender<CdpControlMsg>;
/// The receiver half of a CDP server control channel.
pub type CdpControlReceiver = futures_mpsc::UnboundedReceiver<CdpControlMsg>;

/// Inbound control messages to the CDP server.
pub enum CdpControlMsg {
/// Complete setup with the provided constellation channel handle and start
/// accepting clients.
StartAccepting(std_mpsc::Sender<ConstellationMsg>),
}
@@ -13,8 +13,9 @@ path = "lib.rs"
backtrace = "0.3"
bluetooth_traits = { path = "../bluetooth_traits" }
canvas = {path = "../canvas"}
clipboard = "0.4"
canvas_traits = {path = "../canvas_traits"}
cdp_traits = {path = "../cdp_traits"}
clipboard = "0.4"
compositing = {path = "../compositing"}
debugger = {path = "../debugger"}
devtools_traits = {path = "../devtools_traits"}
@@ -34,7 +35,6 @@ profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
serde = "1.0"
style_traits = {path = "../style_traits"}
servo_cdp = {path = "../cdp"}
servo_config = {path = "../config"}
servo_rand = {path = "../rand"}
servo_remutex = {path = "../remutex"}
@@ -72,6 +72,7 @@ use browsingcontext::{FullyActiveBrowsingContextsIterator, AllBrowsingContextsIt
use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::webgl_thread::WebGLThreads;
use canvas_traits::canvas::CanvasMsg;
use cdp_traits::CdpControlSender;
use clipboard::{ClipboardContext, ClipboardProvider};
use compositing::SendableFrameTree;
use compositing::compositor_thread::CompositorProxy;
@@ -108,7 +109,6 @@ use script_traits::{LogEntry, ScriptToConstellationChan, ServiceWorkerMsg, webdr
use script_traits::{MozBrowserErrorType, MozBrowserEvent, WebDriverCommandMsg, WindowSizeData};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WindowSizeType};
use serde::{Deserialize, Serialize};
use servo_cdp;
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_rand::{Rng, SeedableRng, ServoRng, random};
@@ -203,7 +203,7 @@ pub struct Constellation<Message, LTF, STF> {

/// A channel for the constellation to send messages to the
/// Chrome devtools thread.
cdp_chan: Option<servo_cdp::MsgSender>,
cdp_chan: Option<CdpControlSender>,

/// An IPC channel for the constellation to send messages to the
/// bluetooth thread.
@@ -321,7 +321,7 @@ pub struct InitialConstellationState {
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,

/// A channel to the Chrome developer tools server, if applicable.
pub cdp_chan: Option<servo_cdp::MsgSender>,
pub cdp_chan: Option<CdpControlSender>,

/// A channel to the bluetooth thread.
pub bluetooth_thread: IpcSender<BluetoothRequest>,
@@ -11,6 +11,7 @@ extern crate backtrace;
extern crate bluetooth_traits;
extern crate canvas;
extern crate canvas_traits;
extern crate cdp_traits;
extern crate clipboard;
extern crate compositing;
extern crate debugger;
@@ -33,7 +34,6 @@ extern crate net_traits;
extern crate profile_traits;
extern crate script_traits;
#[macro_use] extern crate serde;
extern crate servo_cdp;
extern crate servo_config;
extern crate servo_rand;
extern crate servo_remutex;
@@ -23,6 +23,7 @@ bluetooth_traits = {path = "../bluetooth_traits"}
bluetooth = {path = "../bluetooth"}
canvas = {path = "../canvas"}
canvas_traits = {path = "../canvas_traits"}
cdp_traits = {path = "../cdp_traits"}
compositing = {path = "../compositing"}
constellation = {path = "../constellation"}
debugger = {path = "../debugger"}
@@ -27,6 +27,7 @@ pub extern crate bluetooth;
pub extern crate bluetooth_traits;
pub extern crate canvas;
pub extern crate canvas_traits;
pub extern crate cdp_traits;
pub extern crate compositing;
pub extern crate constellation;
pub extern crate debugger;
@@ -44,8 +45,8 @@ pub extern crate profile_traits;
pub extern crate script;
pub extern crate script_traits;
pub extern crate script_layout_interface;
pub extern crate servo_cdp;
pub extern crate servo_config;
pub extern crate servo_cdp;
pub extern crate servo_geometry;
pub extern crate servo_url;
pub extern crate style;
@@ -71,6 +72,7 @@ use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::gl_context::GLContextFactory;
use canvas::webgl_thread::WebGLThreads;
use cdp_traits::{CdpControlMsg, CdpControlSender};
use compositing::IOCompositor;
use compositing::compositor_thread::{self, CompositorProxy, CompositorReceiver, InitialCompositorState};
use compositing::windowing::WindowEvent;
@@ -298,7 +300,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
mem_profiler_chan: mem::ProfilerChan,
debugger_chan: Option<debugger::Sender>,
devtools_chan: Option<Sender<devtools_traits::DevtoolsControlMsg>>,
cdp_chan: Option<servo_cdp::MsgSender>,
cdp_chan: Option<CdpControlSender>,
supports_clipboard: bool,
webrender: &mut webrender::Renderer,
webrender_document: webrender_api::DocumentId,
@@ -367,7 +369,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
webvr_constellation_sender.send(constellation_chan.clone()).unwrap();
}
if let Some(cdp_chan) = cdp_chan {
cdp_chan.send(servo_cdp::Msg::StartAccepting(constellation_chan.clone()));
let _ = cdp_chan.send(CdpControlMsg::StartAccepting(constellation_chan.clone()));
}

// channels to communicate with Service Worker Manager
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.