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
+821
−11
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ec06c6
Implement AsRef<BrowsingContextId> for TopLevel
spinda aa1413b
Add type annotation to gfx::display_list
spinda bbe380b
Add type annotation to script::dom::document
spinda 3cd4fa2
Initial Chrome DevTools Protocol implementation
spinda 6b345bf
Move shared types from servo_cdp to cdp_traits
spinda File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Large diffs are not rendered by default.
Oops, something went wrong.
| @@ -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> | ||
|
||
| 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)), | ||
| } | ||
| } | ||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Didn't we add servo/ipc-channel@484f2c4 to improve the ergonomics here?