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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Large diffs are not rendered by default.

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

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

[dependencies]
bincode = "0.8"
cdp_traits = {path = "../cdp_traits"}
futures = "0.1"
ipc-channel = "0.8"
log = "0.3"
msg = {path = "../msg"}
script_traits = {path = "../script_traits"}
serde = "1.0"
serde_json = "1.0"
servo_config = {path = "../config"}
servo_url = {path = "../url"}
tokio-core = "0.1"
tokio-service = "0.1"

[dependencies.cdp]
git = "https://github.com/devtools-html/cdp"
rev = "0b3a0ba2a71b36324a8f465cc47eaaa2762b8d59"

[dependencies.tokio-cdp]
git = "https://github.com/devtools-html/tokio-cdp"
rev = "c23b7a36986c2f3ae7aaf947a9475618395b7758"
@@ -0,0 +1,100 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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 bincode;
use futures::{Async, Future};
use futures::future::{self, Either};
use ipc_channel::ipc::{self, IpcReceiver};
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId};
use script_traits::{ConstellationMsg, LoadData, WebDriverCommandMsg};
use script_traits::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use std::io;
use std::sync::mpsc::Sender;

pub fn focus_top_level_browsing_context_id(
constellation_chan: &Sender<ConstellationMsg>,
) -> io::Result<IpcReceiver<Option<TopLevelBrowsingContextId>>> {
let (sender, receiver) = ipc::channel()?;
let msg = ConstellationMsg::GetFocusTopLevelBrowsingContext(sender);
send(constellation_chan, msg).map(|_| receiver)
}

pub fn get_page_title(
constellation_chan: &Sender<ConstellationMsg>,
browsing_context_id: BrowsingContextId,
) -> io::Result<IpcReceiver<String>> {
let (sender, receiver) = ipc::channel()?;
let msg = WebDriverScriptCommand::GetTitle(sender);
send_webdriver_script_cmd(constellation_chan, browsing_context_id, msg).map(|_| receiver)
}

pub fn get_page_url(
constellation_chan: &Sender<ConstellationMsg>,
browsing_context_id: BrowsingContextId,
) -> io::Result<IpcReceiver<ServoUrl>> {
let (sender, receiver) = ipc::channel()?;
let msg = WebDriverScriptCommand::GetUrl(sender);
send_webdriver_script_cmd(constellation_chan, browsing_context_id, msg).map(|_| receiver)
}

pub fn load_url(
constellation_chan: &Sender<ConstellationMsg>,
top_level_browsing_context_id: TopLevelBrowsingContextId,
load_data: LoadData,
) -> io::Result<IpcReceiver<LoadStatus>> {
let (sender, receiver) = ipc::channel()?;
let msg = WebDriverCommandMsg::LoadUrl(top_level_browsing_context_id, load_data, sender);
send_webdriver_cmd(constellation_chan, msg).map(|_| receiver)
}

fn send_webdriver_script_cmd(
constellation_chan: &Sender<ConstellationMsg>,
browsing_context_id: BrowsingContextId,
msg: WebDriverScriptCommand,
) -> io::Result<()> {
send_webdriver_cmd(
constellation_chan,
WebDriverCommandMsg::ScriptCommand(browsing_context_id, msg),
)
}

fn send_webdriver_cmd(
constellation_chan: &Sender<ConstellationMsg>,
msg: WebDriverCommandMsg,
) -> io::Result<()> {
send(constellation_chan, ConstellationMsg::WebDriverCommand(msg))
}

fn send<T>(sender: &Sender<T>, msg: T) -> io::Result<()> {
sender.send(msg).map_err(|_| io::Error::new(io::ErrorKind::ConnectionReset, "channel closed"))
}

pub fn receive_ipc<T>(receiver: IpcReceiver<T>) -> impl Future<Item = T, Error = io::Error>

This comment has been minimized.

Copy link
@jdm

jdm Sep 7, 2017

Member

Didn't we add servo/ipc-channel@484f2c4 to improve the ergonomics here?

where
for<'de> T: Serialize + Deserialize<'de>,
{
future::poll_fn(move || match receiver.recv() {
Ok(msg) => Ok(msg.into()),
Err(err) => match *err {
bincode::ErrorKind::IoError(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
Ok(Async::NotReady)
}
_ => Err(io::Error::new(io::ErrorKind::Other, err)),
},
})
}

pub fn wrap_receive_ipc<T>(
result: io::Result<IpcReceiver<T>>,
) -> impl Future<Item = T, Error = io::Error>
where
for<'de> T: Serialize + Deserialize<'de>,
{
match result {
Err(err) => Either::A(future::err(err)),
Ok(receiver) => Either::B(receive_ipc(receiver)),
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.